Templating services - how to disable it

        service: >-
          {% if states('binary_sensor.test') == 'on' %}
            switch.toggle
          {% endif %}
        data:
          entity_id: switch.test

I am using this template to decide if the switch is allowed to work or not.

It works, but throws an error in the log, which is not nice. It makes sense though, because if the sensor is off, there is no service provided. Can I use some sort of dummy service or how is this done properly?

I use this script as a “no-operation”

noop:
  sequence:
    delay: 00:00:00

then just use script.noop as the service name.

1 Like

Or use the choose action instead of a service template. It does not require an else case:

- choose:
    - conditions:
        - condition: state
          entity_id: binary_sensor.test
          state: 'on'
      sequence:
        - service: switch.toggle
          target:
            entity_id: switch.test
1 Like