I have a rule that will turn on the light at 07:00 in the morning. someting like:
rule"do stuff"
when
Time cron "0 0 7 * * ?"
then
sendCommand(bladiebla,ON)
sendCommand(bladiebla2,ON)
end
Which works great, however part of the commands i do in the “then” part is switching on lights.
During winter time that’s great but during summer time sometimes the sun is already up so it’s silly to turn on the lights. I have astro installed and have a “sunrise” datatime however calculating with it doesn’t work very well…
Something as simpel as if (sunrise_date < current_date) didn’t do the trick…
Is my logic ok but syntax wrong or is there an easier way to do this?
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.java.math.*
import org.joda.time.*
rule "Dawn"
when
Item Dawn_Event received update ON
then
Night_Proxy.sendCommand(OFF)
Dawn_Proxy.sendCommand(ON)
end
rule "Day"
when
Item Sunrise_Event received update ON
then
Dawn_Proxy.sendCommand(OFF)
Day_Proxy.sendCommand(ON)
end
rule "Twilight"
when
Item Twilight_Event received update ON
then
Day_Proxy.sendCommand(OFF)
Twilight_Proxy.sendCommand(ON)
end
rule "Night"
when
Item Sunset_Event received update ON
then
Twilight_Proxy.sendCommand(OFF)
Night_Proxy.sendCommand(ON)
end