Thank you guys for the advice, it’s invaluable
What I’m trying to achieve is that in case of a power failure, let’s say 2 minutes before this sunset event triggers my power goes down and then comes back on 5 minutes after the sunset event would have triggered. Persistence 'restore on startup 'would not help me here.I would imagine just about everyone would would have a similar rule in their setup no?
May I ask for a clarification in @ThomDietrich’s example above using the || condition? In order for the system to know that it is night time why not use the && condition? The nightstate must be set to ‘ON’ if the current time is after sunset AND before sunrise. Does it matter?
I guess part of my requirement is redundant now as I see there is a ‘Sun Phase’ channel, so I’ll only need my ‘LateAtNight’ item maintained, e.g
I’m not sure what the possible ‘Sun Phase’ channel values could be so I’ll monitor it.
Now I don’t use the Sunset_Start trigger event anymore since I can use the Sun_Phase channel to tell me if it’s light or not. Maybe this helps someone out there who want to achieve this (assuming my logic is OK, which it is according to my new friend the Designer )
Here is my setup:
.items:
DateTime Sunrise_Start "Sunrise Start [%1$tH:%1$tM]" (gAstro) {channel="astro:sun:f3c3056b:rise#start"}
DateTime Sunset_Start "Sunset Start [%1$tH:%1$tM]" (gAstro) {channel="astro:sun:f3c3056b:set#start"}
String Sun_Phase "Sun phase" (gAstro) {channel="astro:sun:f3c3056b:phase#name"}
Startup rule:
val LateAtNight = now.withTimeAtStartOfDay.plusHours(22).millis // 10 PM
rule "OpenHAB system started - astro"
when
System started
then
createTimer(now.plusSeconds(180)) [ |
logInfo("RULE", "--> astro init")
if (Sun_Phase.state == 'DAYLIGHT'){
logInfo("RULE", "--> Switch all lights off")
}
else {
if(now.isAfter(LateAtNight)){
postUpdate(LateNightState, ON)
logInfo("LateNightState updated", "--> LateNightState set to " + LateNightState.state)
}
else {
postUpdate(LateNightState, OFF)
logInfo("LateNightState updated", "--> LateNightState set to " + LateNightState.state)
}
}
]
end
And the rule based on the changes in the Sun_Phase channel…
rule "Switch lights on at night"
when
Item Sun_Phase changed
then
if (Sun_Phase.state == 'DAYLIGHT'){
logInfo("Daytime", "--> Lights off")
sendCommand(Lights_All, OFF)
} else {
if (LateNightState.state == ON){
logInfo("Late at night", "--> Outside lights on full")
sendCommand(Lights_Outdoor, 100)
sendCommand(Light_Study, OFF)
} else {
logInfo("Night time", "--> Lights on")
sendCommand(Lights_Outdoor, 40)
sendCommand(Light_Study, 40)
}
}
end
Not sure how successful I’ll be but I’ll start testing it. If there’s a better way to achieve this I would be glad to hear it.
Thanks again for all your input