Automation not triggering on "unavailable"

I have some emporia vue sensors that periodically become unavailable, and calling the reload_config_entry service wakes them back up. At the moment, their state is “unavailable”, including a_c_compressor_16_1min mentioned in my automation below. But despite this fact, the following automation did not fire:

- id: '1653436082560'
  alias: Refresh Vue Services
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.a_c_compressor_16_1min
    to: unavailable
  condition: []
  action:
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id:
      - sensor.basement_14_1min
      - sensor.bedrooms_1_11_1min
     # and a bunch of others......
  mode: single

If I run the automation manually (by clicking “Run Actions”), the sensors all wake up as expected.

Can anyone spot what I am doing wrong? Thank you!

-Eric

Shouldn’t that first part be a condition instead of a trigger?

Try quoting the state:

to: 'unavailable'

When you created the automation, was the sensor’s state already unavailable or was it some other value?

The State Trigger you created will trigger when the sensor’s state changes from some value to unavailable. It’s the change from something to unavailable that initiates the trigger.

That confirms the action works but manual execution skips the trigger so it can’t be used as a test to confirm if the trigger works.

@123 The state has flipped between returning numeric values to “unavailable” over the past day without triggering.

@tom_l I will try quoting it and see what happens

@Nick4 I want it to trigger when the state becomes “unavailable”. I suppose an alternative would be to trigger on time (every 15 minutes or such) and then run the action using the condition of state = unavailable. Of course it is totally possible I am confused.

Thanks all!

Hmm, in that case it sounds like it should have triggered the State Trigger.

As an experiment, try this version:

- id: '1653436082560'
  alias: Refresh Vue Services
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.a_c_compressor_16_1min
  condition: "{{ trigger.to_state.state == 'unavailable' }}"
  action:
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id:
      - sensor.basement_14_1min
      - sensor.bedrooms_1_11_1min
     # and a bunch of others......
  mode: single
1 Like

Putting “unavailable” did not fix the problem it seems. Giving the version above a try and will report back next time the sensors go off line.

Thanks!

So the version provided by @123 DID trigger, but my sensors remain unavailable. I suspect what happened is after the refresh, the sensors were still unavailable for one reason or another, and then since the state remained ‘unavailable’ but did not change TO unavailable it did not trigger a second time. So now I am trying a timed trigger like this:

- id: '1653436082560'
  alias: Refresh Vue Services
  description: ''
  trigger:
  - platform: time_pattern
    minutes: /15
  condition: "{{ states('sensor.a_c_compressor_16_1min') == 'unavailable' }}"
  action:
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id:
      - sensor.basement_14_1min
      - sensor.bedrooms_1_11_1min
     # and a bunch of others......
  mode: single

I imagine you realize that it’s highly problematic that these Emporia sensors become unavailable so frequently that you need an automation to refesh them and that even after refreshing they may still remain unavailable. Wouldn’t whatever energy monitoring data contain gaps that would render any totals less than accurate?

Agreed.

Interestingly, it’s only the 1 minute sensor within HA that becomes unavailable. The 1 day sensor remains available, and updates frequently. The drawback is that this is an integrating sensor–so it is easy to see what circuits have used the most power “so far today”, but not so easy to see what is using the most power “at this particular moment”. But, by using a utility meter helper that resets every, say, 10 minutes I can see my current usage for all my circuits. So that is another solution.

(I have opened an issue related to this on the integration’s github repo and the developer is looking into it as well.)

Im having this problem now, did it ever get resolved?

I just encountered the problem, and found a workaround.
Edit the YAML and set the capitalization of ‘unavailable’ to match what HA shows the entity to be when it is unavailable.
Apparently, the trigger is case-sensitive.