Help With Automation YAML Code

I’m trying to update automations due to a breaking change in the NWS Alerts custom integration, however HA won’t save the code if I edit in YAML. It seems to fail some sort of validation.

alias: Household - Climate (Severe Weather Mode) Tornado Warning - Activate
description: ""
trigger:
  - platform: state
    entity_id: sensor.nws_alerts
condition:
  - condition: template
    value_template: >
      {% set ns = namespace(events=[]) %}
      {% for x in range(0,states('sensor.nws_alerts_test')|int ) %}
        {% set event = state_attr('sensor.nws_alerts_test', 'Alerts')[x].Event %}
        {% set ns.events = ns.events + [event] %}
     {% endfor -%}
     {{ 'Tornado Warning' in ns.events  }}
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.severe_weather
    alias: Activate Severe Weather Mode
  - alias: Activate Severe Weather Mode (Tornado Warning)
    service: input_boolean.turn_on
    data: {}
    target:
      entity_id:
        - input_boolean.severe_weather_tornado_warning
  - alias: Notify Living Room (LG WebOS Television)
    service: notify.lg_television_wifi_living_room
    data:
      message: The National Weather Service has issued/updated a Tornado Warning.
mode: single

Any idea what is wrong?

Thanks!

try this

alias: Household - Climate (Severe Weather Mode) Tornado Warning - Activate
description: ""
trigger:
  - platform: state
    entity_id: sensor.nws_alerts
condition:
  - condition: template
    value_template: >
      {% set ns = namespace(events=[]) %}
      {% for x in range(0, states('sensor.nws_alerts_test') | int) %}
        {% set event = state_attr('sensor.nws_alerts_test', 'Alerts')[x].Event %}
        {% set ns.events = ns.events + [event] %}
      {% endfor %}
      {{ 'Tornado Warning' in ns.events }}
action:
  - alias: Activate Severe Weather Mode
    service: input_boolean.turn_on
    target:
      entity_id: input_boolean.severe_weather
  - alias: Activate Severe Weather Mode (Tornado Warning)
    service: input_boolean.turn_on
    target:
      entity_id: input_boolean.severe_weather_tornado_warning
  - alias: Notify Living Room (LG WebOS Television)
    service: notify.lg_television_wifi_living_room
    data:
      message: The National Weather Service has issued/updated a Tornado Warning.
mode: single

1 Like

Thank you! Freaking indentation… LOL