Automation: Turn Light On or Off depending on input boolean?

I’m trying to trim down my automations as I currently have one for on and one for off on each of my input booleans that are linked to a light. I appreciate the below is completely wrong but I hope you can see what I’m trying to achieve:

- alias: 'On or Off Switch'
  condition: []
  id: '6518643521321'
  trigger:
    platform: state
    entity_id: input_boolean.testlight
  action:
    service: input_boolean.toggle
    data_template:
      entity_id: switch.bedroom_light
      value:>
        {% if is_state('input_boolean.testlight', 'on') %}
           switch.turn_off
        {% else %}
           switch.turn_on
        {% endif %}

Use a service_template:

action:
    service_template: >
        {% if is_state('input_boolean.testlight', 'on') %}
           switch.turn_off
        {% else %}
           switch.turn_on
        {% endif %}
      entity_id: switch.bedroom_light

But if you only want the light to toggle it’s much easier to just use this:

  action:
    service: homeassistant.toggle
      entity_id: switch.bedroom_light
2 Likes

Bedankt / Thanks.

I’ll implement the toggle on my lights (ie xiaomi bulbs I have), I can’t use it on my switches (RF codes) as I have to double press the “on” sometimes as it doesn’t always register. Thank you for the help.