Light flash triggered by weather forecast help request

I’m trying to get my lights to flash when I turn them on in the morning if the forecast is rainy. I’ve figured out how to force my lights to flash, but I’m having a hard time using the forecast as a condition for the automation. Any advice would be greatly appreciated.
I tried adapting: Rain forecast automation with no success. I can get the template editor to show true with

{{ 'rainy' in state_attr('weather.home', 'forecast')[0].condition }}

but get “template value should be a string for dictionary value @ data[‘value_template’]. Got None” when I test it as a condition. I’ve included the condition as written now:

condition: template
value_template: {{ 'rainy' in state_attr('weather.home','forecast')[0].condition }}

What am I doing wrong? Any help would be greatly appreciated!

Try this

{{ 'rainy' in state_attr('weather.home', 'forecast')[:0].condition }}

I got the same error, thanks for the response!!

It might be working and it’s just the GUI test function that is broken. I will try physical testing and repost. Reference: UI Testing of Automation Conditions Does Not Work with Template Conditions · Issue #12282 · home-assistant/frontend · GitHub

1 Like

It was working! The issue was in the interface, not the automation. If anyone wants to do something similar, here’s my automation! If anyone has any clue to clean up and consolidate the value templates, I’d appreciate it!

alias: Rain alarm
description: ''
trigger:
  - platform: state
    entity_id:
      - light.all_lights
    to: 'on'
condition:
  - condition: time
    before: '09:00:00'
    after: '05:00:00'
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
  - condition: or
    conditions:
      - condition: state
        entity_id:
          - weather.home
          - weather.home_hourly
          - weather.thermostat
        match: any
        state:
          - rainy
          - pouring
          - lightning
          - hail
          - lightning-rainy
      - condition: template
        value_template: >-
          {{ 'rainy' in state_attr('weather.home_hourly', 'forecast')[:12] |
          map(attribute='condition') }}
      - condition: template
        value_template: >-
          {{ 'pouring' in state_attr('weather.home_hourly', 'forecast')[:12] |
          map(attribute='condition') }}
      - condition: template
        value_template: >-
          {{ 'lightning' in state_attr('weather.home_hourly', 'forecast')[:12] |
          map(attribute='condition') }}
      - condition: template
        value_template: >-
          {{ 'lightning-rainy' in state_attr('weather.home_hourly',
          'forecast')[:12] | map(attribute='condition') }}
      - condition: template
        value_template: >-
          {{ 'hail' in state_attr('weather.home_hourly', 'forecast')[:12] |
          map(attribute='condition') }}
      - condition: template
        value_template: >-
          {{ 'rainy' in state_attr('weather.thermostat',
          'forecast')[0].condition }}
      - condition: template
        value_template: >-
          {{ 'pouring' in state_attr('weather.thermostat',
          'forecast')[0].condition }}
      - condition: template
        value_template: >-
          {{ 'lightning-rainy' in state_attr('weather.thermostat',
          'forecast')[0].condition }}
      - condition: template
        value_template: >-
          {{ 'lightning' in state_attr('weather.thermostat',
          'forecast')[0].condition }}
      - condition: template
        value_template: >-
          {{ 'hail' in state_attr('weather.thermostat', 'forecast')[0].condition
          }}
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: scene.create
    data:
      snapshot_entities:
        - light.group_1
        - light.group_2
        - light.group_3
      scene_id: baseline
  - repeat:
      count: '5'
      sequence:
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 50
        - service: light.turn_on
          data:
            rgb_color:
              - 0
              - 0
              - 255
          target:
            entity_id: light.all_lights
        - delay:
            hours: 0
            minutes: 0
            seconds: 5
            milliseconds: 0
        - service: scene.turn_on
          target:
            entity_id: scene.baseline
          data: {}
        - delay:
            hours: 0
            minutes: 0
            seconds: 5
            milliseconds: 0
mode: restart