UPS automations not working

I am using the Network UPS Tools integration on my RPi running the latest version of Home assistant. I am monitoring the state of the ups and I am getting valid state changes on the cards as the unit goes on battery, off battery and fully recharged. The state changes come through as text, OL, OB CHRG and others as well. For some reason my automations do not trigger during state changes.

I have tried ‘OB CHRG’ and ‘OB_CHRG’ and have tried the “_” in place of the space in all of the various states.

Here are the automations that are not triggering, they are in my automations/ups.yaml file:

# UPS Automation
- id: UPS_01
  alias: 'Notify when UPS goes on battery'
  trigger:
    - platform: state
      entity_id: sensor.dr_ups_status_data
      from: 'OL'
      to: 'OB_DISCHRG'
  action:
    - service: notify.sms_matt
      data:
        title: "Alert from HomeAssistant"
        message: "Home UPS on battery"

- id: UPS_03
  alias: 'Notify when UPS goes on battery while charging'
  trigger:
    - platform: state
      entity_id: sensor.dr_ups_status_data
      from: 'OL_CHRG'
      to: 'OB_DISCHRG'
  action:
    - service: notify.sms_matt
      data:
        title: "Alert from HomeAssistant"
        message: "Home UPS on battery"

- id: UPS_02
  alias: 'Notify when UPS goes off battery'
  trigger:
    - platform: state
      entity_id: sensor.dr_ups_status_data
      from: 'OB_DISCHRG'
      to: 'OL_CHRG'
  action:
    - service: notify.sms_matt
      data:
        title: "Alert from HomeAssistant"
        message: "Home UPS oFF battery"
        
- id: UPS_04
  alias: 'Notify when UPS is full'
  trigger:
    - platform: state
      entity_id: sensor.dr_ups_status_data
      from: 'OL_CHRG'
      to: 'OL'
  action:
    - service: notify.sms_matt
      data:
        title: "Alert from HomeAssistant"
        message: "Home UPS fully charged"

- id: "Desktop off on UPS"
  alias: 'Desktop off on UPS'
  trigger:
    - platform: time_pattern
      minutes: '/5'
  condition:
    - condition: numeric_state
      entity_id: sensor.dr_ups_status_data
      below: 70
  action:
    - service: switch.turn_off
      data:
        entity_id: switch.desktop

- id: 'UPS shutdown hassio'
  alias: UPS shutdown hassio
  initial_state: 'on'
  trigger:
  - platform: time_pattern
    minutes: '/3'
  condition:
  - condition: numeric_state
    below: '5'
    entity_id: sensor.dr_ups_battery_charge
  action:
  - service: notify.sms_matt
    data:
      title: "Alert from HomeAssistant"
      message: "UPS low HomeAssistant shutdown"
  - service: hassio.host_shutdown

I know it is something simple that I have missed, but I just can’t see it!

Thanks Matt

What is displayed on the frontend (in the card) isn’t the actual state you need to use in the automation.

you need to look at the entity in the states page to see what the actual states are and use those.

So, I have tried that… I have used “OL” and “Online” as well as the verbiage for the other states. It seems to just be ignored.

I assume that I should be using the state listed as state: Online?

Since you are using the platform: state in the trigger of your automations then you should not be using the “state: Online” but instead you should be using “OL” (or whatever is says in the entry under the “state” column).

There are a couple of things to check…

make sure that the automations are shown as ‘on’ in the states listings for those automations. If not, then turn them on.

If they are on then you can make sure that the action is working by clicking on the little box with the arrow on the left of the automation and then click “trigger” to see if the action actually occurs.

So, the automations are on, they also trigger fine when clicking trigger. The to: and from: above are the values that show in the state column during various cases. The description in the third column is where the full text descriptions came from during state changes, so I figured I may as well test them. But neither is working and the automations never show triggered.

It appears to me that I am not looking for state properly.

That a lot of automations, I’d condense it down something like this:

  alias: 'Notify when UPS state changes'
  trigger:
     platform: state
     entity_id: sensor.dr_ups_status_data

  action:
     service: notify.sms_matt
     data_template:
       title: "Alert from HomeAssistant"
       message: "Home UPS: {{ trigger.to_state }}"
2 Likes

Am I reading this correctly that if the state changes this automation would tell me that the state changed and to what state it changed to?

That would be correct.

Thanks, I will test it this evening and see if changes in state are detected by it.

This looks like just what I need as well, but when I try to test-run it I get “Error rendering data template: UndefinedError: ‘trigger’ is undefined” in the logs…do I need to set something else up as well?

post your code

1 Like

That’s likely because when you test run it you are bypassing the trigger so there is no trigger.to_state defined.

1 Like

That was exactly the case, thanks! As soon as I unplugged the UPS cable, I got the notification :slight_smile: