Page 1 of 1

How to determine current state after power loss

Posted: Thursday 18 February 2021 22:08
by TonB
Domoticz preserves the current states of switches and devices.
But only the last known state.

When you have a power failure and the power comes back on, the devices will be set to their last know state.

But, during this power failure some timers/events will not have been fired. (eg specific time or sun down..)

Does someone have a script, or how can I write my own, so the devices will be in the state they should be at the time the power gets back on.

example: (sun down time = 18:00)

Let's say the powerfailure accurs at 16:48 and the power get's back on at 18:35

In this example the events 011,012,013 and 0,14 will not be fired.
Resulting in :
- the Somfy blinds are open instead of the ventilation position.
- the kitchen lights are off (should be on)
- the dinner table lights are off (this is correct, but they have not been on in the meantime)

EVENT/TIME ACTION
001 : 07:00 Hallway lights on
002: 07:15 Kitchen Lights on
003: 07:15 KaKu switch koffee On
004: 08:00 Somfy Blinds open
005: 08:00 Hallway lights off
006: 10:00 Kitchen lights off
007: 10:15 KaKu switch koffee Off
008: Sun Down -1:15 Door lights on (=Sundown - 1:15 = 16:45)
009: Sun Down -1:15 Garden lights on (=Sundown - 1:15 = 16:45)
010: Sun Down -1:15 table lights on (=Sundown - 1:15 = 16:45)
011: Sun Down -0:30 Somfy Blinds Ventilation position (=Sundown - 0:30 = 17:30)
012: 16:30 Kitchen lights on
013: 17:00 Dinner table lights on
014: 18:30 Dinner table lights off

015: 18:00 KaKu switch TV console On
016: 20:00 Somfy blinds close
017: 23:15 Kitchen lights off
018: 23:20 Door lights off
019: 23:20 Garden lights off
020: 23:25 table lights off
021: 23:30 KaKu switch TV console Off
022: 00:00 ALL OFF

Re: How to determine current state after power loss

Posted: Thursday 18 February 2021 23:04
by waaren
TonB wrote: Thursday 18 February 2021 22:08 Does someone have a script, or how can I write my own, so the devices will be in the state they should be at the time the power gets back on.
should be doable in dzVents. Write a script that triggers on domoticz start and use a table with devices and the timerange(s) they should be at a certain state and (if applicable) the state outside these timeranges.

Then write two nested for loops. The outer will cycle over the devices and the inner over the timeranges. If the current time is within a timerange then switch the device to the required state and if current time is not in any timerange for the device then switch to the opposite.

Some small extra functions will be needed to convert the relative times to actual times but that is also doable.

Re: How to determine current state after power loss

Posted: Friday 19 February 2021 8:55
by EddyG
Or use, like I did, an UPS. ;) This way I have a raspberry pi that is already running for more then 894 days and still going strong.
The only downside is that it is still running jessie and Domoticz version V 4.9700, which is running for more then 277 days now without any problems.

Re: How to determine current state after power loss

Posted: Friday 19 February 2021 10:09
by TonB
Hmm, that might be an option.
But, while the raspberry is still running and all power in the house is off and in the meantime a timer is triggered, the device will not respond at that time.

When power is restored, will the devices run the "missed" trigger ?

Re: How to determine current state after power loss

Posted: Friday 19 February 2021 13:09
by EddyG
In case of Zwave, Zigbee devices, which have 2-way communication On/Off is set when power returns.
The timer set things 'inside' Domoticz, so when a plug or bulb comes online it will be set.
On some Zwave devices there are settings to restore state in the device it self.
At least that is my experience with Zigbee, I do not know exactly about Zwave, because I am in the transition of switching all zwave devices to zigbee.
Otherwise you could do both, script and UPS.

Re: How to determine current state after power loss

Posted: Friday 19 February 2021 14:12
by waltervl
This would only be relevant if you have a lot of power outages.
To go into this update hassle for 1 outage per year is probably not worth the effort.

If you have an important Switch that you want to be sure that it is switched correctly after a power outage you could also repeat the timer action for every hour (or other delta).

Or instead of using the standard timer settings use a (DzVents) script that does the complete schedule configuration and timing of all to be switched devices and check every 5 or 10 minutes if the switch is set according the schedule. So no usage of the default timer function. Downside is that if you switch one switch manually to another state it will be reset automatically.....

Zigbee and Zwave devices are reporting there current status back. For Zigbee devices, like Ikea Bulbs, they can default switch on after a power outage (build in the Ikea firmware). And that will be reported back to Domoticz.

Re: How to determine current state after power loss

Posted: Friday 07 April 2023 4:44
by user4563
Just adding that I solved the issue in my case w/ a DzVents script that runs once after power restore:

viewtopic.php?p=301762#p301762