Using automation to shutdown home assistant pi

Thanks for the info… it looks like I am in luck!
image

I will get started testing this to verify that it works.

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.

So, the service call works… How would it build the service section in an automation to shut the system down?

You’d need to have access to your apc. Does home assistant communicate with it?

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.

  • platform: nut
    alias: lrups
    name: “LR UPS”
    username: upsmon
    password: nut
    host: 192.168.1.196
    port: 3494
    resources:
    • ups.load
    • battery.charge
    • input.voltage
    • battery.runtime
    • ups.status
    • ups.model

My resulting cards.

nut is so confusing to set up… i have 2 windows pcs and 1 linux… right now. ive got apcupsd but that only limits me to one :frowning:

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.

im sure i can get it working on the HA side… i just havent found good instructions on how to install on each comp plugged into a ups.

Good starting point document… This is set up in standalone more, but only need to add netserver mode and add a listen ip / port combo to get it going.

1 Like

just gotta find a windows version. thx

how do you have your standalone/slaves and everything setup?

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.

Does anyone know of a good non-hassio Docker install method for NUT on Linux? it will be on the same NUC (running Debian 9) that is running HA.

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?

Use a timer to do the shutdown, and cancel the timer if the OL gets up again ?

Would something like this work?

Use the “for” setting on the trigger. If UPS is “on battery discharging” for 8 minutes, shutdown home assistant.

I guess if the UPS comes online again before the 8 minutes the action will not run, right?

1 Like

That’s perfect, thank you!

I combined your timeout with this solution for detecting power outages:

I ping my router every minute. It’s not on an UPS so if it’s down, that means that I don’t have electricity anymore (granted, I’m trusting its reliability more than that of my electricity grid, but that’s a risk I’d rather take than having my Home Assistant corrupted due to a power outage)

Just for reference, this works just fine:

Hello how I can shutdown my proxmox external server?