Hi @deltabert,
Apologies for my late response.
To give you an update, my lighting and startup rules are working very reliably. It’s been working very well for months now on my SD card (I’ll be migrating to SSD soon). Only once did my sunrise rule not trigger for some reason, so my wife unplugged the Pi and plugged it back in and the startup rule set the lights accordingly.
I don’t have access to y setup as I am away but I’ll post it when I’m back.
It looks similar to my dummy setup on my laptop which is as follows:
Light.items
/* -----------------Groups---------------- */
Group:Dimmer:OR(ON,OFF) Lights_All "All Lights [%d]" <light>
Group:Dimmer:OR(ON,OFF) Lights_Outdoor "Outdoor Lights [%d]" <light> (Lights_All)
Group:Dimmer:OR(ON,OFF) Lights_Indoor "Indoor Lights [%d]" <light> (Lights_All)
/* -----------------Lights----------------- */
// Outdoor
Dimmer Light_Front_Door_1 "Front Door 1 [%d %%]" <light> {channel=""}
Dimmer Light_Front_Door_2 "Front Door 2 [%d %%]" <light> {channel=""}
Dimmer Light_Front_Door "Front Door [%d %%]" <light> (Lights_Outdoor)
Dimmer Light_Patio_1 "Patio 1 [%d %%]" <light> {channel=""}
Dimmer Light_Patio_2 "Patio 2 [%d %%]" <light> {channel=""}
Dimmer Light_Patio "Patio [%d %%]" <light> (Lights_Outdoor)
Dimmer Light_Braai "Braai [%d %%]" <light> (Lights_Outdoor) {channel=""}
Dimmer Light_Kitchen_Porch "Kitchen Entrance [%d %%]" <light> (Lights_Outdoor) {channel=""}
Dimmer Light_Backyard "Back yard [%d %%]" <light> (Lights_Outdoor) {channel=""}
Dimmer Light_Adi_Deck "Adi's deck [%d %%]" <light> (Lights_Outdoor) {channel=""}
// Indoor
Dimmer Light_Study "Study [%d %%]" <light> (Lights_Indoor) {channel=" "}
Virtual.items (for proxy switches)
/* -----------------General---------------- */
Switch NightState "Night"
Switch LateNightState "Late at Night"
Dimmer Dummy_Slider "Dummy slider"
Dimmer Dummy_Switch "Dummy switch"
DateTime Current_Time "Date [%1$tA, %1$tm/%1$td/%1$tY %1$tT]" <calendar> {channel="ntp:ntp:local:dateTime"}
// Create string items for panel names to link dashboards
Astro.items:
/* -----------------Groups---------------- */
Group gAstro "Astronomical Data"
/* -----------------Astro---------------- */
// Sun
DateTime Sunrise_Start "Sunrise Start [%1$tH:%1$tM]" (gAstro) {channel="astro:sun:f0276b48:rise#start"}
DateTime Sunset_Start "Sunset Start [%1$tH:%1$tM]" (gAstro) {channel="astro:sun:f0276b48:set#start"}
And my rules…
Startup.rules:
rule "OpenHAB system started - Astro"
when
System started
then
logInfo("System started rule trigerred", "--> System started")
val LateAtNight = now.withTimeAtStartOfDay.plusHours(22).millis // 10 PM
createTimer(now.plusSeconds(60)) [ |
if (now.isAfter((Sunset_Start.state as DateTimeType).calendar.timeInMillis) ||
now.isBefore((Sunrise_Start.state as DateTimeType).calendar.timeInMillis))
{
logInfo("NightState updated", "--> NightState set to ON")
postUpdate(NightState, ON)
} else {
logInfo("NightState updated", "--> NightState set to OFF")
postUpdate(NightState, OFF)
}
if (now.isAfter(LateAtNight) || now.isBefore((Sunrise_Start.state as DateTimeType).calendar.timeInMillis)){
logInfo("LateNightState updated", "--> LateNightState set to ON")
postUpdate(LateNightState, ON)
} else {
logInfo("LateNightState updated", "--> LateNightState set to OFF")
postUpdate(LateNightState, OFF)
}
val Craig_Presence = Presence_Craig.state
postUpdate(Presence_Craig, Craig_Presence)
]
end
DayNight.rules:
rule "Switch NightState to ON at sunset"
when
Channel 'astro:sun:f3c3056b:set#start' triggered START
then
postUpdate(NightState, ON)
logInfo("NightState updated", "--> NightState set to " + NightState.state)
end
rule "Switch NightState and LateNightState to OFF at sunrise"
when
Channel 'astro:sun:f3c3056b:rise#start' triggered START
then
postUpdate(NightState, OFF)
postUpdate(LateNightState, OFF)
logInfo("NightState updated", "--> NightState set to OFF")
logInfo("LateNightState updated", "--> LateNightState set to OFF")
end
rule "Switch LateNightState to ON at 22h00"
when
Time cron "0 0 22 1/1 * ? *"
then
postUpdate(LateNightState, ON)
logInfo("LateNightState updated", "--> LateNightState set to " + LateNightState.state)
end
Lighting.rules:
rule "Switch lights on at night"
when
Item NightState changed
then
if (NightState.state == OFF) {
logInfo("Daytime", "--> Lights " + NightState.state)
sendCommand(Lights_All, OFF)
} else {
sendCommand(Lights_Outdoor, 40)
logInfo("Night time", "--> Lights on")
sendCommand(Light_Study, 40)
}
end
rule "Adjust lights late at night"
when
Item LateNightState changed to ON
then
logInfo("Late at night", "--> Outside lights on full")
sendCommand(Lights_Outdoor, 100)
sendCommand(Light_Study, OFF)
end
rule "Update patio lights"
when
Item Light_Patio changed
then
val SliderValue = Light_Patio.state as Number
sendCommand(Light_Patio_1, SliderValue)
sendCommand(Light_Patio_2, SliderValue)
end
rule "Update front door lights"
when
Item Light_Front_Door changed
then
val SliderValue = Light_Front_Door.state as Number
sendCommand(Light_Front_Door_1, SliderValue)
sendCommand(Light_Front_Door_2, SliderValue)
end
Please note my design goal was to have as few rule components as possible and so I use proxy switched (virtual items) for monitoring events and triggers.
Any comments / criticism welcome.
I hope that helps,
Craig