Hi!! I have been searching but I have not found the solution to what I want to do.
I have a switch that activates the “day mode” by astro binding sunrise, but if I restart the openhab (i.e Cut electricity), it returns to its OFF state.
I liked to put in the start rule that if the current time is higher than the Sunrise time, activate the switch if it is not activated.
I understand what it should be:
If CurrentDate > Sunrise_Time
But “CurrentDate” contains more data than the time (day, month, year) and I do not know how to separate them to compare them later.
I hope you can help me.
val Functions$Function1 <String, Integer> ToMin = [ s |
(new Integer(s.substring(0,2)) * 60) + new Integer(s.substring(3,5))]
var MoD = now.getMinuteOfDay
var MoD_Sr = ToMin.apply(Sunrise_Time.state.toString.substring(11,16))
Yes, while CurrentDate contains more data than time, so does Sunrise_Time. Both are a complete DateTime and both include day, month, year, timezone, etc. You don’t have to separate them out. The simplest is to get at the epoch (i.e. number of milliseconds since 1970-01-01 00:00:00 GMT) and compare those numbers, which you will see in the DP above.