Page 1 of 1

Power Outage / Catch Up

Posted: Sunday 29 September 2013 17:06
by maq1017
Really impressed with Domoticz. The one thing I'm not sure is covered is what happens in a power outage, from what I can see any timers that should have been performed during the downtime/outage would be missed.

I'd really love to see an implementation of the system knowing when it last did something (maybe via logs or a custom variable that gets written out every so often?) and checking the state of items that should have been turned on since an outage, as my concern is a power outage at the wrong time could mean all lights remain off until the next trigger happens to arrive (likely the next day)

In the meantime, I think I can write a bash script to plug the gap but would love to know what anyone else has done, if they've faced a similar issue

Thanks
M.

Re: Power Outage / Catch Up

Posted: Wednesday 24 August 2016 21:20
by anasazi
Hi,

I know this is an old thread but is this function implemented in Domoticz?
If not, does anyone know how this can be done instead?

Re: Power Outage / Catch Up

Posted: Thursday 23 June 2022 6:11
by user4563
What solutions have you all used after a power outage to turn on switches that should be on (or off) in the timer period?

I'm looking to implement this.

Re: Power Outage / Catch Up

Posted: Thursday 23 June 2022 9:38
by lost
user4563 wrote: Thursday 23 June 2022 6:11 What solutions have you all used after a power outage to turn on switches that should be on (or off) in the timer period?

I'm looking to implement this.
There is no easy way I'm aware off just to get current schedule setpoint (if any) of a given switch. In my case, that's not to handle a power failure case as my PI hosting Domoticz have a battery backup able to last several hours, but for my heating control that is mostly managed by schedules but also take into account presence or door/window that remains opened too long: No way to set back heaters setpoints easily to current scheduled one.

That's IMO a missing feature that would be helpful.

Re: Power Outage / Catch Up

Posted: Thursday 23 June 2022 23:23
by user4563
I don't have time now but maybe I can look into doing this through DzVents. This would cover light timers after a power on from a power outage.

PseudoCode:

Fire script once on power up
Sleep until all nodes have been queried.
if current time is after sunset and before sunrise, turn on lights
if current time is after sunrise but before sunset, turn off lights

Re: Power Outage / Catch Up

Posted: Friday 07 April 2023 4:39
by user4563
So after too many outages, here is my solution for my scenario:

5 minutes after my Windows PC boots from a power outage, I have task scheduler run a PowerShell script to start a DzVents Script:

PowerShell:

Code: Select all

Invoke-WebRequest -Uri "http://127.0.0.1:8080/json.htm?type=command&param=customevent&event=power_restored"
or cURL:

Code: Select all

curl --url "http://127.0.0.1:8080/json.htm?type=command&param=customevent&event=power_restored"
5 minutes because I need to make sure all of the Z-Wave nodes are queried first. Domoticz is usually complete in 2 minutes for me. *nix users can add a cronjob.

The DzVents script:

Code: Select all

return {
    
    on = { 
		customEvents = {
		    'power_restored',
	                    }
	     },
	 
	execute = function(domoticz, item)

            --execute only from sundown to sunrise (night)
            if (domoticz.time.isNightTime == true) then
                    
                    domoticz.devices('Kitchen deck').switchOn().checkFirst()
                    domoticz.devices('Porch light').switchOn().checkFirst()
                    domoticz.devices('Kitchen deck').switchOn().checkFirst()
                    domoticz.devices('Living deck').switchOn().checkFirst()
                    domoticz.devices('Garage lights').switchOn().checkFirst()
                    domoticz.devices('Driveway lights').switchOn().checkFirst()
                    domoticz.devices('Deck rail lights').switchOn().checkFirst()
            else
               
             --execute only from sunrise to sundown (day)

                    domoticz.devices('Kitchen deck').switchOff().checkFirst()
                    domoticz.devices('Porch light').switchOff().checkFirst()
                    domoticz.devices('Kitchen deck').switchOff().checkFirst()
                    domoticz.devices('Living deck').switchOff().checkFirst()
                    domoticz.devices('Garage lights').switchOff().checkFirst()
                    domoticz.devices('Driveway lights').switchOff().checkFirst()
                    domoticz.devices('Deck rail lights').switchOff().checkFirst()
            end  
               
    end     
 }
It's just simply checks if it's after sundown then make sure the lights are on or if it's after sunrise make sure they are off.

Using the customEvents you save resources as it only fires on a power restore as a normal DzVents script would fire every minute and using checkFirst() you keep your z-wave network traffic down.

My lights simply follow sundown to sunrise so change according to your schedule/needs after a power outage. Custom times can easily be accomplished with something like:

Code: Select all

            if   (domoticz.time.matchesRule('between 45 minutes before sunset and 11:59')) then
                
                     -- do something

            else
                
                    --do something else

            end