I have a group where I linked all my lights and I can use it to power OFF all the lights. BUT when I use it, a lot of non necessary logs and command are sent to the bus. So I’d like to design a pattern where only the powered ON lights will receive the power OFF command.
my idea is a group of lights on .items file:
Group:Switch:OR(ON, OFF) gLight "all the light"
Switch Luce_Bagnetto "Light1" <light> (gLight)
Switch Luce_Bagnetto "Light2" <light> (gLight)
rules:
//rule that switch OFF only powered on lights
when
Item away received command ON
than
gLight.members.filter[ i | i.state == ON]
//here I miss an easy way to sendCommand OFF
end
maybe someone know a more intelligent way to address this problem.
Thanks Domenico
Of course I read It. but I miss some step because I don’t have experience on programming.
I’m trying following rule:
rule "switch OFF"
when
Item away received command ON
then
if (gLight.state == ON) {
gLight.members.filter[ i | i.state == ON].forEach[i | i.sendCommand(OFF) ]
logInfo("A letto", "spengo le luci accese")
}
end
that rule work but only for simple light, not for dimmers.
I had a problem with this approach because I made a rule that first poweroff all the lights and than powerON one light. But power off sequence need more time and it shutdown the light powered by the rule…
I should have said a rule to turn all lights in a group off and not every light in home.
Doing this you will need a rule for each group that you want to control.
That’s what I like about OH, you can start simple, add complex rules as you go and without losing control of your devices. FYI make sure you have a backup and verify it works as you don’t wanna lose all your hard work.
It doesn’t work for Dimmers because Dimmers don’t carry ON or OFF as a state. They carry a PercentType. So i.state == ON will always be false for a Dimmer.
However, Dimmers understand ON and OFF so you can use this instead in your filter
i.getStateAs(OnOffType) == ON
That will cause the Dimmer to convert it’s PercentType to ON/OFF and your filter will work.
Great tips! this worked
Edit:
I post the complete rule for other people on the community:
rule "A letto routine"
when
Item A_Letto received command ON
then
if (gLight.state == ON) {
gLight.members.filter[ i | i.getStateAs(OnOffType) == ON].forEach[i | i.sendCommand(OFF) ]
logInfo("A letto", "spengo le luci accese")
}
end