Trigger automation on sensor unavailable

Wondering if anyone can shed some insight into this.

I have written an automation to turn on and turn off a switch when ever the temperature reading becomes “unavailable” as a way of resetting the sensor. I want it to trigger if the sensor is unavailable for five minutes. The automation does what is intended when triggered manually, but it won’t trigger otherwise.

The script:

- id: '1587721504100'
  alias: Spare room sensor reboot
  description: Reboot when temperature is unavailable
  - entity_id: sensor.spare_room_temperature
    for: 00:05:00
    platform: state
    to: unavailable
  - condition: device
    device_id: 11e0ee306d1d48db9dc073f174ddf583
    domain: switch
    entity_id: switch.powerboard_1_usb
      hours: 0
      minutes: 10
      seconds: 0
    type: is_on
  - device_id: 11e0ee306d1d48db9dc073f174ddf583
    domain: switch
    entity_id: switch.powerboard_1_usb
    type: turn_off
  - delay: 00:00:10
  - device_id: 11e0ee306d1d48db9dc073f174ddf583
    domain: switch
    entity_id: switch.powerboard_1_usb
    type: turn_on

Can anyone see why it won’t trigger?

Why does the switch.powerboard_1_usb need to have been on for 10 minutes?

Have you tried removing that condition and seeing if it works?

I set that to ensure it wouldn’t cycle on/off continuously. I’m pretty sure it wasn’t working before I put that in. I’ll remove it and see how it goes. I’ll have to wait till it becomes unavailable again though.

It will only trigger when the sensor goes to ‘unavailable’, so unless the sensor keeps going connecting and disconnecting then it shouldn’t cycle continuously.

It would be good if you could do a screenshot of the unavailable device on the states page (Developer Tools > States) so we can help you further.

1 Like

Thanks for the response Andy. Now you mention it, I should have checked the states page first. Thanks for the reminder and for taking the time to respond.

Did you ever get this working? I’m also having problems trying to get an automation to trigger on an “unavailable” state. Thanks.

Yes, as I remember it I used the wrong ‘state name’. It displayed “unavailable” in the front end (lovelace), but the state (from developer tools) was actually “unknown”. I changed it in the automation and its been working since.


In my case the word unavailable had to be quoted in the automation YAML, and the UI editor for automations wouldn’t do that. More detail here: How to use "unavailable" as a trigger/status