Automation online and offline scan depending

I have the automations as in the code below.
I have added

      for:
        minutes: 5

because if the device was offline (read the ip scan lost the wifi-connected device) for just a very short time I get to many false notifications.

The offline notifications has decreased, but the online notifications keep the same and should not be triggered if “the device went up within 5 minutes”.
How can this be done?

automation:
- alias: ip_espble01_on
  initial_state: true
  trigger:
    - platform: state
      entity_id: binary_sensor.ip_espble01
      to: 'on'
  action:
    - service: notify.telegram
      data:
        title: ESPBLE01
        message: 'online'

- alias: ip_espble01_off
  initial_state: true
  trigger:
    - platform: state
      entity_id: binary_sensor.ip_espble01
      to: 'off'
      for:
        minutes: 5
  action:
    - service: notify.telegram
      data:
        title: ESPBLE01
        message: '5 minutes off'

I think the way I would do it is to create an input_boolean and turn it on when the “off” automation runs and then use that input boolean as a condition in the “on” automation.

automation:
- alias: ip_espble01_on
  initial_state: true
  trigger:
    - platform: state
      entity_id: binary_sensor.ip_espble01
      to: 'on'
  condition:
    - condition: state
      entity_id: input_boolean.some_name
      state: 'on'
  action:
    - service: notify.telegram
      data:
        title: ESPBLE01
        message: 'online'
    - service: input_boolean.turn_off
      entity_id: input_boolean.some_name

- alias: ip_espble01_off
  initial_state: true
  trigger:
    - platform: state
      entity_id: binary_sensor.ip_espble01
      to: 'off'
      for:
        minutes: 5
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.some_name
    - service: notify.telegram
      data:
        title: ESPBLE01
        message: '5 minutes off'

Hello finity,

It looks like this is working. Thanks!

1 Like