Toggle button rule

What is the easiest to implement a toggle button for light? When the button changes state - light also does that. So if button changed for 1 to 0 when light was off it will be on e.t.tc.
The trigger part is easy…

    trigger:
      - platform: state
        entity_id: switch.kitchen_hb_light

But than comes the hard part - can i keep it sumple or have to write 2 rules?
One will be with condition if light is on and one is if it is off. I guess it can be done with template but an example would greatly help

I use a script to toggle a switch and put the script on the front end. I don’t think toggle needs to know the state, just puts it in the other state.

script:
  toggle_kitchen_hb_light:
    sequence:
      - service: switch.toggle
        data:
          entity_id: switch.kitchen_hb_light
1 Like

Thanks makes perfect sense. But i understood it differently. Shouldn’t it be a button in the automation receiveing the status (it’s a physical button) and then calling a script to switch on or off the light? or…?
Something like

Automation 
trigger:
  - platform: state
    entity_id: switch.kitchen_hb_light
action:
  service: script.turn_on
  entity_id: script.scr_kitchen_light

Script kitchen light
    sequence:
      - service:light.toggle
        data:
          entity_id: light.kitchen_light

Ok, I think you need to use the toggle service like

Automation 
trigger:
  - platform: state
    entity_id: switch.kitchen_hb_light
action:
  service: switch.toggle
  entity_id: light.kitchen_light

not sure your entity_id: light.kitchen_light is correct as I expected a switch but you can check in the dev page.

1 Like

Thank you! That’s exactly what i was looking for!