only_if
only_if allows rule execution when result is true and prevents when false.
rule 'Set OutsideDimmer to 50% if LightSwtich turned on and OtherSwitch is also ON' do
changed LightSwitch, to: ON
run { OutsideDimmer << 50 }
only_if { OtherSwitch == ON }
end
Because only_if uses ‘truthy?’ on non-block objects the above rule can also be written like this:
rule 'Set OutsideDimmer to 50% if LightSwtich turned on and OtherSwitch is also ON' do
changed LightSwitch, to: ON
run { OutsideDimmer << 50 }
only_if OtherSwitch
end
multiple only_if statements can be used and all must be true for the rule to run.
rule 'Set OutsideDimmer to 50% if LightSwtich turned on and OtherSwitch is also ON and Door is closed' do
changed LightSwitch, to: ON
run { OutsideDimmer << 50 }
only_if OtherSwitch
only_if { Door == CLOSED }
end