Passign variables to script

Hello, I want to create this script:

light_dim:
  sequence:
    - service: light.turn_on
      data_template:
        entity_id: '{{entity_id}}'
        brightness: >-
          {% set current = states['{{entity_id}}'].attributes.brightness|default(0)|int %}
          {% if '{{direction}}' == '-1' %}
            {% set next = current - 50 %}
          {% else %}
            {% set next = current + 50 %}
          {% endif %}
          {% if next < 0 %}
            {% set next = 0 %}
          {% endif %}
          {% if next > 255 %}
            {% set next = 255 %}
          {% endif %}
          {{ next }}

But the problem is that I don’t know how to access to variables I pass to this script inside of the % blocks. For example, this is not working: {% if '{{direction}}' == '-1' %}

How can I achieve that?

I would try

{% if direction == -1 %}
1 Like

Yes, it’s working. Thanks :slight_smile:

1 Like