Compare Hours/Minutes (NTP Binding)

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.
Thank you.

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))

Why don´t you use persistence with restore on startup?

(mapdb for example would fit to your example)

If you change the state of your switch with a rule, you mey get unwanted things be done every time you restart openhab on daytime.

Maybe you open your rollershutters in the morning with this day-switch and you close them on noon manually, the shutters will open on every restart of openhab… Maybe this is unwanted behavior.

halloween has the correct answer.

For completeness…

See Design Pattern: Time Of Day for examples of how to do the comparison.

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.

I’m a novice even in this, but I’m going to look at persistence since it’s one of the things that as you say is essential in a good configuration of the house. (blinds, lights …)

Thanks!!!

Thanks for the examples, they will help me a lot to go complicating my rules, I am still migrating from Vera and it is costing me a bit to adapt, but openhab I like every day more.

woow, I see that I still have a lot to learn, I’ll try it, thank you very much