Hi folks,
I have what is turning out to be a bit of a dog’s breakfast with rules and hoping someone can show that there is a simpler way.
I have presence detection which switches a switch called Present (Yes, plagiarised from here )
I have a switch called NightState which is controlled by Astro
I have a rule which sets a switch called BedTime at 23:00
Now, what I want is when it’s night certain lamps (g_Lamps) turn on but if no one is home then g_Lamps_NoOneHome must turn on.
At 23:00 certain lamps must turn off and only leave certain ones one (Hallway lamp)
At daytime all lamps must turn off unless someone is home then cupboard LEDs must stay on.
At the moment I have it sort of working but it’s weaving in and out of code which is not clean. Any change to it and it breaks. It’s also quite slow (RPi). I am sure I can speed it up with groups.
As much as this gets controlled from the time or night time, I also want it to be controlled from the Present state. i.e. if it’s night and we leave, go into night-no-one-home mode.
When we return it needs to go into night-someone-home mode.
All very simple
rule "Night has started"
when
Item NightState changed from OFF to ON
then
if (AutoDayNight.state == OFF){
logInfo("Night Rule", "It's getting dark. Auto Day/Night disabled")
return
}
//someone home
if (Present.state == ON) {
proxyNightPresent.sendCommand(ON)
}
else {
proxyNightNotPresent.sendCommand(ON)
}
end
rule "Night has ended"
when
Item NightState changed from ON to OFF
then
if (AutoDayNight.state == OFF){
logInfo("Night Rule", "Getting light. Auto Day/Night disabled")
return
}
logInfo("Night Rule", "It's getting Light!")
g_Lamps.sendCommand(OFF)
g_LampsPC.sendCommand(0)
g_Lanterns.sendCommand(0)
if (Present.state == ON){
g_WetroomLEDS.sendCommand(25)
g_KitchenCupboards.sendCommand(25)
}
else {
g_WetroomLEDS.sendCommand(0)
g_KitchenCupboards.sendCommand(0)
}
end
rule "Night state and someone is home"
when Item proxyNightPresent received command ON then
if (NightState.state !== NULL && NightState.state != ON){
return
}
logInfo("proxyNightPresent", "Night, someone home.")
g_HallwayLamps.sendCommand(ON)
g_Lanterns.sendCommand(ON)
g_Lamps.sendCommand(ON)
g_LampsPC.sendCommand(50)
g_WetroomLEDS.sendCommand(100)
g_KitchenCupboards.sendCommand(100)
proxyNightPresent.sendCommand(OFF)
end
rule "Night state and nobody is home"
when Item proxyNightNotPresent received command ON then
if (NightState.state !== NULL && NightState.state != ON){
return
}
logInfo("proxyNightPresent", "Night, nobody home.")
g_AwaySW.sendCommand(ON)
g_AwayPC.sendCommand(25)
proxyNightNotPresent.sendCommand(OFF)
end