I am using Network UPS Tools add-on with two UPS connected to it. Within each device, there is an entity that will indicate when the UPS is “online”–utility power or “on battery”.
I want to create automations to send notifications when the UPS enters “on battery” state and notification when the UPS enters “online” state.
Looking at the using the device as a trigger–the only options are voltage changes, load changes, battery level, but no status like online and on battery.
There is a “status” entity that does report this information, however, in automation, when I select the entity using “State” as the trigger, under “From” and “To” the only attributes for that entity is “unavailable” and “unknown”. The online and on battery states are not available.
A workaround is using the UPS device and set input voltage thresholds, but I rather use the online and on battery status. I am trying to do this via GUI as I am not proficient with YAML.
Yes, the entity reports either “online” or “on battery”.
Edit: So the entity does accurately report the UPS state. I thought these possible states would be selectable as states or attributes in automation, but they are not there.
I think they probably should, but this could be an anomaly of the ups and not Homeassistant. I would just type the exact word that you want in your automation that you now know the state is changing to.
@pcwii and @ServiceXp thank you for your replies. When I go to the entity, while it’s on utility, it reads “online”, while it’s on battery, it reads “on battery”. I presume I would use these strings in the attribute field?
I will try this the next chance I get. Right now I am trying to see how I can get back some automations that disappeared after 2023.6.1 update.
Thank you, @FriedCheese, with your script, I was able to use the visual editor to replicate the settings and verify them in YAML. Through this, I learned new tricks on how automation is done.
I will test the notifications later today and report back.
I have my UPS going through a smart plug so can test on the fly. Should work, with the caveat that NUT can take a bit to update depending on what you have the scan interval set to in the integration.
Thanks @FriedCheese. Both my NAS-connected APC and HA-host-connected CyberPower have three states: Online, On Battery Battery Discharging, and Online Battery Charging. Using your example, I created three triggers and three actions. The notification seems to be working. Cheers.
Edit: Yes, whereas the NAS will notify immediately, NUT takes a bit to update and send the notification, but well under 30 seconds.
This works great, HOWEVER…if the mains power comes back on before the UPS runs out, there doesn’t seem to be a signal to tell the HA server to power back on. or if there is, I dont know where. the UPS is an APC ES 850G2
I have been having a lot of ‘blips’ in our power lately, losing power for 30 seconds. Long enough obviously to pull the rug out from the HA server. So, not wanting to play anymore russian roulette, I decided to plug the HA into the UPS (I never did before as I figured, if i lose power, the HA system is pretty much useless) I configured an automation that monitors the NUT server on my Synology NAS, when the UPS Battery level drops to 90% it signals the HA Supervisor: Power Off the Host. The HA Server is configured to restart when power is restored, but in my blip case, The UPS never completely lost power.
Yeah…that’s one of those round robin situations. You need something to monitor the UPS that can do something like send a WoL packet to the HA gear when power comes back. I have a few setup with a Raspberry Pi Zero W that could do that
I have mine setup to not shut down until the UPS gets down to about 15% and all my network gear is running off the same UPS, so more than a blip is going to drain the batteries. My HA server is setup to power on when power is restored. I also have it running through a WiFi plug as a backup to toggle power and trigger a boot.
Thanks @FriedCheese
I have to be careful, as I need the HA to shut down prior to the NAS going into standby as I then lose my NUT devices. Maybe the best alternative is your suggestion of a smart plug to toggle when I’m away.
My nick is 20 years old from an old company i started and never changed
That all sounds very convoluted. IMO, the correct solution is to get a ups that has the runtime you desire and call it good. I got a 4U triplite that gives me 90 minutes of runtime at a 25% nominal load. Gives plenty of time to get home in most situations before things really go pear shaped.
HA, my network gear, and my cable modem are all on it, and HA sends me an alert when it switched from online to on battery, via NUT.
Actually, its not as convoluted as it sounds. I discovered an oversight in my UPS Server options. I failed to set ‘Shutdown UPS when the system enters Standby Mode’. The NUT server is set for going to standby at 10 minutes. I then set the HA automation to trigger on UPS status Data going from OL to OB for 35 seconds and to wait 9 minutes and then issue the power off host. When the Mains comes back, the UPS turns back on and that of course triggers the HA Server to restart.
This way there is a very small 1 minute window where the power could come back on and the UPS wouldn’t have shut off. But a cheap WiFi plug can cover that contingency from when I’m out of the country and cant manually toggle
Interesting workflow. Have you tested that the ups returns to powered on when line power is restored?
I’m also curious how you will control the wifi smart plug if HA is down. Presumably it’s some cloud-connected flavor like kasa or similar?
Also, NUT is able to get runtime data from my ups. Have you tried using that instead of the timer? Say, when remaining runtime is less than x minutes, then initiate the shutdown sequence.
I think it’s only convoluted if you’re trying to have contingency plans for every situation.
For me, the plug was put in some time ago and getting it removed just isn’t a priority plus it gives me a backup to the backup. It’s a Kasa plug that’s barred from the Internet, but I have Wireguard setup to get local access if needed.
The reality is that if I have extended power outage while I’m home, the UPS just keeps things floating until I get the generator in my truck hooked up. If I’m gone, I’ll just shut HA down and let the network gear stay powered up off the UPS.