If - then in script

Dear Forum,

I am struggeling with the next step of my blinds script.

testscript:
  alias: testscript
  variables:
    entity_id_var: "{{ cover_entity_input }}"
    window_switch_var: "{{ window_switch_input }}"
    force_position_var: "{{ force_position_input }}"
    position_var: "{{ position_input }}"   
  sequence:  
  - service: cover.set_cover_position
    data:
      position: >
        {% if states('window_switch_var') == 'on' %}
          "{{ force_position_var }}"
        {%-elif states('window_switch_var') == 'off' %}
          "{{ position_var }}"
        {% endif %}      
      entity_id: "{{ entity_id_var }}"
  - service: input_number.set_value
    data: 
      entity_id: input_number.helfer_testnummer         
      value: "{{ position_var }}"
  mode: single     

I must have something wrong, getting the error:

Fehler beim Aufrufen des Diensts cover/close_cover. expected int for dictionary value @ data[‘position’]

when triggering the script. What’s wrong?

these are strings. For an int you’ll need to change the string to an int (ie {{ var | int }} or remove the quotes

1 Like