Using Variables in Scripts passed from automation

I get the error below when trying to save my script. Any ideas what I am doing wrong?

Message malformed: Entity {{ room_schedule_selection }} is neither a valid entity ID nor a valid UUID for dictionary value @ data['sequence'][0]['if'][0]['entity_id']

Start of script, it carries on, but the error is the "{{ room_schedule_selection }}"shown here:

sequence:
  - alias: "Turn Off - Else:  Set the thermostat"
    if:
      - condition: state
        entity_id: "{{ room_schedule_selection }}"
        state: "Off"
    then:

Many Thanks

You cannot use templates in a State condition, use a Template condition instead.

sequence:
  - alias: "Turn Off - Else:  Set the thermostat"
    if:
      - condition: template
        value_template: "{{ is_state(room_schedule_selection, 'off') }}"
    then:
1 Like

Thank you @Didgeridrew. This now saves and runs as I expected.

1 Like