Variables in Script

alias: KG_Hobbyraum_SzeneWerte
sequence:
  - variables:
      transition: 1
  - service: scene.turn_on
    target:
      entity_id: scene.kg_hobbyraum_standard
    data:
      transition: {{ transition | float }}
mode: parallel

Not working… → error:

… ans ideas why?

Everything works when i Write:
„Transition: 1“ directly
But it has to be dynamically set… that is the sense. Different transition times per situation (not mentioned in the script)

Thank you very much already - I ran out of ideas…

I think you need to wrap the template in double quotes:

transition: "{{ transition | float }}"
1 Like

Thank you very much. That works. (I though I already tried… but …)

So now next level putting the variable in “ifs” - how can I pass it to “the higher level”?

  - if:
      - condition: template
        value_template: "{{ ( states('input_select.kg_szene') == 'Standard' ) }}"
    then:
      - variables:
          transition: 5
  - service: scene.turn_on
    target:
      entity_id: scene.kg_hobbyraum_standard
    data:
      transition: "{{transition|float}}"

it says “undefined”…

I’m not very experienced with variables, but I’m pretty sure the variable now only exists in the then block, not outside it. Variables need to be defined at the top level to be able to use then troughout the script.

See this for more detail, especially the bit about scope: