Get entity_id of the template switch that I am programming

I have this setup for template switch:

      template_light:
        friendly_name: Template switch
        value_template: "{{ is_state('binary_sensor.template_light_sensor', 'on') }}"
        turn_on:
          - service_template: >
              {% if is_state('switch.template_light', 'off') %} 
                switch.toggle
              {% endif %}
            data:
              entity_id:
                switch.light_switch
        turn_off:
          - service_template: >
              {% if is_state('switch.template_light', 'on') %} 
                switch.toggle
              {% endif %}
            data:
              entity_id:
                switch.light_switch

I have 25 this template switches and it is a pain to change - {% if is_state(‘switch.template_light’, ‘on’) %} for every template switch I have. Is there a way to call the entity_id of this switch like this:

{% if is_state({this.entity_id}, 'on') %} 

so I want the {this.entity_id} to return the string - ‘template_light’

Thank you!

The closest thing to what you’ve described is the Trigger State Object but it only exists in automations (because they contain triggers).

1 Like