Graceful shutdown and restart in case of power failure

As yet only on paper. I plan to get a UPS with a NUT (Network UPS Tools) interface, connect it with the HA NUT integration, and write an automation to shut down when battery level is low.

That should be good idea and ideal way to go. Since this setup is for my friend who wants to keep the cost lower, he went with the normal APC ups without any NUT features.

1 Like

I use the following automation setup for managing my UPS in my rack that handles all the primary gear that is connected to it. The actions at 10% charge left are actioned through hass.agent’s MQTT commands to the client installed on the main PC and NAS is set to safe shutoff on its own once the press action is activated and everything to power on when power is restored.

I have a seperate automation setup to notify me when my HA instance has restarted and use a switchbot bot to turn on and off the usb port that my skyconnect is plugged into on my mbeat 7 port hub which I also got rid of the battery from and swapped in a cr2 battery eliminator cable so I don’t have to worry about new batteries when I am not home should I need to control it.

I have smart plugs as well set to on state on power restore as well as backup for core devices to act as a auto power switch for the restore on power loss setting to work more consistently as a failsafe.

alias: UPS Automations
description: ""
trigger:
  - type: battery_level
    platform: device
    device_id: 
    entity_id: 
    domain: sensor
    below: 99
    for:
      hours: 0
      minutes: 0
      seconds: 30
    id: UPS Discharging
  - type: battery_level
    platform: device
    device_id:
    entity_id: 
    domain: sensor
    below: 50
    for:
      hours: 0
      minutes: 0
      seconds: 30
    id: "UPS Discharging: 50%"
  - type: battery_level
    platform: device
    device_id: 
    entity_id: 
    domain: sensor
    below: 10
    for:
      hours: 0
      minutes: 0
      seconds: 30
    id: "UPS Discharging: 10%"
  - platform: state
    entity_id:
      - sensor.main_ups_status
    from: null
    to: Online Battery Charging
    id: UPS Charging
    for:
      hours: 0
      minutes: 0
      seconds: 5
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - UPS Discharging
        sequence:
          - service: notify.mobile_app
            metadata: {}
            data:
              title: UPS
              message: Main UPS is Discharging
              data:
                notification_icon: mdi:battery-arrow-down
                color: yellow
      - conditions:
          - condition: trigger
            id:
              - "UPS Discharging: 50%"
        sequence:
          - service: notify.mobile_app
            metadata: {}
            data:
              title: UPS
              message: Main UPS is at 50%
              data:
                notification_icon: mdi:battery-50
                color: yellow
      - conditions:
          - condition: trigger
            id:
              - "UPS Discharging: 10%"
        sequence:
          - service: notify.mobile_app
            metadata: {}
            data:
              title: UPS
              message: Main UPS is at 10%
              data:
                notification_icon: mdi:battery-10
                color: red
          - device_id: NAS power button
            domain: button
            entity_id: 
            type: press
          - device_id: main pc hass.agent mqtt press
            domain: button
            entity_id: 
            type: press
          - type: turn_off
            device_id: main pc monitors smart plug
            entity_id: 
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - UPS Charging
        sequence:
          - service: notify.mobile_app
            metadata: {}
            data:
              title: UPS
              message: Main UPS is Charging
              data:
                notification_icon: mdi:battery-charging
                color: green
mode: single

1 Like