Thanks for the tips, the logInfo line fixed the error. I also created the thing called astro:sun:minus90 (sorry for not seeing this myself
)
I rebooted the OpenHab but still I am not seeing the correct current time of the day
.
The log now looks like this:
2019-10-12 12:59:29.306 [vent.ItemStateChangedEvent] - vMorning_Time changed from NULL to 2019-10-12T06:00:00.000+0200
2019-10-12 12:59:29.328 [vent.ItemStateChangedEvent] - vNight_Time changed from NULL to 2019-10-12T23:00:00.000+0200
2019-10-12 12:59:29.331 [vent.ItemStateChangedEvent] - vBed_Time changed from NULL to 2019-10-12T00:00:00.000+0200
==> /var/log/openhab2/openhab.log <==
2019-10-12 12:59:33.679 [INFO ] [b.handler.EspMilightHubBridgeHandler] - Sucessfully subscribed to milight/states/#
==> /var/log/openhab2/events.log <==
2019-10-12 12:59:34.538 [hingStatusInfoChangedEvent] - ‘zwave:device:a5af8125:node6’ changed from OFFLINE (BRIDGE_OFFLINE): Controller is offline to ONLINE
2019-10-12 12:59:34.545 [hingStatusInfoChangedEvent] - ‘zwave:serial_zstick:a5af8125’ changed from OFFLINE (BRIDGE_OFFLINE): Controller is offline to ONLINE
2019-10-12 12:59:34.552 [me.event.ThingUpdatedEvent] - Thing ‘zwave:serial_zstick:a5af8125’ has been updated.
2019-10-12 12:59:34.555 [hingStatusInfoChangedEvent] - ‘zwave:device:a5af8125:node5’ changed from OFFLINE (BRIDGE_OFFLINE): Controller is offline to ONLINE
2019-10-12 12:59:46.972 [hingStatusInfoChangedEvent] - ‘zwave:device:a5af8125:node5’ changed from ONLINE to ONLINE: Node initialising: REQUEST_NIF
2019-10-12 12:59:47.424 [vent.ItemStateChangedEvent] - SW_Buitenlamp changed from NULL to 0
2019-10-12 12:59:47.692 [hingStatusInfoChangedEvent] - ‘zwave:device:a5af8125:node5’ changed from ONLINE: Node initialising: REQUEST_NIF to ONLINE
2019-10-12 12:59:59.360 [hingStatusInfoChangedEvent] - ‘ntp:ntp:local’ changed from ONLINE to REMOVING
2019-10-12 12:59:59.372 [hingStatusInfoChangedEvent] - ‘ntp:ntp:local’ changed from REMOVING to REMOVED
2019-10-12 12:59:59.421 [hingStatusInfoChangedEvent] - ‘ntp:ntp:local’ changed from REMOVED to UNINITIALIZED
2019-10-12 12:59:59.437 [hingStatusInfoChangedEvent] - ‘ntp:ntp:local’ changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)
==> /var/log/openhab2/openhab.log <==
This is my things file:
Thing astro:sun:minus90 “Offset -90” [geolocation=“12.34578,1.23456,123”, interval=300]{
Channels:
Type rangeEvent : set#event [
offset=-90
]
Type start : set#start [
offset=-90
]
Type end : set#end [
offset=-90
]
}
Thing astro:sun:local “Local Sun” [geolocation=“12.34578,1.23456,123”, interval=300]{
Channels:
Type rangeEvent : rise#event [
offset=-0
]
Type start : rise#start [
offset=-0
]
Type rangeEvent : set#event [
offset=-0
]
Type end : rise#end [
offset=-0
]
}
This my time of the day rules file:
rule “Calculate time of day state”
when
System started or // run at system start in case the time changed when OH was offline
Channel ‘astro:sun:local:rise#event’ triggered START or
Channel ‘astro:sun:local:set#event’ triggered START or
Channel ‘astro:sun:minus90:set#event’ triggered START or
Time cron “0 1 0 * * ? *” or // one minute after midnight so give Astro time to calculate the new day’s times
Time cron “0 0 6 * * ? *” or
Time cron “0 0 23 * * ? *”
then
// logInfo(logName, "Calculating Time Of The Day")
logInfo("Calculate time of day state", "Calculating Time Of the Day")
// Calculate the times for the static tods and populate the associated Items
// Update when changing static times
// Jump to tomorrow and subtract to avoid problems at the change over to/from DST
val morning_start = now.withTimeAtStartOfDay.plusDays(1).minusHours(18)
vMorning_Time.postUpdate(morning_start.toString)
val night_start = now.withTimeAtStartOfDay.plusDays(1).minusHours(1)
vNight_Time.postUpdate(night_start.toString)
val bed_start = now.withTimeAtStartOfDay
vBed_Time.postUpdate(bed_start.toString)
// Convert the Astro Items to Joda DateTime
val day_start = new DateTime(vSunrise_Time.state.toString)
val evening_start = new DateTime(vSunset_Time.state.toString)
val afternoon_start = new DateTime(vEvening_Time.state.toString)
// Calculate the current time of day
var curr = "UNKNOWN"
switch now {
case now.isAfter(morning_start) && now.isBefore(day_start): curr = "MORNING"
case now.isAfter(day_start) && now.isBefore(afternoon_start): curr = "DAY"
case now.isAfter(afternoon_start) && now.isBefore(evening_start): curr = "AFTERNOON"
case now.isAfter(evening_start) && now.isBefore(night_start): curr = "EVENING"
case now.isAfter(night_start): curr = "NIGHT"
case now.isAfter(bed_start) && now.isBefore(morning_start): curr = "BED"
}
// Publish the current state
logInfo(logName, "Calculated time of day is" + curr)
vTimeOfDay.sendCommand(curr)
end
The item on my sitemap says: Current time of the day: UNKNOWN