One switch controlling the execution of another switch

Hi,

Sorry for a rookie question, but I am new to the rule language of OpenRemote…

I have two switches, one (in-memory virtual) ENABLE switch controlled by the GUI user and one STATUS switch controlled by a z-wave door sensor.

I would like the value of the virtual ENABLE switch to Control the execution of event for the STATUS switch. The rule I have written (which 100% does not work)´;-)) looks like:

rule “ReportOpenDoor” when
Event ( source == “Door_STATUS.Status”, value == “on” )
then
if ( source == “Door_ENABLE.Status”, value == “on” ) {
execute.command( “whatever” );
}
end

Not sure if I am using the correct “nomenclature” here, but I hope you understand…

Thankful for any help!

Hi,

If I understand you correctly then the rule would be:

rule “ReoprtOpenDoor”

when

Event(source == “Door_STATUS.Status”, value == “on”)

Event(source == “Door_ENABLE.Status”, value == “on”)

then

execute.command(“whatever”);

end

You want to include both sensors on the RHS (when…then) because they can trigger the rule independently, i.e. the rule is sensitive to both sensors. You shouldn’t use if(…) statement in the rule body.

Kind regards,

Michal

Thanks Michal!

But the Door_ENABLE.Status should not trigger the rule. Its status should just be checked when the Door_STATUS.Status has triggered the rule. Nothing should happen if if only Door_ENABLE is triggered.

/Anders

OK, now I understand what you want and this is in fact very common pattern impossible to solve with the default rules engine implementation in OpenRemote. The solution which works for me is using the rules engine in the STREAM mode (you would need to recompile the controller to change this. On the forums there were more posts about it). Then, having this you would rewrite the rule as:

rule “ReportOpenDoor”

when

$e: Event(source == “Door_STATUS.Status”, value == “on”)

Event(source == “Door_STATUS.Enable”, value == “on”, this before $e)

then

execute.command(“whatever”);

end

Kind regards,

Michal

Thx!