Page 1 of 1

Mains failure backup and detection

Posted: Monday 30 November 2015 14:28
by Dave21w
Hi Guys,

This is my first post here, currently only using LWRF kit with their WiFi Link but looking to change to a Pi and USB RFXCom, this got me thinking, I'm no programmer but electronics hardware is no problem for me so i'd be happy to share my ideas, if we power the Pi via a 9-20v in 5v out dc-dc switcher (eBay) we could then use a standard 12v lead acid battery which is being float charged to power it much as a house alarm does, if possible could Domoticz inlcude a mains failure option on one of the GPIO pins, it would be easy to detect a failure and return of the mains supply with a bit of hardware and maybe a delay in the software to ensure the mains was back to stay (say wait 5 mins to confim) the reason behind this is if Domoticz monitored what was turned on when the mains failed providing the off time for that item had not passed it could then resend the on commands so that from a security point of view any lights that should be on because its past dusk would be turned back on so your house would still look occupied.

Hope this isnt too much of an ask for my first post

Cheers

Dave

Re: Mains failure backup and detection

Posted: Monday 30 November 2015 14:48
by ThinkPad
Usecase for this is quite small, if you have Z-Wave this problem isn't even existing. Z-Wave is a two-way protocol so the switches will be synchronized to the demanded status in Domoticz.

For the powerloss issue i have my server (Intel NUC) that runs Domoticz (virtual machine) behind a UPS, together with all the electronics in my metercabinet (modem, router, switch etc.)
Stupid thing however, is that my UPS doesn't have a USB-connection. So my server still has no knowledge if the mains power is present. Maybe i will switch to a UPS with a USB-connection if i see something coming by for cheap (i bought this UPS for almost nothing, battery was broken, popped in a new battery myself).

As a workaround i thought of pinging a device in my home that is not protected by the UPS, but if i have problems with my router or so, this would lead to shutting down the server :?

Re: Mains failure backup and detection

Posted: Monday 30 November 2015 14:56
by nigels0
@Dave,

Good idea. I use this: http://www.piups.net which basically does the whole shutdown thing. Possibly not too difficult to add the startup function you suggest as the Python shutdown code is available.

Re: Mains failure backup and detection

Posted: Monday 30 November 2015 15:01
by ThinkPad
nigels0 wrote:@Dave,

Good idea. I use this: http://www.piups.net which basically does the whole shutdown thing. Possibly not too difficult to add the startup function you suggest as the Python shutdown code is available.
Thanks, but i'm not using a Raspberry Pi but a full blown PC (Intel NUC) with a real UPS (MGE Ellipse). Works fine, but like i said: downside is that it doesn't have any USB/Serial signaling to let my PC know that the power is gone.

Re: Mains failure backup and detection

Posted: Monday 07 December 2015 11:47
by ThinkPad
I was thinking about building something with an Arduino.

Arduino connected (and powered!) through USB to my server. Then a mains adapter (not plugged into the UPS, but directly on mains) that puts 5V (or so) on a digital pin of the Arduino.
If pin is high (=mains available) = Serial.print("PWR:OK")
If pin is low (=mains is gone) = Serial.print("PWR:LOSS")

Then a script that reads the serial output every minute. If it counts "PWR:LOSS" ten times (=10 minutes) then shutdown ESXi, and thus, the server. And it also needs to send a shutdown command to my Synology NAS over SSH because that one is also behind the UPS.

How does that sound? Things that need improvement?

Re: Mains failure backup and detection

Posted: Monday 07 December 2015 11:57
by jannl
You always can check the uptime and react accordingly

Re: Mains failure backup and detection

Posted: Monday 07 December 2015 11:59
by ThinkPad
jannl wrote:You always can check the uptime and react accordingly
Check the uptime of what?

Re: Mains failure backup and detection

Posted: Monday 07 December 2015 12:00
by jannl
Uptime of the server, uptime of domoticz.....

Re: Mains failure backup and detection

Posted: Monday 07 December 2015 12:10
by ThinkPad
That is maybe useful for the topicstarter, i have my server and NAS behind a UPS to prevent powerloss.
But like i said, my UPS doesn't have a USB-connection so i don't know if the power is gone or not.

Re: Mains failure backup and detection

Posted: Monday 07 December 2015 12:37
by jannl
Same here.
A script checks if the UPS is online, if not the pi shuts down after 5 minutes.
NAS shuts down after 10 minutes and switches of the UPS.

Only problem is when the power gets back after about 7 or 8 minutes. Nas will not shutdown and the Pi does not reboot automatically. The never happened and if it does a lot I might figure out a way to start the Pi via WOL or so from the NAS.

Re: Mains failure backup and detection

Posted: Monday 07 December 2015 14:10
by Dave21w
Thanks for all your replys and suggestions, I know alot of people here use a UPS and i suppose that is the easier option but the run time on those is usually 20 to 30 mins,the main reason behind doing it the way i was suggesting was that running from a standard alarm battery (12v 7Ah with suitable switching regulator) the battery powered run time for the Pi would be about 20hrs, no need shutdowns and having to wait till you get home to restart it again and once the mains is restored and detected then domoticz could resend on commands to stuff that should be on . I am also looking at powering some of my other network related devices the same way so hopefully my network switch and virgin media (not so super) super hub will not lose power, obviously if the cabinet in the street where my internet feed comes from is on the same phase as my house then the internet is down anyway !!

Once again thanks for all your feedback

Dave