Help needed with an automation that doesn't trigger

I’m trying to set up an automation which will trigger when a device is detected as being offline. I’m using ping for the detection and that functions ok, for that I’m using this code:

binary_sensor:
  - platform: ping
    name: "UPS Supply"
    host: 192.168.1.155

The status goes from ‘on’ when it is online to ‘off’ when it is not (unplugged)

I want to use this in an automation and in the example below I’m trying to get it to turn on a light if the binary sensor above has gone to ‘off’ for more than 30 seconds but cancel the automation if the binary sensor comes back on. For this I have tis automation, but it doesn’t trigger. Any ideas why?


- id: '1578149229611'
  alias: UPS
  description: ''
  trigger:
  - entity_id: binary_sensor.ups_supply
    for: 00:00:30
    platform: state
    to: 'off'
  condition:
  - condition: state
    entity_id: binary_sensor.ups_supply
    state: 'on'
  action:
  - alias: ''
    data: {}
    entity_id: switch.living_room_main_light
    service: switch.turn_on

The condition says the sensor has to be on, but it only triggers when it has been off. How do you expect it to be on when it has been off?

1 Like

Just remove your condition. Your automation will only trigger when the binary sensor has been off for 30 seconds, if it turns back to on during the 30 seconds it will not trigger.

1 Like

Doh… of course. What I meant to do is use the condition to cancel the automation if the sensor comes back on but as Burningstone has stated, this is not necessary. Thanks all.

Just noted an unneded “alias” in your action, and you can also remove the data part as it is empty anyway:

- id: '1578149229611'
  alias: UPS
  description: ''
  trigger:
  - entity_id: binary_sensor.ups_supply
    for: "00:00:30"
    platform: state
    to: 'off'
  action:
  - entity_id: switch.living_room_main_light
    service: switch.turn_on

I used the Automations tool in configuration to create it and that automatically added those. You are correct though in that they are superfluous, so I will remove them.