Rule handling tomorrow daylight

So, I have the following items:

DateTime Night_Start "Night Start [%1$tH:%1$tM]" { channel="astro:sun:myastrothing:night#start" }
DateTime Night_End "Night End [%1$tH:%1$tM]" { channel="astro:sun:myastrothing:night#end" }
DateTime Day_Start "Day Start [%1$tH:%1$tM]" { channel="astro:sun:myastrothing:daylight#start" }
DateTime Day_End "Day End [%1$tH:%1$tM]" { channel="astro:sun:myastrothing:daylight#end" }

And, the following in rules:

val night_beg = new DateTime(Night_Start.state.toString)
val night_end = new DateTime(Night_End.state.toString)
val day_beg = new DateTime(Day_Start.state.toString)
val day_end = new DateTime(Day_End.state.toString)

And the following logic in a rule:

	if(	now.isAfter(day_end)  &&
        now.isBefore(day_beg)  &&
		zwave_device_16500637f6a_node11_switch_binary.state == OFF) {
			logInfo("Driveway Motion Rule", "Send Amber lamp on")
			createTimer(now.plusMinutes(30), [ | zwave_device_16500637f6a_node11_switch_binary.sendCommand(OFF) ])

The intent being to have the light come on for 30 minutes, if it between day_end and day_beg (day_beg as in the beginning of tomorrow).

Since the light never comes on, I’m guessing my day_beg is actually referring to beginning of the current day, thus the logic fails.

Assuming this is the case, I need to add 24 hours to day_begin. (I don’t see any “tomorrow morning” like methods on now() or Astro…but, that could be my search engine skills. :smirk: )

I’m thinking I could add another Astro thing with an offset of 24 hours, but is there an easier/better way?


So, when the day_beg var is created it has a method plusHours() because the var type is a DateTime?
(And DateTime is based on the Joda DateTime class?)

Yes, it has that method (and many others) because it is type DateTime.

BTW, when you edit your rules using VS Code with the openHAB extension, you can see all the methods available – a great time saver.

Yeah…but, you don’t see those methods unless you type a period after the name. And, I hadn’t thought to do that. :blush:

And, I could just use plusDays(1) as well…now that I type a period (I also have a bookmarked link to the DateTime Joda page.) :grinning: