How to trigger notification using NUT-connected UPS when power out?

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.

I would appreciate any insights or help.

Thank you.

When you monitor the state of this entity when you unplug the UPS so it is on battery power does the state of this entity change to anything useful?

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.

1 Like

You’ll need to enter the state manual.

On my APC UPS I use ‘OB DISCHRG’ and ‘OL CHRG’ because I use the status data sensor.

1 Like

@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.

That is correct.

1 Like

Here’s what I use:

alias: UPS - Notification
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.network_rack_ups_status
    to: On Battery
    id: battery
  - platform: state
    entity_id:
      - sensor.network_rack_ups_status
    to: Online
    id: online
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: battery
        sequence:
          - service: notify.mobile_app_ryan_s_phone
            data:
              message: The UPS is on battery.
      - conditions:
          - condition: trigger
            id: online
        sequence:
          - service: notify.mobile_app_ryan_s_phone
            data:
              message: The UPS is back on mains power.
mode: single

3 Likes

This looks correct to me, does it work?

Sure does.

2 Likes

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.

1 Like

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.

1 Like

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.

3 Likes