Pass variable from automation to script

Hi everyone,

I try to set-up a script that can be called from multiple automations with changing variable.
In my case I have multiple automations to set my shutters to a specific position an would like to set them with only one script.

So one of my automations looks like this:

alias: "Close at sunset"
description: ""
trigger:
  - platform: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: -7
condition: []
action:
  - service: script.shutters_down
    data:
      position_var: 50
mode: single

And the script has:

alias: "Close Shutters"
sequence:
  - device_id: 3f19442a537d7684d75abfe15a93c437
    domain: cover
    entity_id: 01fb8df83d85318698294eacaed0f8c3
    type: set_position
    position: {{ position_var | float }}

Saving the script fails with:

Message malformed: value must be one of [‘close’, ‘close_tilt’, ‘open’, ‘open_tilt’, ‘stop’] for dictionary value @ data[‘type’]

Running it via an Input Number also did not help:

position: {{states('input_number.shutter_position') | float }}

If I set a number to position, it works fine:

position: 30

But the idea is of course to make the script a generic one so I can use it from multiple automations.

Same error.
What am I not seeing here?
Thanks for any hint or help.

You need quotation marks around your template, and you need to change it to a Call service action… Device actions don’t accept templates.

alias: "Close Shutters"
sequence:
  - service: cover.set_cover_position
    target:
      entity_id: cover.your_cover_entity
    data:
      position: "{{ position_var | float }}"

Thank you so much. Just learned a lot about home assistant.

So my solution now is not even doing a script anymore but triggering the “call service action” directly from automation as there already is such a services for covers available.