Automation - change toggle state NOT WORKING

hello

im trying to change the state of switch toggle of a sonoff.
ive created binary sensor thats ping every 10 sec the sonoff device and return 0 for offline and 1 for online state.

next step is to set the automation for toggle the HA switch off when binary sensor is not find the sonoff connected to the network.

i use :

automation:

  • alias: “turn off light toggle when sonofflr2 poweroff”
    trigger:
    platform: state
    entity_id: binary_sensor.sonofflr2
    to: ‘0’
    action:
    service: switch.turn_off
    entity_id: switch.living_room_light_2

this is not working :frowning:

any idea???

thanks!!!

Try ‘off’ instead of ‘0’ in the to: ‘0’ trigger also use the code blocks when posting code please otherwise it’s difficult to help when we can’t see the spacing.

You can also use this instead of switch.turn_off

  - service: homeassistant.turn_off
    entity_id: switch.bathroom_light

I’m not sure if either will make a difference, but it’s worth a try.

@keithh666 may be correct here regarding the trigger. The way to confirm is to check your states tab and view the state of binary_sensor.sonofflr2

You should also be able to look at the state for the automation and see it’s last_triggered attribute to tell if it ran. If it is running correctly, the issue is with the action.