DWD WarnWetter markdown card

Just copied the latest content (two posts above) and do not have anything showed (yes, we have weather warnings currently)…

Any ideas?

OK, got it.
(Again), for all newcomers here: ALWAYS copy and paste into the editor, NOT in the visual!
Then it works :slight_smile:

Hi

Today i got this "Error"

<font color=>Amtliche WARNUNG vor extremer HITZE
Tue 11:00 - Tue 19:00
Am Dienstag wird eine extreme Wärmebelastung erwartet.

Any Idea ? This is the reading:

warning 1 name   EXTREME HITZE
warning 1 level     51
warning 1 type      8
warning 1 headline  Amtliche WARNUNG vor extremer HITZE


Sorry for the formatting, i am new with this editor :(

The error is that no color for level 51 is defined
Update the following line:

{% set level_colors = {0:'#c5e566', 1:'#ffeb3b', 2:'#fb8c00', 3:'#e53935', 4:'#880e4f', 20:'#fe68fe', 50:'#fe68fe', 51:'#9e46f8'} %}

You can also check if a color is defined for the warning level and use a default colro aus fallback.

Thank you very much . That solved the Problem

With the upcomming home-assistant release 0.115 there will be some light changes in the dwd weather warnings sensor which affect the markdown card.

The major changes are:

  • DWD’s new API is used which allowes more detailed queries (not just counties, but also cities, sea regions, coast regions and bigger lakes). See docs after release.
  • The warning color is now part of the sensor value
  • All timestamps are now UTC

My whole card:

content: >-
  {% set current_count = state_attr("sensor.warnwetter_current_warning_level", "warning_count") %}
  {% set advance_count = state_attr("sensor.warnwetter_advance_warning_level", "warning_count") %}
  {% if ((current_count == 0 or current_count == None) and (advance_count == 0 or advance_count == None)) %}
    **<font color=#c5e566>Keine Warnungen</font>**
  {% else %}
    {% for i in range(current_count) %}
      {% set headline = state_attr("sensor.warnwetter_current_warning_level", "warning_" ~ loop.index ~ "_headline") %}
      {% set description = state_attr("sensor.warnwetter_current_warning_level", "warning_" ~ loop.index ~ "_description") %}
      {% set level = state_attr("sensor.warnwetter_current_warning_level", "warning_" ~ loop.index ~ "_level") %}
      {% set time_start = state_attr("sensor.warnwetter_current_warning_level", "warning_" ~ loop.index ~ "_start") | as_timestamp %}
      {% set time_end = state_attr("sensor.warnwetter_current_warning_level", "warning_" ~ loop.index ~ "_end") | as_timestamp %}
      {% set color = state_attr("sensor.warnwetter_current_warning_level", "warning_" ~ loop.index ~ "_color") %}
    **<font color={{ color }}>{{ headline }}</font>**
    {{ time_start | timestamp_custom("%a %H:%M") ~ " - " ~ time_end | timestamp_custom("%a %H:%M") }}
    *{{ description|trim }}*
    {% if not loop.last %}***{% endif %}
    {% endfor %}
    {% if ((current_count != 0) and (advance_count != 0)) %}***{% endif %}
    {% for i in range(advance_count) %}
      {% set headline = state_attr("sensor.warnwetter_advance_warning_level", "warning_" ~ loop.index ~ "_headline") %}
      {% set description = state_attr("sensor.warnwetter_advance_warning_level", "warning_" ~ loop.index ~ "_description") %}
      {% set level = state_attr("sensor.warnwetter_advance_warning_level", "warning_" ~ loop.index ~ "_level") %}
      {% set time_start = state_attr("sensor.warnwetter_advance_warning_level", "warning_" ~ loop.index ~ "_start") | as_timestamp %}
      {% set time_end = state_attr("sensor.warnwetter_advance_warning_level", "warning_" ~ loop.index ~ "_end") | as_timestamp %}
      {% set color = state_attr("sensor.warnwetter_advance_warning_level", "warning_" ~ loop.index ~ "_color") %}
    **<font color={{ color }}>{{ headline }}</font>**
    {{ time_start | timestamp_custom("%a %H:%M") ~ " - " ~ time_end | timestamp_custom("%a %H:%M") }}
    *{{ description|trim }}*
    {% if not loop.last %}***{% endif %}
    {% endfor %}
  {% endif %}
title: DWD Wetterwarnungen
type: markdown
6 Likes

Great script. Thank you! Would it also be possible to display the weekdays in another language? In my case German. So … instead of Tue = Dienstag for example?

I use the following parts in order to get the weekdays in german:

{% set time_start = state_attr("sensor.wetterwarnungen_current_warning_level", "warning_" ~ loop.index ~ "_start") %}
{% set weekday_start = as_timestamp(time_start) | timestamp_custom("%w", True) | int %}
{% set time_end = state_attr("sensor.wetterwarnungen_current_warning_level", "warning_" ~ loop.index ~ "_end") %}
{% set weekday_end = as_timestamp(time_end) | timestamp_custom("%w", True) | int %}

{{ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][weekday_start-1] ~ ", " ~ time_start.strftime("%H:%M") ~ " - " ~ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][weekday_end-1] ~ ", " ~ time_end.strftime("%H:%M") }}

