Hey everyone, I’ve been working on a project to streamline my home’s lighting system, and I thought I’d share my journey and ask for some feedback. I have six rooms, each with its own set of light switches and scenes, and I’ve been trying to find a way to make the automation process more efficient without having to write separate rules for each switch.
Initially, I set up individual rules for each light switch, but as the number of switches grew, the code became repetitive and hard to manage. I stumbled upon the idea of grouping all the light switches and their corresponding scenes into a single rule. Here’s what I came up with:
java
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)
}
This approach seems to work well, but I’m curious if there’s a more efficient way to handle this. I’d also like to add a feature where a long press on the switch dims the lights, and I want to incorporate presence detection so that if someone is home, the lights stay on. Here’s a snippet of what I’m thinking:
java
Dimmer Dimmer_MasterBedRoom “Dimmer [%d %%]”
I’m wondering if this can be integrated into the same rule and how I might go about implementing it. The goal is to make the system as seamless and user-friendly as possible.
I’d love to hear your thoughts and any suggestions you might have. Have any of you tackled a similar project? What tricks or tips can you share? Let’s discuss and maybe come up with an even better solution together!