In the rule body, you can use if/then statements. For example…
rule "Test DSL rule"
when
// These are your triggers
Item Test_Lamp_1 changed
or
Item Test_Television changed
then
logInfo("Test Rule", "Test: Start")
if (Test_Lamp_1.state == ON && Test_Television.state == OFF) {
Test_Lamp_2.sendCommand(ON)
}
logInfo("Test Rule", "Test: End")
end
Jython version…
from core.rules import rule
from core.triggers import when
@rule("Test Jython rule")
@when("Item Test_Lamp_1 changed")
@when("Item Test_Television changed")
def test_rule(event):
test_rule.log.info("Test: Start")
if items["Test_Lamp_1"] == ON and items["Test_Television"] == OFF):
sendCommand("Test_Lamp_2", "ON")
test_rule.log.info("Test: End")
Does that mean when the TV is switched off?
That would be a straightforward rule trigger.
But it’s ambiguous …
Does that mean anytime that lamp2 is turned on AND the TV is off?
That would be another straightforward trigger.
Don’t forget you can trigger a rule from multiple events, so you might trigger from both TV changing or light2 changing.
1 Like
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
4
I’m making a short (well, maybe not that short, but it’s not like we don’t all have more time) video about how to setup openHAB2, which includes a tiny section on DSL rules and NodeRed.
While I’m not going to cover linking different protocols, the whole “if this is ON AND I switch this ON, something else should come ON” basic rule will be in there.
What I’ll do is add an index of the video in the description, just so you don’t have to watch everything.