Notify when entity becomes available

I’m looking for an automation that is basically the opposite of this one so that it notifies when an entity comes online? Can anyone help? So I’d get a notification on the below when something goes offline then another one when it comes back online?


- id: 'eb88ef61-f976-4600-a20f-13d569aacba1'  
  alias: Sensor Offline
  trigger:
  - platform: event
    event_type: state_changed
  condition:
  - condition: template
    value_template: >
      {{
        trigger.event.data.entity_id.startswith('sensor.') and
        trigger.event.data.new_state is not none and
        trigger.event.data.new_state.state == 'unavailable' and
        (
          trigger.event.data.old_state is none or
          trigger.event.data.old_state.state != 'unavailable'
        )
      }}
  mode: parallel
  action:
  - wait_template: "{{ not is_state(trigger.event.data.entity_id, 'unavailable') }}"
    timeout: "00:10"
    continue_on_timeout: true
  - condition: template
    value_template: "{{ is_state(trigger.event.data.entity_id, 'unavailable') }}"
  - data_template:
      message: '{{ trigger.event.data.new_state.name }} is offline, please investigate'
      title: Sensor Offline
    service: notify.mobile_app_matts_iphone

Swap around the words old_state and new_state.

Thanks for the reply, so would it look like this? I tried but it didnt seem to work?

- id: 'eb88ef61-f976-4600-a20f-13d569aacba1'  
  alias: Sensor Offline
  trigger:
  - platform: event
    event_type: state_changed
  condition:
  - condition: template
    value_template: >
      {{
        trigger.event.data.entity_id.startswith('sensor.') and
        trigger.event.data.new_state is not none and
        trigger.event.data.new_state.state == 'unavailable' and
        (
          trigger.event.data.old_state is none or
          trigger.event.data.old_state.state != 'unavailable'
        )
      }}
  mode: parallel
  action:
  - condition: template
    value_template: "{{ is_state(trigger.event.data.entity_id, 'unavailable') }}"
  - data_template:
      message: '{{ trigger.event.data.new_state.name }} is offline, please investigate'
      title: Sensor Offline
    service: notify.mobile_app_matts_iphone

I suspect it did work, but you haven’t changed your action so the message is saying that it’s found an unavailable item even though the trigger is that an item has come back from the dead, and the condition that precedes it is only allowing the unavailable entities through.

1 Like

Got it sorted, thanks for the help.

1 Like