DWD WarnWetter markdown card

I have been playing around with the Deutsche Wetter Dienst (DWD) Weather Warnings Integration and the Markdown Card to get a list of all current and advanced warnings for my region in one card on the dashboard.

In the configuration.yaml i added the following sensor:

sensor:
  - platform: dwd_weather_warnings
    region_name: ENTER_YOUR_REGION_HERE
    name: Warnwetter

The code for the markdown card is:

content: >-
  {% set level_colors = ["#c5e566", "#ffeb3b", "#fb8c00", "#e53935", "#880e4f"] %}
  {% 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) and (advance_count == 0)) %}
  **<font color={{ level_colors[0] }}>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") %}
      {% set time_end = state_attr("sensor.warnwetter_current_warning_level", "warning_" ~ loop.index ~ "_end") %}
    **<font color={{ level_colors[level] }}>{{ headline }}</font>**
    {{ time_start.strftime("%a %H:%M") ~ " - " ~ time_end.strftime("%a %H:%M") }}
    *{{ description }}*
    {% 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") %}
      {% set time_end = state_attr("sensor.warnwetter_advance_warning_level", "warning_" ~ loop.index ~ "_end") %}
    **<font color={{ level_colors[level] }}>{{ headline }}</font>**
    {{ time_start.strftime("%a %H:%M") ~ " - " ~ time_end.strftime("%a %H:%M") }}
    *{{ description }}*
    {% if not loop.last %}***{% endif %}
    {% endfor %}
  {% endif %}
type: markdown
title: DWD Wetterwarnungen

The result looks like:
dwd

21 Likes

Thanks a lot for fiddling this out!
Will definitely add this to my Dashboard!

/Ralf

Great! Thx a lot for that! Unfortunately it does not yet work as expected:

2020-03-22_17h16_02
Do you have an idea what the problem could be?

I think the problem is indentation.
Be careful to not indent any line other (especially more) than i did.
According to markdown syntax indentation of four spaces or one tab results in displaying the following text as code block and that is what your result looks like.

Seems like the line

{% if not loop.last %}***{% endif %}

is indented wrong.

Yes you are right! That is the problem. I really had to triple check to find it, but wrong indention indeed was the problem. Thx for your help!!

Is there a solution how the message: “Es liegt keine Warnung vor” can be displayed?

It always looks a bit strange when only the heading is shown.

Has anyone tried how to forecast the weather e.g. can integrate from the WarnApp?

Would be a nice feature if you get the German weather from a German weather service.

greetings
Gerald

This is how it looks on my screen:
image
I also would appreciate a German weather platform. Unfortunately I am not a programmer at all… :cry:


This ist my Screen

If changed the this line in order to check if the counts are not none. Think it could happen that the attribute “warning_count” is not available sometimes. I checked the sensors now and the attributes are set.

{% if ((current_count == 0 or current_count == None) and (advance_count == 0 or advance_count == None)) %}

1 Like

Hello,

i also get the picture from post #2. Checked the indentation, everything ok. Also copied with the function and inserted. There, created a new Dashboard with this content, but it only shows the code?

Don’t know what i’m doing wrong… any help apreciated.

/ Ralf

If it looks like in the post from Tom7320 it can only be indentation.
When i developed the card i wrote its content with Notepad++ and always replaced the content of the whole card with my next try because the UI editor sometimes thinks he knows better and changes the indentation.
It is also important to switch to the code editor view (“Code-Editor Anzeigen” button in German at the end of the UI editor) and paste the code only in the code editor view of the markdown card.

1 Like

Thanks for sharing @stephan19
This works great on my lovelace dashboard.

I’m wondering if this code can be used for notifications as well. My idea is to have notifications on my (Android) mobile. Ideally, the notifications are sticky as long as the warnings are valid and the notification color is corresponding to the warning level.

Yeah, got it working correctly now. Indentation is the key even it is very sensative…
Thanks a lot!

/Ralf

1 Like

It seems as if the warning level “20” is not taken into account.

I’ve seen that today too.

I think this shoud be fixed when the following part is changed for the current and advanced warnings.

From:

**<font color={{ level_colors[level] }}>{{ headline }}</font>**

To:

**<font color={{ level_colors[level] if level_colors[level] is defined else level_colors[1]  }}>{{ headline }}</font>**

This should prevent the error when another warning level is set and the color from the first warning level is used instead.
I will see if it is working tomorrow since it will be very hot then again.

1 Like

I additionally want to point out, that it seems as if the error level and therefore the color for “normal warnings” is always +1 of the real warning. E.g. if you look at the dwd homepage and see an error in yellow (level 1) in home assistant it will be orange (level 2).
After digging deeper into the problem i found out the the dwd is sending the wrong warning level via the api HA currently uses. I started pull request about 2 months ago to switch to dwd’s new api but the pull request is not yet merged.

Since the warning level 20 (for high UV levels) has its own color, I’ve made another change for the font color:

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

When I find out what level is set for the other types of warnings, I could add the correct color for those.

2 Likes

Italic (description) does not work anymore:

image

Any ideas why?

The code:

{% set level_colors = {0:'#c5e566', 1:'#ffeb3b', 2:'#fb8c00', 3:'#e53935', 4:'#880e4f', 20:'#fe68fe'} %}
{% 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) and (advance_count == 0)) %}
**<font color={{ level_colors[0] }}>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") %}
    {% set time_end = state_attr("sensor.warnwetter_current_warning_level", "warning_" ~ loop.index ~ "_end") %}
  **<font color={{ level_colors[level] if level_colors[level] is defined else level_colors[1]  }}>{{ headline }}</font>**
  {{ time_start.strftime("%a %H:%M") ~ " - " ~ time_end.strftime("%a %H:%M") }}
  *{{ description }}*
  {% 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") %}
    {% set time_end = state_attr("sensor.warnwetter_advance_warning_level", "warning_" ~ loop.index ~ "_end") %}
  **<font color={{ level_colors[level] }}>{{ headline }}</font>**
  {{ time_start.strftime("%a %H:%M") ~ " - " ~ time_end.strftime("%a %H:%M") }}
  *{{ description }}*
  {% if not loop.last %}***{% endif %}
  {% endfor %}
{% endif %}

The problem is that the description ends with a whitespace.

Short solution:

*{{ description|trim }}*

My whole card:

content: >-
  {% set level_colors = {0:'#c5e566', 1:'#ffeb3b', 2:'#fb8c00', 3:'#e53935', 4:'#880e4f', 20:'#fe68fe', 50:'#fe68fe'} %}
  {% 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={{ level_colors[0] }}>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") %}
      {% set time_end = state_attr("sensor.warnwetter_current_warning_level", "warning_" ~ loop.index ~ "_end") %}
    **<font color={{ level_colors[level] }}>{{ headline }}</font>**
    {{ time_start.strftime("%a %H:%M") ~ " - " ~ time_end.strftime("%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") %}
      {% set time_end = state_attr("sensor.warnwetter_advance_warning_level", "warning_" ~ loop.index ~ "_end") %}
    **<font color={{ level_colors[level] }}>{{ headline }}</font>**
    {{ time_start.strftime("%a %H:%M") ~ " - " ~ time_end.strftime("%a %H:%M") }}
    *{{ description|trim }}*
    {% if not loop.last %}***{% endif %}
    {% endfor %}
  {% endif %}
type: markdown
title: DWD Wetterwarnungen
1 Like

Ahhh! Trim. That was it. I was wondering why it sometime did work and sometimes it did not. Now I know… Thx! :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: