Help with Home Assistant Automation for UPS Shutdown Sequence

Hello everyone,

I’m trying to set up an automation in Home Assistant that triggers a shutdown sequence for my devices when my UPS goes into battery mode (ONBATT). I want to ensure that the automation only executes if the power outage lasts for 10 seconds. I prefer to use the nut.ups_event because it’s faster to update and provides real-time notifications about the UPS status.

However, it’s not working. Even if the UPS goes back ONLINE within 10 seconds, the automation continues to execute the rest of the actions after the 10-second wait is over. If I change continue_on_timeout to false, it will not continue even if the UPS is still on battery after 10 seconds.

What should I do?
Thank you!

Here’s the current configuration I have:

alias: UPS shutdown sequence
description: ""
trigger:
  - platform: event
    event_type: nut.ups_event
    event_data:
      notify_type: ONBATT
condition: []
action:
  - wait_for_trigger:
      - platform: event
        event_type: nut.ups_event
        event_data:
          notify_type: ONLINE
    timeout: "00:00:10"
    continue_on_timeout: true

  - action: automation.trigger
    metadata: {}
    data:
      skip_condition: true
    target:
      entity_id:
        - automation.switch_input_to_hdmi_1_if_different
        - automation.change_sound_output_if_external_arc
  
  - data:
      message: >-
        שים לב: בשל הפסקת חשמל, מקור הקלט הוחלף ל-HDMI 1 ומקור השמע הוחלף לרמקול
        הטלוויזיה.
      title: שינוי מקור ושמע לברירת מחדל
    action: notify.lg_webos_smart_tv

  - delay: "00:00:05"
  
  - data:
      message: "שים לב: בשל הפסקת חשמל, הטלוויזיה תכבה בעוד כ-5 שניות על מנת למנוע נזק."
      title: כיבוי טלוויזיה בשל הפסקת חשמל
    action: notify.lg_webos_smart_tv

  - delay: "00:00:05"

  - data:
      entity_id: media_player.lg_webos_smart_tv
      command: system/turnOff
    action: webostv.command

  - delay: "00:00:05"
  
  - condition: and
    conditions:
      - condition: state
        entity_id: media_player.lg_webos_smart_tv
        state: "off"
      - condition: state
        entity_id: media_player.denon_avr_x2200w
        state: "off"

  - action: remote.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: remote.shield

  - type: shutdown_return
    device_id: 570b9d86c07043bc4824381fc0d4f41d
    domain: nut
    enabled: false

  - data:
      message: הפסקת חשמל, הכל כובה
    action: notify.mobile_app_sm_s918b

  - action: hassio.host_shutdown
    data: {}
    enabled: false

mode: single

Make a template binary_sensor that shows the last event

template:
- trigger:
  - id: "on"
    platform: event
    event_type: nut.ups_event
    event_data:
      notify_type: ONBATT
  - id: "off"
    platform: event
    event_type: nut.ups_event
    event_data:
      notify_type: ONLINE
  binary_sensor:
  - name: UPS on Batt
    unique_id: ups_on_batt
    state: "{{ trigger.id }}"

Then make an automation that shuts down on 10 seconds.

alias: UPS shutdown sequence
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.ups_on_batt
    to: "on"
    for: "00:00:10"
action:
...

the automation should only fire when it’s on battery for 10 seconds or more

5 Likes

thank you very much! ill try that

I’m learning a little here, so have a question … If I have this correct, you are using the NUT Server AddON which sends the nut.ups_event and you also have the NUT Integration which has a sensor showing the UPS’s state. Are you saying that the AddOn sends this event quicker than the NUT integration sensor’s state gets updated?

yes that correct