Timing summer OR statement

Hello,

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?

Take a look at @rlkoshak posts regarding daytime switches:

Continuing the discussion from Automation/Orchestration Design Patterns:

and an update on that:

Continuing the discussion from Automation/Orchestration Design Patterns:

I’ve read through the link thanks for that. I does seem way overkill to introduce another variable which keeps another state per event.

Surely there must be a way to compare two datetime variable with each other, they are of the same type…

You also could have a “short” version which would look like this:

items:

Switch    Dawn_Event    { astro="planet=sun, type=rise, property=start,offset=-30" }
Switch    Sunrise_Event    { astro="planet=sun, type=rise, property=start, offset=+15" }
Switch    Twilight_Event    { astro="planet=sun, type=set, property=start, offset=-15" }
Switch    Sunset_Event    { astro="planet=sun, type=set, property=end, offset=+15" }
Switch    Dawn_Proxy    "Morgendämmerung"
Switch    Day_Proxy    "Tag"
Switch    Twilight_Proxy    "Abenddämmerung"
Switch    Night_Proxy    "Nacht"

rules:

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

sitemap:

Switch item=Dawn_Proxy
Switch item=Day_Proxy
Switch item=Twilight_Proxy
Switch item=Night_Proxy