I am building a Home Assistant system that needs to work reliably at a location far from where I live. I am thinking about graceful shutdown and restart in case of power failure and have some ideas, but wonder if anyone else has a setup actually working?
I am running HA on a Dell Optiplex 3050 MFF.
I acknowledge previous discussions but they do not cover all of this and are specific to the Raspberry Pi:
I can of course connect the computer and the internet router to a UPS. Then there is no problem as long as the power comes back on before the battery goes flat. After that, it would still fail in an uncontrolled way, like just turning off the power when there is no UPS, and that leaves a risk of database corruption if HA happens to be in the middle of an operation at the time.
I have in mind a small battery-operated device that operates autonomously when HA is off but connects to it when its is on.
It would require
ā a means of communicating with HA (Ethernet, ZigBee, Bluetooth or WiFi)
ā a 230V voltage detector connected to the mains before the UPS, to detect the power failure and inform HA (which will notify me)
ā some way of determining UPS battery status, e.g. DC voltage measurement (?) to inform HA it has to shut down
ā a means of restarting the HA computer, e.g. a relay that does the equivalent of pushing the start button
Has anyone built anything like this for a reasonable price? Perhaps a Shelly Uni plus a 240V relay for the mains detector? Perhaps an ESP32 with a relay for the computer restart output? In either case the power could come from a decent sized battery pack or a separate UPS that would last a very long time compared with the one being monitored??
By luck 5 or 12V input maybe? Could then make use of a power bank that can be charged and discharged at the same time (āpower pathā). Just need to add a esp than into the mix and some detection if the power bank is charged - or maybe even just read the charge level (ether by measuring the cell voltage or maybe some diodes to detect leds indicating the charge percentage).
Obviously need to check if the switching of the power source is āfastā enough to donāt crash the mini pc.
For the esp(home) part this could be the snippet to tell HA to do a graceful shutdown:
I already set the BIOS to recover when the power comes on and that works OK. The question is how to shut it down in a controlled way that would not interfere with the restartā¦
19V actually, but I have a power pack for that. The computer (a Dell Optiplex) complains that it is not the original power supply but the BIOS can be set to ignore that, so it does work. However it does not report when the mains is off or what the battery level is.
I could buy a separate mains voltage detector and when that goes off, invoke the shutdown procedure, but I do not know how to restart the computer when the mains comes back if the power pack is still providing voltage.
There are smart UPSs that report their mains and battery levels, but then I would need another processor to listen to it over USB that does not require a UPS itself, and presumably a switch in the 19V supply to turn the main computer back on when the power comes back. I was looking for something simpler and cheaper!
im sorry that its in portuguese,but i think its okay to understand with auto translate subtitles.
he is using some ideas that you have, node mcu+ analog voltage sensor and some code, looks a little difficult because he have to calibrate this analog sensor a little, to roughly find the values for energy on or off.
then he uses the state of the energy to create automation to shutdown the home assistant.
For your restart, maybe you can use mqtt on another device, maybe a router with openwrt, to send a wake on lan package for your home assistance, thats one idea.
Yes, thatās the kind of thing I had in mind, and a cheap solution! Thanks.
Wake-on-LAN is a great one for the restart (it is available for my Dell Optiplex) and if I get an ESP32 with an ethernet module I could program it from HA with ESPHome to take care of the restart with WoL as well as signalling mains failure for the HA self shutdown. That would work with a cheap 19V UPS like the Eaton 3S Mini.
I wonder how to detect a running appliance on AC via voltage anyways because it doesnāt matter if a device is on or not as the voltage will/should always be the same
You donāt. If you want to detect whether a device is running use a plug with a current monitor. But here we want to know if there is a power cut, and that we do with voltage.
I do not know the ins and outs of the HA database, but I assume HA must write some data to disk sometimes as there would otherwise be no persistence over a restart. Whatever that data is, there is a risk ā as with any computer system ā that if it happens to be in the middle or a write operation when power is lost, data could be corrupted.
It has never happened to me yet with HA so perhaps the risk is low? I have not made a high priority of this project!
There is as far as I know no persistency, that is also the reason that any running automation will restart when ha is being restarted. To my knowledge only statistics are stored.
So if you use a āvirtualā database, it will only reside in memory, and no data is written to diskš
Just wondering if thereās a proper solution to this?
Iām running adguard on my HA on a DELL optiplex small form factor.
and found that whenever I lost power, and although thereās that BIOS setting to power on automatically, adguard always get itself in its knickers in a twist. So I have to manually power cycle in again one more time before things goes smoothly again.
Thanks
Hi Andy,
Have you got any solution identified that is working for you? I am in similar situation where the Dell Optiplex 7050 Micro running HA is sitting in a corner room in wild. I have put the system and few of the ESP chips behind 660VA UPS to protect them from abrupt power outages. I am thinking to use one of the cloud based switch that we use to power on the HA remotely with similar BIOS settings that you have. The cloud based switch will be triggered to power on the HA whenever needed. Since this setup is headless the UPS will continue run for 30 minutes.
My idea is this. When HA detects the cloud based switch is offline for more than 20 minutes it will trigger shutdown command and halt. Before shutting down it will generate an email mentioning its status. If you have found any better way please share.