This page last changed on Feb 21, 2014 by nickbrookes76.

Hi, I've been pulling my hair out trying to accomplish a task with OR. (Which is brilliant by the way).

My set up is x10 switches with one tivo, and all of this works fabulously well.
uen
I want to now set up a switch on my android panel which writes a "fact" to a file which can then be used to trigger a whole series of events.

The reason i want to write to a file is that i want to build in resiliency in case of power outage.

I have worked out the shell scripts to write out "facts" each address such as a1 now has a text file in a folder called /facts/ which stores on or off. - this obviously doesn't necessarily hold true when a light switch can alter a state - but i'm ok with that.

The shell script also then executes the x10 command, this way i can know the programmatic status of an x10 switch, because i can't poll x10 for statuses...

I have another shell script which i can use to read the status of the x10 address, which i want to be able to use in a sensor.

This is where i am having problems...

I can't seem to get the sensor working, i've read and re-read the how-to guides and i'm still stumped.

I want to set a "fact" such as holiday -"on" via a button -using the shell script. this will allow me to turn on the occupancy simulator via rules. I have set up a label linked to a sensor to show the state, but all it says is N/A.

the sensor is set up as a switch, with the following:
name : sim sensor
protocol : shell execution protocol
path: /opt/openremote/scripts/scr_read
command parameter: sim
polling interval : 5s
regular expression: on|off
sensor names : sim sensor

the rule i have set up to cycle an x10 module to see if the fact switch works is as follows

package org.openremote.controller.model.event
global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;
global org.openremote.controller.statuscache.LevelFacade levels;
import org.openremote.controller.protocol.*;
...

rule "Test notin on"
when
 Event( source=="sim sensor", value == "on" )
then
 execute.command("p15 on");
end

rule "Test notin off"
when
  Event( source=="sim sensor", value == "off" )
then
 execute.command("p15 off");
end

I've tried setting up custom sensors and using customstates instead of events, .......

the label i've used on the panel is set up as follows:
sensor : sim sensor
sensor state
on text : on
off text : off
but the panel on my phone shows N/A and the switch next to it never shows the on picture, despite the "fact" being "on".

Can anyone understand me let alone help me????
Please?

There is a holiday example in the Rules documentation.
If your sensor says N/A, there is no value. You have to fix that first.

PS: For better readability you could enclose your code within {code}..{code} tags (see markup instructions). Do not place a / inside the end tag.
Formatting makes the code easier to read, which increases your chances to get an answer

Posted by pz1 at Feb 21, 2014 08:27

Thanks Pieter, added code tags. also managed to get the switch working which sets a fact in my folder - now i guess i need to understand and fix why the rules are not firing. i've adjusted the packages etc at the top of the code to no avail, and added events / switches writing out to the log, cron tasks to kick off the rule every minute etc, but nothing seems to work. The rules are solely to check that the fact i insert has an effect when evaluated, but i can't get the rules to work???

here is a snippet of my code...

package org.openremote.controller.model.event
global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;
global org.openremote.controller.statuscache.LevelFacade levels;
global org.openremote.controller.statuscache.RangeFacade ranges;
import org.openremote.controller.model.event.*;
import org.openremote.controller.protocol.*;


rule "heater on 5 mins before wakeup"
  timer (cron: 0 55 6 ? * 2-6)
when
  eval(true)
then
  execute.command("h16_on");
end


rule "heater off after 10 minutes"
  timer (cron: 0 5 7 ? * 2-6)
when
  eval(true)
then
  execute.command("h16_off");
end


rule "bedside light on at 7am"
  timer (cron: 0 0 7 ? * 2-6)
when
  eval(true)
then
  execute.command("h1_on");
end


rule "bedside light off at 10 past 7"
  timer (cron: 0 10 7 ? * 2-6)
when
  eval(true)
then
  execute.command("h1_off");
end


rule "thomas' light on at 7 am"
  timer (cron: 5 0 7 ? * 2-6)
when
  eval(true)
then
  execute.command("f1_on");
end

rule "thomas' light off at 7.10 am"
  timer (cron: 5 10 7 ? * 2-6)
when
  eval(true)
then
  execute.command("f1_off");
end



rule "thomas' light ofam"
  timer (cron: 5 10 20 ? * *)
when
  eval(true)
then
  execute.command("a1_on");
end




rule "Test simul on"
when
 Event( source=="vacation_sensor" )
 Switch( source=="vacation_sensor", value =="on" )
then
 System.out.println ("about to switch on a1");
 execute.command("a1 on");
end

rule "Test simul off"
when
  Event ( source=="vacation_sensor" )
  Switch ( source=="vacation_sensor", value == "off" )
then
System.out.println ("about to switch off a1");
 execute.command("a1 off");
end

nothing appears in the log and a1 does not cycle on or off...

I've tried it without the event (.. lines but that doesn't work either.

I know the vacation_sensor cycles on and off, as i can see that in the file which stores the info, and the label on my app.
why does't the rule work ?

Posted by nickbrookes76 at Feb 21, 2014 13:12

I am not an expert in this! I can only share my experience.

  • package org.openremote.controller.model.event and
    import org.openremote.controller.model.event.*;
    in the header seem a bit superfluous to me. I would leave out the latter.
  • I have learned to add and test rules one by one. I have rules like your first 7 working, though I have written them more compact, which imho should not make a difference:
    rule "Blanket on"
      timer (cron: 0 0 22 * * ?) when eval (true) then
      execute.command("Switch4On"); 
    end

    I try to avoid spaces and underscores in commands.

  • I do not know if there is a fundamental difference between State or Event. Semantically I would say the latter is a change of state. That could be more easily missed? I don't know. I have asked this before, but no satisfying answer yet.
Posted by pz1 at Feb 21, 2014 13:51

Thanks for your response,
I've deleted all of the previous rules, and just have now one rule.

It still won't fire. Is there something else i need to do on the raspberry pi in order to 'clear out any cobwebs'. for instance, i can not click the refresh stuff button on the local controller without getting an error message.

My rules now look like this ...

package org.openremote.controller.model.event
global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;
global org.openremote.controller.statuscache.LevelFacade levels;
global org.openremote.controller.statuscache.RangeFacade ranges;
import org.openremote.controller.protocol.*;

rule "Test simul on"
when
 Switch( source=="vacation_sensor", value =="on" )
then
 execute.command("a1 on");
end

rule "Test simul off"
when
  Switch ( source=="vacation_sensor", value == "off" )
then
 execute.command("a1 off");
end
Posted by nickbrookes76 at Feb 22, 2014 11:01

What error are you getting on refresh ?

Posted by ebariaux at Feb 24, 2014 08:35

i get Failed to reload configuration and clear cache!

not sure why?

BTW i got the rules working - i had missed an underscore in my command. I feel suitably stupid.

Posted by nickbrookes76 at Feb 24, 2014 19:18
Document generated by Confluence on Jun 05, 2016 09:31