Trying to learn

So today it’s Sunday so I thought I’d try to broaden my ‘knowledge’ a bit.
So I tried to create a markdown card looking for the info for weather alerts.
Being that it’s winter and we are actually having one… why not.

{{ state_attr('sensor.nws_alerts_alerts', 'Alerts') }}

Gets me to here:

What I’d like to get is the “Description” part of the Alert, is that even possible?

Many Thanks for all that help!!!

EDIT: Okay so I figured this out… but I have only one more question…
How do you extract data if there’s more than 1 alert?

Here’s the winner for the ONE alert…

 {{ states.sensor['nws_alerts_alerts'].attributes['Alerts'][0]['Description']}}

This ought to work for any number of alerts.

{{ state_attr('sensor.nws_alerts_alerts', 'Alerts')
  | map(attribute='Description')
  | list | join('\n') }}

If the Markdown card doesn’t handle \n as a newline, replace it with an HTML line break tag <br>

Thank you!! The template test area likes it… but I won’t know until there’s more than 1 alert here… there were 2 but I missed one of them sooooo.

It also works on the frontend too!! So I’ll have to wait for more than 1 alert before going any further… which is putting them in rotation but one step at a time…
Thank you so much for the help!!!

You can simply use simulated data.

{% set Alerts = [
{'Event': 'Wind Advisory',
 'Description': 'Wind weather alert.'},
{'Event': 'Rain Advisory',
 'Description': 'Rain weather alert.'},
{'Event': 'Hail Advisory',
 'Description': 'Hail weather alert.'},
{'Event': 'Tornado Advisory',
 'Description': 'Tornado weather alert.'}] -%}
{{ Alerts | map(attribute='Description')
  | list | join('\n') }}

OH yes… that’ll work!!! Thank you!!

1 Like