How to determine current state after power loss

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
TonB
Posts: 11
Joined: Thursday 18 February 2021 21:32
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

How to determine current state after power loss

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to determine current state after power loss

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: How to determine current state after power loss

Post 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.
TonB
Posts: 11
Joined: Thursday 18 February 2021 21:32
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: How to determine current state after power loss

Post 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 ?
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: How to determine current state after power loss

Post 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.
User avatar
waltervl
Posts: 5904
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: How to determine current state after power loss

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
user4563
Posts: 110
Joined: Tuesday 19 October 2021 17:24
Target OS: Linux
Domoticz version: 2025.1
Contact:

Re: How to determine current state after power loss

Post 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
ODroid H4+ / Ubuntu server 24.04 LTS
Aeotec Z-Stick Gen5+
ZWave-JS-UI / Mosquitto MQTT
Domoticz for Android
Domoticz Scenes add-on in Kodi
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest