Help with data_template using dynamic entity names

Hi Petro,

I finally solved the problem. Thanks to you, I used the following code you provided in the previous post, to query the state of variable ‘light_id’ (instead of entity_id). And it works!

My script now:

  dimmer_swipe_up:
    sequence:
      - service: light.turn_on
        data_template:
          entity_id: '{{ light_id }}'
          brightness: >-
            {% set domain, name = light_id.split('.') %}
            {% set current = states[domain][name].attributes.brightness | int %}
            {% set step = states('input_number.light_step') | int %}
            {% set next = current + step | int %}
            {% if next > states('input_number.light_maximum') | int %}
              {% set next = states('input_number.light_maximum') | int %}
            {% endif %}
            {{ next }}

So the variable got passed alright. The caveat was how I queried the state of the variable. It seems your approach works for me! Thank you so much!

1 Like