Item states on restart/reboot

I have some item states which are set based in, for example, sunset. So I have this:

rule "Sunset"
when
   Channel 'astro:sun:home:set#event' triggered START
then
   IsItDark.postUpdate(ON)
end

Then I also have:

rule "EveningMode"
when
        Item IsItDark changed to ON
then
        EveningMode.postUpdate(ON)
        DayMode.sendCommand(OFF)
        NightMode.sendCommand(OFF)
end

But if I restart, they all get set back to NULL and nothing works unless I use the REST API to set everything back on track.

Is there a way to get round this?

Cheers
Andy

What do you have set up for persistence?

Persisting and restoring your “dark” Item covers many cases.
It relies on your openHAB not being out of service for long, as it simply “remembers” the last state of the Item at boot up time.

There is a risk that if you reboot when an event is due - sunset, say - then the restored will be wrong, and stay wrong, until sunrise.

The most complete solution is a rule that runs after boot up, triggered by System started
This can compare if “now” is before sunrise or after sunset, and set your “dark” Item.
To do that, you would need to set up further Items linked to Astro binding’s state channels. These would get populated with sunrise and sunset times for that day at boot up or each midnight.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.