How do I get this to work: If-condition in script > sequence

Hello all…

Actually I just need a very simple if syntax in a script (as seen here in documentation), but somehow it doesn’t work in general (not only because of a wrong condition). And somehow my impression is that an if-else is declared differently everywhere in YAML. Anyway, I’ve lost track and would be very happy if someone could take a look at it:

script_sequence_on:
  sequence:
    # =============== RELAY 1
    - if
        condition: state
        entity_id: zone.home
        state: states('input_number.input_for_relay_1 > 0 
    - then 
      - type: turn_on
        entity_id: switch.relay_1
        domain: switch
      - delay:
          minutes: "{{ states('input_number.input_for_relay_1') | int }}"
      - type: turn_off
        entity_id: switch.relay_1
        domain: switch
      - delay: '00:00:03' 
    # =============== RELAY 2
    # same if-condition her for relay 2
    - type: turn_on
      entity_id: switch.relay_2
      domain: switch
    - delay:
        minutes: "{{ states('input_number.input_for_relay_2') | int }}"
    - type: turn_off
      entity_id: switch.relay_2
      domain: switch
    - delay: '00:00:03'
  mode: single

Thank you

Hannah

    - if:
        condition: numeric_state
        entity_id: input_number.input_for_relay_1
        above: 0
    - then:
      ...etc
1 Like

ok… condition was wrong (I thought so), but the if-syntax was right?

Then I think I’ll switch back from the add-on “Studio Code Server” to the simple “File Editor”. For me, with the same syntax (and a correct condition) simply EVERYTHING was displayed in red as an error.

Many, many thanks!

No you missed the colons after the if and then.

That’s why it was highlighted as an error. VSCode was right.

1 Like