Automation for when device becomes available

What is the latest and cleanest way to trigger an automation for when a certain device becomes available?

Context, I live in a sh!thole 3rd world country where power outages are normal, and mosquitos are a thing so I have electrical mosquito repellents that are on smart switches.

If the power happens to be out when the normal automation runs (and they’re unavailable), I want to be sure that they turn on if they go from unavailable between hours of x and y.

You could use

trigger:
  - platform: state
    entity_id:
      - switch.plug.yourplug
    from: unavailable

Some plugs also support resuming last state after an outage.

2 Likes

Something like

trigger:
  - platform: state
    entity_id:
      - switch.mosquito_1
    from: unavailable
condition:
  - condition: time
    before: "06:00:00"
1 Like

If the device state can also be unknown after an outage, I would use

trigger:
  - platform: state
    entity_id:
      - switch.plug.yourplug
    from: 
      - unavailable
      - unknown
    not_to:
      - unavailable
      - unknown

This will probably also trigger after a restart, that may or may not be what you want. You might want to add a test using the uptime sensor if you dont.

2 Likes

Overachiever!!!

2 Likes