Learning scripts, parameter passing

Dear HomeAssistant specialists,

I’m “playing” with scripts and simple parameter passing, below the “problem” code

script (in scripts.yaml)
  lamp_turn_color:
    alias: turn the HueLamp2 into selected color
    sequence:
      - service : homeassistant.turn_on
        data_template:
          brightness: '{{ grn }}'
          entity_id: light.hue_color_lamp_2 


automation (in automations.yaml)
     ...
      action:
        service: script.lamp_turn_color
        data_template:
          variables:
            grn: '{{ 35 }}'

I’ll try to pass just an int, 0…255, spent quite some hours to make it work, but without failures reported it’s not working…

If someone can give me a hint, very appreciated…

Peter

      action:
        service: script.lamp_turn_color
        data_template:
          variables:
            grn: 35

Unfortunately it is not working, if I use the below script the lamp turns to the reduced brightness, with the variable as proposed (grn: 35) unfortunately no action.

  lamp_turn_color:
    alias: turn the HueLamp2 into selected color
    sequence:
      - service : homeassistant.turn_on
        data_template:
#          brightness: '{{ grn }}'
          brightness: 125
          entity_id: light.hue_color_lamp_2
lamp_turn_color:
    alias: turn the HueLamp2 into selected color
    sequence:
      - service : homeassistant.turn_on
        data_template:
          brightness: '{{ grn|int }}'
          entity_id: light.hue_color_lamp_2

?

Any errors?

when I do this, I don’t use the variables: key at all. In so in my automation, I have:

     ...
      action:
        service: script.lamp_turn_color
        data:
          grn: 35

Note: No need for data_template unless you’re actually using templates (like if you were reading the state of a slider, for example).

then in the script:

lamp_turn_color:
    alias: turn the HueLamp2 into selected color
    sequence:
      - service : homeassistant.turn_on
        data_template:
          brightness: '{{ grn }}'
          entity_id: light.hue_color_lamp_2
1 Like

2018-12-01 17:23:29 ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘grn’ is undefined

Yeah, I think @ha_steve has it tbh, you don’t need the variables key.

YES !

it’s working without the variables statement…

Many thanks, I’ll try to understand why the variables statement was blocking the parameter passing…