This page last changed on Jan 24, 2014 by tobo.

How would I go about having a rule not fire at startup. The below holds true at startup but there's no actual change, just that OR has been restarted. I would like for this rule to apply only when there's an actual change to "Sensor", not initialization. Possible?

rule "rule"
when
Event(source == "rule", value == "off")
then
execute.command("yada yada");
end

Thanks in advance,
Tobo

declare was_on
  value: String
end

rule "rule1"
salience 10
when
  Event(source=="rule", $v: value)
  $w: was_on()
then
  $w.setValue($v.toString());
  update($w);
end

rule "rule2"
when
then
  insert(new was_on());
end

rule "rule"
when
  Event(source == "rule", value == "off")
  was_on(value!="off")
then
  execute.command("yada yada");
end
Posted by aktur at Jan 24, 2014 15:58

Big thanks for the swift reply, will give it a go this evening or during the weekend and let you know how it went

Posted by tobo at Jan 24, 2014 16:46

Unfortunately I only found some time on Friday and a pure copy/paste didn't work. OR started eating a lot of CPU, I'm guessing "rule2" above made it go into an infinite loop. I tried to add a no-loop to that rule but to no avail, it still went crazy. Had to revert and thought I would have more time to try it out but that wasn't the case unfortunately.

I'll try to find some more time in the upcoming week and post my findings.

Posted by tobo at Jan 26, 2014 19:57

Just wanted to let you know how it turned out. I used a modified version of your code that set a boolean to true when the switch was set to on the first time since on isn't a "dangerous" state in my implementation. Ie, the sensor defaults to off (always in OR it seems) and the first time it goes to on (either straight away when updated or later on when activated) a flag i set to true. When OR wants to run the "off" scenario the flag has to be true so problem fixed.

"rule2" seems to send OR into some sort of loop and I didn't have the patience to troubleshoot further with the above modification. Thanks for the pointers!

Posted by tobo at Feb 09, 2014 18:21

It might be helpful to others if you published your code here

Posted by pz1 at Feb 10, 2014 07:57

Yep, basically I'd call it code in order to avoid triggering sensor off states when restarting OR, at least that's what I use it for since OR defaults to off.

Relevant code:


declare States
 alarm: int
 perimeter: int
 knx: int
end

rule "Initiate States"
no-loop
when
 eval ( true )
then
 States $states = new States();
 $states.setAlarm(0);
 $states.setPerimeter(0);
 $states.setKnx(0);
 insert ( $states );
end

rule "Alarm off"
when
 Event(source == "Motion sensors sensor", value == "off")
 $states: States()
 eval ($states.getAlarm() == 1)
then
 execute.command("KNX Scene welcome");
 execute.command("Vera scene welcome");
end

rule "Alarm on"
when
 $states: States()
 Event(source == "Motion sensors sensor", value == "on")
then
 $states.setAlarm(1);
 execute.command("KNX Scene bye");
 execute.command("Vera scene bye");
end

Posted by tobo at Feb 10, 2014 08:14

Rule "Alarm off" can be also written as:

rule "Alarm off"
when
 Event(source == "Motion sensors sensor", value == "off")
 States(alarm == 1)
then
 execute.command("KNX Scene welcome");
 execute.command("Vera scene welcome");
end
Posted by aktur at Feb 10, 2014 09:00

Ah, one line less, I like

Although, just for the rules that don't update value I guess or is there a one-liner for that as well?

Posted by tobo at Feb 10, 2014 12:26
Document generated by Confluence on Jun 05, 2016 09:35