I would like to use my UPS charge state to trigger a shutdown of the pi that runs my HA instance. I would like to prevent a crash and possible SD card corruption.
So, can I just call the service hassio.host_shutdown at a set charge level and if I do will it shut down the system?
yes, as long as you are using hass.io with hassOS. If you upgraded hass.io when it was using ResinOS, then it will not work. So, if you upgraded hass.io from 0.74 or lower to 0.74 or higher, hassio.host_shutdown will not work. If you installed hassio 0.74 or higher, that uses HassOS and you should be good to go.
Petro, I was running hass.io long before .74, so what is the process now? I did have to do a couple of fresh builds in the past, not sure what the versions were at this point. How would one tell if this will work?
I don’t know if it will work. Try the service and verify that it works. The fact that it says resin OS doesn’t mean that DBUS is on the system and working.
I got it working! Yes, I can communicate via USB with the CyberPower ups and I get regular state updates!
1 basic automation… I have built several to shut down and notify now that it is working. I also have it working with a pi running nut connected to another remote ups.
UPS Automation
id: UPS_01
alias: ‘Notify when UPS goes on battery’
trigger:
platform: state
entity_id: sensor.nut_ups_status_data
from: ‘OL’
to: ‘OB DISCHRG’
action:
service: notify.sms_matt
data:
title: “Alert from HomeAssistant”
message: “Home UPS on battery”
I am using the addon Network UPS Tools to monitor the local ups and since it installed Nut on the HA server, I was able to add the sensor to communicate with another pi running Nut.
I find nut easier than apcupsd, have tried it a few times over the years and it was a PITA. The best part here is the addon works for basic 1 ups connection. After that, it is just setting nut up on additional systems in netserver mode and adding sensors! I will admit, from start to finish I have about 6 hours in making this work, but that also includes 8 automations and the front end stuff. I still have to work out a couple of command line scripts to shut down a couple of other pi’s, I find those to be painful as I always have trouble getting keys to work properly.
The cyberpower was originally connected to a sometimes on / sometimes off windows 10 system and the software is super basic and would not send a shutdown to the HA server. I have crashed it a couple of times over the years and had to rebuild, hope to avoid that issue.
Not sure about windows version… I am shutting down windows machines with HA automations.
Can you explain the last question? I do not run standalones or slaves. If it has a pi attached, it is getting the nut install and netserver mode. I do leave the local listener enabled and could use that, but HA is incharge of passing on shutdown commands not the local nut installs.
Does that make sense?
I would be willing to zip up one of my conf directories to give you more of a starting place.
i see different configs with multiple computer set as slaves… but i guess 1 pc/ ups then they would all be standalone as long as netserver is transmitting information that HA can pick up. And shutdown procedures would be per ups
also do the add-on config only set it up if your have the ups on the same machine as HA instance? none of mine are.
You could go that route, I chose to leave the local listener so I could troubleshoot issues from the local command line. But the biggie for me was getting the netserver running.
Shutdown proceedures would be per ups/per system based on HA automations. My main ups running HA and some critical networking also has my big bad win10 pc attached. Based on the ups state and charge levels I shut down the windows machine and shutdown the monitor with a sonoff switch. The monitor at idle sucks a fair amount of power. All done to extend the time that HA and the associated switch stay up as long as possible. You will want to check the states incase power drops back out during the recharge process as well. Once could do it based on input voltage as well.
The add-on is designed for a locally attached UPS, but one does not have to be there. The key is that it gets nut running on the HA server and allows for the Nut sensors to be built. Once could just not build sensors for a local UPS.
I got the notification working when the UPS changes status, but what about shutting down Home Assistant?
I can easily set an action that runs 10 minutes after the status changes from OL to OB DISCHRG and call the hassio.host_shutdown service, but what about canceling the shutdown if the UPS gets to OL again within those 10 minutes?