Can you please post the complete YAML Code ?
Thx

Sure.

  - type: markdown
    title: Wetterwarnungen
    content: >-      
      {% set current_count = state_attr("sensor.wetterwarnungen_current_warning_level", "warning_count") %}
      {% set advance_count = state_attr("sensor.wetterwarnungen_advance_warning_level", "warning_count") %}
      {% if ((current_count == 0 or current_count == None) and (advance_count == 0 or advance_count == None)) %}
      **<font color=#c5e566>Keine Warnungen</font>**
      {% else %}
        {% for i in range(current_count) %}
          {% set headline = state_attr("sensor.wetterwarnungen_current_warning_level", "warning_" ~ loop.index ~ "_headline") %}
          {% set description = state_attr("sensor.wetterwarnungen_current_warning_level", "warning_" ~ loop.index ~ "_description") %}
          {% set level = state_attr("sensor.wetterwarnungen_current_warning_level", "warning_" ~ loop.index ~ "_level") %}
          {% set time_start = state_attr("sensor.wetterwarnungen_current_warning_level", "warning_" ~ loop.index ~ "_start") %}
          {% set weekday_start = as_timestamp(time_start) | timestamp_custom("%w", True) | int %}
          {% set time_end = state_attr("sensor.wetterwarnungen_current_warning_level", "warning_" ~ loop.index ~ "_end") %}
          {% set weekday_end = as_timestamp(time_end) | timestamp_custom("%w", True) | int %}
          {% set color = state_attr("sensor.wetterwarnungen_current_warning_level", "warning_" ~ loop.index ~ "_color") %}
        **<font color={{ color }}>{{ headline }}</font>**     
        {{ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][weekday_start-1] ~ ", " ~ time_start.strftime("%H:%M") ~ " - " ~ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][weekday_end-1] ~ ", " ~ time_end.strftime("%H:%M") }}
        *{{ description|trim }}*
        {% if not loop.last %}***{% endif %}
        {% endfor %}
        {% if ((current_count != 0) and (advance_count != 0)) %}***{% endif %}
        {% for i in range(advance_count) %}
          {% set headline = state_attr("sensor.wetterwarnungen_advance_warning_level", "warning_" ~ loop.index ~ "_headline") %}
          {% set description = state_attr("sensor.wetterwarnungen_advance_warning_level", "warning_" ~ loop.index ~ "_description") %}
          {% set level = state_attr("sensor.sensor.wetterwarnungen_advance_warning_level", "warning_" ~ loop.index ~ "_level") %}
          {% set time_start = state_attr("sensor.wetterwarnungen_advance_warning_level", "warning_" ~ loop.index ~ "_start") %}
          {% set weekday_start = as_timestamp(time_start) | timestamp_custom("%w", True) | int %}
          {% set time_end = state_attr("sensor.wetterwarnungen_advance_warning_level", "warning_" ~ loop.index ~ "_end") %}
          {% set weekday_end = as_timestamp(time_end) | timestamp_custom("%w", True) | int %}
          {% set color = state_attr("sensor.wetterwarnungen_advance_warning_level", "warning_" ~ loop.index ~ "_color") %}
        **<font color={{ color }}>{{ headline }}</font>**
        {{ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][weekday_start-1] ~ ", " ~ time_start.strftime("%H:%M") ~ " - " ~ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][weekday_end-1] ~ ", " ~ time_end.strftime("%H:%M") }}
        *{{ description|trim }}*
        {% if not loop.last %}***{% endif %}
        {% endfor %}
      {% endif %}  
