These days I am working on a Tutorial for lights and before I release it I would like some help with the buttons.
I have 6 rooms:
- BathRoom
- BedRoom
- MasterBedRoom
- LivingRoom
- Hallway
- Balcony
Each of these has at least one switch defined:
Contact Contact_BathroomL {gpio="pin:24 debounce:0 activelow:yes"}//SW3
Contact Contact_BathroomR {gpio="pin:25 debounce:0 activelow:yes"}//SW4
Now comes the nice part(At least I think so…) For each room I have defined a scene selector(Even if the hallway only have one light(Simple switch)…)
Number Scene_MasterBedRoom "Scene" <sofa>
these scene always have the same start mapping:
- 0=OFF
- 1=ON
- 2=NIGHT
- 3=…
- 4=…
Untill now i have made a seperate rule for each contact:
rule "Update bathroom light when button pressed"
when
Item Contact_BathroomR changed from OPEN to CLOSED
then
if(Scene_BathRoom.state == 0){
if (vTimeOfDay.state.toString.contains("NIGHT")){
Scene_BathRoom.sendCommand(2)
}
else{
Scene_BathRoom.sendCommand(1)
}
}
else {
Scene_BathRoom.sendCommand(0)
}
end
So can I modify this rule so that we only need 1 rule no mater how many light switches we have?
Add all contacts to the group: Group Group_LightSwitches
Add all scenes to the group: Group Group_RoomScenes
Then do something like this:
Group_LightSwitches.members.forEach[ room |
val sceneItem= Group_RoomScenes.members.findFirst[g | g.name.contains(room.name)] as NumberItem
if (sceneItem!=null){
if(sceneItem.state == 0){
if (vTimeOfDay.state.toString.contains("NIGHT")){
sceneItem.sendCommand(2)
}
else{
sceneItem.sendCommand(1)
}
}
else {
sceneItem.sendCommand(0)
}
So all my switches are push buttons(I mounted a spring on them…) due to the fact that you can control the lights several ways(tablet,phones,pc,alexa…)
So the last feature I would like to implement is that if there is a long press then we will dim the lights:
Dimmer Dimmer_MasterBedRoom "Dimmer [%d %%]"
can this be implemented in the same rule, and if so how?
Finally in the same rule I would also add the presence detection, we are pretty sure someone is home if a button is pressed:
Switch Presence_Home "Somebody is at home" (Group_MyOpenhab)
@rlkoshak do you have some coments on this?