Really sorry to keep posting questions here, but I do appreciate the help! I noticed there are 3 weather alerts showing on my dashboard today, however I didn’t get a push notification. Upon checking the logs, I can see 2 errors relating to this automation.
I’m wondering if this is due to having multiple warnings for my region at the same time? The errors are:
Logger: homeassistant.helpers.template
Source: helpers/template.py:2345
First occurred: 21 February 2024 at 12:22:39 (3 occurrences)
Last logged: 09:24:00
Template variable warning: 'str object' has no attribute 'summary' when rendering '{%- for item in state_attr('sensor.weather_alerts','entries') %} {%- for type in [ ('extreme heat'),('fog'),('ice'),('lightning'),('rain'),('rain, wind'),('snow'),('snow, ice'),('thunderstorm'),('thunderstorms'),('wind')] if type == item.summary | regex_findall_index('.*warning of (.*) affecting.*', ignorecase=True) %} {% set summary = warning.summary | regex_findall_index('(.*) affecting South West England: (.*) valid from (.*) to (.*)', ignorecase=True) %} {% set time_from = as_timestamp(strptime(summary[2], "%H%M %a %d %b")) | timestamp_custom("%H:%M") %} {% set time_to = as_timestamp(strptime(summary[3], "%H%M %a %d %b")) | timestamp_custom("%H:%M") %} {% set date_from = summary[2][5:8] +'-'+ summary[2][9:11] +'-'+ summary[2][12:] %} {% set date_to = summary[3][5:8] +'-'+ summary[3][9:11] +'-'+ summary[3][12:] %} {% set link = warning.link %} <b>⚠️ {{ summary[0] }}</b> {{ warning.summary.split(':')[0] | title }} {%- if date_from == date_to %} {{ date_from }} {%- else %} {{ date_from }} ➜ {{ date_to }} {%- endif %} {{ time_from }} ➜ {{ time_to }} {%- endfor %} {%- endfor %}'
and
Logger: homeassistant.components.automation.weather_alerts
Source: components/automation/__init__.py:615
Integration: Automation (documentation, issues)
First occurred: 21 February 2024 at 12:22:39 (3 occurrences)
Last logged: 09:24:00
Error rendering variables: IndexError: list index out of range
The first error is the similar to the error I was getting, before moving the variables section up underneath the trigger section in the automation order as suggested, but now it’s saying that the warning variable has no attribute ‘summary’, whereas before it was saying there was no attribute ‘link’, so there is something not quite right with the ‘warning’ variable still. My current automation:
alias: Weather Alerts
description: ""
trigger:
- platform: state
entity_id: sensor.weather_alerts_devon
variables:
warning: |
{%- for item in state_attr('sensor.weather_alerts','entries') %}
{%- for type in [
('extreme heat'),('fog'),('ice'),('lightning'),('rain'),('rain, wind'),('snow'),('snow, ice'),('thunderstorm'),('thunderstorms'),('wind')]
if type == item.summary | regex_findall_index('.*warning of (.*) affecting.*', ignorecase=True) %}
{% set w = item %}
{{ w }}
{%- endfor %}
{%- endfor %}
message: |
{%- for item in state_attr('sensor.weather_alerts','entries') %}
{%- for type in [
('extreme heat'),('fog'),('ice'),('lightning'),('rain'),('rain, wind'),('snow'),('snow, ice'),('thunderstorm'),('thunderstorms'),('wind')]
if type == item.summary | regex_findall_index('.*warning of (.*) affecting.*', ignorecase=True) %}
{% set summary = warning.summary | regex_findall_index('(.*) affecting South West England: (.*) valid from (.*) to (.*)', ignorecase=True) %}
{% set time_from = as_timestamp(strptime(summary[2], "%H%M %a %d %b")) | timestamp_custom("%H:%M") %}
{% set time_to = as_timestamp(strptime(summary[3], "%H%M %a %d %b")) | timestamp_custom("%H:%M") %}
{% set date_from = summary[2][5:8] +'-'+ summary[2][9:11] +'-'+ summary[2][12:] %}
{% set date_to = summary[3][5:8] +'-'+ summary[3][9:11] +'-'+ summary[3][12:] %}
{% set link = warning.link %}
<b>⚠️ {{ summary[0] }}</b>
{{ warning.summary.split(':')[0] | title }}
{%- if date_from == date_to %}
{{ date_from }}
{%- else %}
{{ date_from }} ➜ {{ date_to }}
{%- endif %}
{{ time_from }} ➜ {{ time_to }}
{%- endfor %}
{%- endfor %}
condition:
- condition: template
value_template: "{{ trigger.to_state.state not in ['', 'unknown', 'unavailable','0'] }}"
action:
- service: notify.notify
data:
title: ⛅ Met Office
message: "{{ message }}"
data:
actions:
- action: URI
title: View Warning
uri: "{{ warning.link }}"
These same two errors generate when I run the automation manually now, and no push notification is generated. For reference, the current ‘state’ of my sensor.weather_alerts is ‘3’ and it has the following attributes:
entries:
- title: Yellow warning of rain affecting South West England
title_detail:
type: text/plain
language: null
base: https://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/sw
value: Yellow warning of rain affecting South West England
links:
- rel: alternate
type: text/html
href: >-
https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2024-02-22&id=166e6f71-9368-488f-9a12-888d240b9674&referrer=rss
- length: '15285'
type: image/png
href: >-
https://data.consumer-digital.api.metoffice.gov.uk/v1/warnings/rss/image/yellow-rain.png
rel: enclosure
link: >-
https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2024-02-22&id=166e6f71-9368-488f-9a12-888d240b9674&referrer=rss
summary: >-
Yellow warning of rain affecting South West England: Bath and North East
Somerset, Bournemouth Christchurch and Poole, Bristol, Dorset,
Gloucestershire, North Somerset, Somerset, South Gloucestershire, Swindon,
Wiltshire valid from 0500 Thu 22 Feb to 1800 Thu 22 Feb
summary_detail:
type: text/html
language: null
base: https://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/sw
value: >-
Yellow warning of rain affecting South West England: Bath and North East
Somerset, Bournemouth Christchurch and Poole, Bristol, Dorset,
Gloucestershire, North Somerset, Somerset, South Gloucestershire, Swindon,
Wiltshire valid from 0500 Thu 22 Feb to 1800 Thu 22 Feb
id: >-
https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2024-02-22&id=166e6f71-9368-488f-9a12-888d240b9674&referrer=rss®ion=South
West England
guidislink: false
- title: Yellow warning of wind affecting South West England
title_detail:
type: text/plain
language: null
base: https://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/sw
value: Yellow warning of wind affecting South West England
links:
- rel: alternate
type: text/html
href: >-
https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2024-02-22&id=603a4c83-9114-4648-8840-7e78b26978ca&referrer=rss
- length: '15776'
type: image/png
href: >-
https://data.consumer-digital.api.metoffice.gov.uk/v1/warnings/rss/image/yellow-wind.png
rel: enclosure
link: >-
https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2024-02-22&id=603a4c83-9114-4648-8840-7e78b26978ca&referrer=rss
summary: >-
Yellow warning of wind affecting South West England: Bournemouth
Christchurch and Poole, Dorset, Wiltshire valid from 0800 Thu 22 Feb to 1800
Thu 22 Feb
summary_detail:
type: text/html
language: null
base: https://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/sw
value: >-
Yellow warning of wind affecting South West England: Bournemouth
Christchurch and Poole, Dorset, Wiltshire valid from 0800 Thu 22 Feb to
1800 Thu 22 Feb
id: >-
https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2024-02-22&id=603a4c83-9114-4648-8840-7e78b26978ca&referrer=rss®ion=South
West England
guidislink: false
- title: Yellow warning of rain affecting South West England
title_detail:
type: text/plain
language: null
base: https://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/sw
value: Yellow warning of rain affecting South West England
links:
- rel: alternate
type: text/html
href: >-
https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2024-02-22&id=fbd10cc1-d33f-4cca-90c7-379ed4172ca4&referrer=rss
- length: '15285'
type: image/png
href: >-
https://data.consumer-digital.api.metoffice.gov.uk/v1/warnings/rss/image/yellow-rain.png
rel: enclosure
link: >-
https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2024-02-22&id=fbd10cc1-d33f-4cca-90c7-379ed4172ca4&referrer=rss
summary: >-
Yellow warning of rain affecting South West England: Bournemouth
Christchurch and Poole, Cornwall, Devon, Dorset, Gloucestershire, North
Somerset, Plymouth, Somerset, South Gloucestershire, Torbay valid from 0300
Thu 22 Feb to 1400 Thu 22 Feb
summary_detail:
type: text/html
language: null
base: https://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/sw
value: >-
Yellow warning of rain affecting South West England: Bournemouth
Christchurch and Poole, Cornwall, Devon, Dorset, Gloucestershire, North
Somerset, Plymouth, Somerset, South Gloucestershire, Torbay valid from
0300 Thu 22 Feb to 1400 Thu 22 Feb
id: >-
https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2024-02-22&id=fbd10cc1-d33f-4cca-90c7-379ed4172ca4&referrer=rss®ion=South
West England
guidislink: false
icon: mdi:rss
friendly_name: Weather Alerts