1 Like

Thank you very much, works great now.

image

I changed the color logic a bit for better readability and to be in line with the HA default theme.
Note: That does ignore the colors from DWD.
image
image

      {% set current_count = state_attr("sensor.dwd_weather_warnings_current_warning_level", "warning_count") %}
      {% set advance_count = state_attr("sensor.dwd_weather_warnings_advance_warning_level", "warning_count") %}
      {% if ((current_count == 0 or current_count == None) and (advance_count == 0 or advance_count == None)) %}
      **<font color=#44739e>Keine Warnungen</font>**
      {% else %}
        {% for i in range(current_count) %}
          {% set headline = state_attr("sensor.dwd_weather_warnings_current_warning_level", "warning_" ~ loop.index ~ "_headline") %}
          {% set description = state_attr("sensor.dwd_weather_warnings_current_warning_level", "warning_" ~ loop.index ~ "_description") %}
          {% set level = state_attr("sensor.dwd_weather_warnings_current_warning_level", "warning_" ~ loop.index ~ "_level") %}
          {% set time_start = state_attr("sensor.dwd_weather_warnings_current_warning_level", "warning_" ~ loop.index ~ "_start") | as_timestamp %}
          {% set weekday_start = time_start | timestamp_custom("%w", True) | int %}
          {% set time_end = state_attr("sensor.dwd_weather_warnings_current_warning_level", "warning_" ~ loop.index ~ "_end") | as_timestamp %}
          {% set weekday_end = time_end | timestamp_custom("%w", True) | int %}
**<font color=#fdd835>{{ headline }}</font>**     
*<font color=gray>{{ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][weekday_start-1] ~ ", " ~ time_start | timestamp_custom("%H:%M") ~ " - " ~ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][weekday_end-1] ~ ", " ~ time_end | timestamp_custom("%H:%M") }}</font>*
        {{ description|trim }}
        {% if not loop.last %}
***
        {% endif %}
        {% endfor %}
        {% if ((current_count != 0) and (advance_count != 0)) %}{% endif %}
        {% for i in range(advance_count) %}
          {% set headline = state_attr("sensor.dwd_weather_warnings_advance_warning_level", "warning_" ~ loop.index ~ "_headline") %}
          {% set description = state_attr("sensor.dwd_weather_warnings_advance_warning_level", "warning_" ~ loop.index ~ "_description") %}
          {% set level = state_attr("sensor.sensor.dwd_weather_warnings_advance_warning_level", "warning_" ~ loop.index ~ "_level") %}
          {% set time_start = state_attr("sensor.dwd_weather_warnings_advance_warning_level", "warning_" ~ loop.index ~ "_start") | as_timestamp%}
          {% set weekday_start = time_start | timestamp_custom("%w", True) | int %}
          {% set time_end = state_attr("sensor.dwd_weather_warnings_advance_warning_level", "warning_" ~ loop.index ~ "_end") | as_timestamp %}
          {% set weekday_end = time_end | timestamp_custom("%w", True) | int %}
**<font color=#fdd835>{{ headline }}</font>**
*<font color=gray>{{ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][weekday_start-1] ~ ", " ~ time_start | timestamp_custom("%H:%M") ~ " - " ~ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][weekday_end-1] ~ ", " ~ time_end | timestamp_custom("%H:%M") }}</font>*
        {{ description|trim }}
        {% if not loop.last %}
***
        {% endif %}
        {% endfor %}
      {% endif %} 

4 Likes

I think there is a error in the code, Weekday is always show as Sonntag …

Fixed the markup above.

What is the state of the sensor? Max level of existing warnings? Didn’t find the information in the docs and it is <> count.

And did someone ever get something in advance sensor?

Yes, the state of the sensor is the max level of all currently existing warnings.

I’ve seen advance warnings. The advance sensor contains all warnings marked as “Vorabinformationen” (red hatched) on the DWD homepage. This type of message is rather rare.

1 Like

Thank you.

I also integrated the dwd addon - works except something in the formatting:

It looks like this:

Screenshot_20220109_181550

Which means it does not separate the warnings with a line.

What did I do wrong ?

Like my prior post.