Markdown für DWD-Unwetterwarnung - Codeproblem

Moin zusammen!

Ich habe mir vor einigen Tagen die Integration “DWD-Unwetterwarnung” installiert und auch das Markdown aus dem entsprechenden YT-Tutorial eingepflegt. Das Ergebnis ist das folgende:

Wie man sieht, funktioniert die aktuelle Warnstufe (obere Hälfte) gut und auch die Formatierung ist korrekt.

Der Sensor für die Vorhersage (untere Hälfte) zieht auch Daten, aber die Formatierung spinnt hier völlig.

Ich habe den Code der Vorwarnstufe zigfach studiert, aber ich finde den Fehler nicht:

type: markdown
          content: |2-
              {% set level_colors = {0:'#c5e566', 1:'#ffeb3b', 2:'#fb8c00', 3:'#e53935', 4:'#880e4f', 20:'#fe68fe', 50:'#fe68fe'} %}
              {% set current_count = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_count") %}
              {% set advance_count = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "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.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_headline") %}
                  {% set description = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_description") %}
                  {% set level = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_level") %}
                  {% set time_start = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_start") %}
                  {% set time_end = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "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.dwd_weather_warnings_105112000_vorwarnstufe", "warning_" ~ loop.index ~ "_headline") %}
                  {% set description = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "warning_" ~ loop.index ~ "_description") %}
                  {% set level = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "warning_" ~ loop.index ~ "_level") %}
                  {% set time_start = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "warning_" ~ loop.index ~ "_start") %}
                  {% set time_end = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "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 %}

Findet Ihr hier vielleicht den Grund, weshalb die untere Hälfte nicht korrekt formatiert ist?

Danke und beste Grüße!
Stefan

Das sieht mir doch recht komisch aus. Versuch es doch mal so:

type: markdown
content: >-
  {% set level_colors = {0:'#c5e566', 1:'#ffeb3b', 2:'#fb8c00', 3:'#e53935',
  4:'#880e4f', 20:'#fe68fe', 50:'#fe68fe'} %}

  {% set current_count =
  state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe",
  "warning_count") %}

  {% set advance_count =
  state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe",
  "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.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_headline") %}
      {% set description = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_description") %}
      {% set level = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_level") %}
      {% set time_start = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_start") %}
      {% set time_end = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "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.dwd_weather_warnings_105112000_vorwarnstufe", "warning_" ~ loop.index ~ "_headline") %}
      {% set description = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "warning_" ~ loop.index ~ "_description") %}
      {% set level = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "warning_" ~ loop.index ~ "_level") %}
      {% set time_start = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "warning_" ~ loop.index ~ "_start") %}
      {% set time_end = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "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 %}

Es könnte auch einfach nur die falsche Einrückung sein

type: markdown
content: |2-
  {% set level_colors = {0:'#c5e566', 1:'#ffeb3b', 2:'#fb8c00', 3:'#e53935', 4:'#880e4f', 20:'#fe68fe', 50:'#fe68fe'} %}
  {% set current_count = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_count") %}
  {% set advance_count = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "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.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_headline") %}
      {% set description = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_description") %}
      {% set level = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_level") %}
      {% set time_start = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_start") %}
      {% set time_end = state_attr("sensor.dwd_weather_warnings_105112000_aktuelle_warnstufe", "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.dwd_weather_warnings_105112000_vorwarnstufe", "warning_" ~ loop.index ~ "_headline") %}
      {% set description = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "warning_" ~ loop.index ~ "_description") %}
      {% set level = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "warning_" ~ loop.index ~ "_level") %}
      {% set time_start = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "warning_" ~ loop.index ~ "_start") %}
      {% set time_end = state_attr("sensor.dwd_weather_warnings_105112000_vorwarnstufe", "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 %}
2 „Gefällt mir“

1000 Dank - es muss tatsächlich irgendwie an der Einrückung gelegen haben, denn mit der o.g. Version wurden mir spontan beide Sensoren richtig angezeigt und korrekt formatiert!

Klasse, ich freue mich!

Viele Grüße
Stefan

Ich benutzte diesen Code jetzt schon eine Ganze Weile.

Aber ich habe gerade festgestellt, dass die Uhrzeiten der Warnungen mit diesem Code zwei Stunden falsch angezeigt werden.

Aber ich finde den Fehler nicht.

Ich hatte das geiche Problem und hier schon mal eine Lösung aufgezeigt.

Super vielen Dank für den Link und deinen Code. Habe ich gleich mal eingebaut bei mir.

Man möchte ja eigentlich keinen Warnungen, aber bei der nächsten sehe ich dann ob es bei mir auch klappt :blush:

Ich habe es bei mir auch verschieden Versucht. Jedes Markdown was ich im Netz gefunden habe hatte einen anderen Fehler. Bei Einem stimmen die Farben der Headlines nicht bei der Anderen die Wochentage in englisch und die Zeit nach UTC.

Hier jetzt mein funktionierendes: (Beispiel Wernigerrode)

{% set level_colors = {0:'#c5e566', 1:'#ffeb3b', 2:'#fb8c00', 3:'#e53935', 4:'#880e4f', 20:'#fe68fe', 50:'#fe68fe'} %}
{% set current_count = state_attr("sensor.stadt_wernigerode_aktuelle_warnstufe", "warning_count") %}
{% set advance_count = state_attr("sensor.stadt_wernigerode_vorwarnstufe", "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.stadt_wernigerode_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_headline") %}
    {% set description = state_attr("sensor.stadt_wernigerode_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_description") %}
    {% set level = state_attr("sensor.stadt_wernigerode_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_level") %}
    {% set time_start = state_attr("sensor.stadt_wernigerode_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_start") | as_timestamp %}
    {% set weekday_start = time_start | timestamp_custom("%w", True) | int %}
    {% set time_end = state_attr("sensor.stadt_wernigerode_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_end") | as_timestamp %}
    {% set weekday_end = time_end | timestamp_custom("%w", True) | int %}
**<font color={{ level_colors[level] }}>{{ 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.stadt_wernigerode_vorwarnstufe", "warning_" ~ loop.index ~ "_headline") %}
    {% set description = state_attr("sensor.stadt_wernigerode_vorwarnstufe", "warning_" ~ loop.index ~ "_description") %}
    {% set level = state_attr("sensor.stadt_wernigerode_vorwarnstufe", "warning_" ~ loop.index ~ "_level") %}
    {% set time_start = state_attr("sensor.stadt_wernigerode_vorwarnstufe", "warning_" ~ loop.index ~ "_start") | as_timestamp%}
    {% set weekday_start = time_start | timestamp_custom("%w", True) | int %}
    {% set time_end = state_attr("sensor.stadt_wernigerode_vorwarnstufe", "warning_" ~ loop.index ~ "_end") | as_timestamp %}
    {% set weekday_end = time_end | timestamp_custom("%w", True) | int %}
**<font color={{ level_colors[level] }}>{{ 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 %} 
{% set level_colors = {0:'#c5e566', 1:'#ffeb3b', 2:'#fb8c00', 3:'#e53935', 4:'#880e4f', 20:'#fe68fe', 50:'#fe68fe'} %}
{% set current_count =
state_attr("sensor.dwd_weather_warnings_105554000_aktuelle_warnstufe",
"warning_count") %}
{% set advance_count =
state_attr("sensor.dwd_weather_warnings_105554000_vorwarnstufe",
"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.dwd_weather_warnings_105554000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_headline") %}
{% set description = state_attr("sensor.dwd_weather_warnings_105554000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_description") %}
{% set level = state_attr("sensor.dwd_weather_warnings_105554000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_level") %}
{% set time_start = state_attr("sensor.dwd_weather_warnings_105554000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_start") %}
{% set time_end = state_attr("sensor.dwd_weather_warnings_105554000_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_end") %}
**<font color={{ level_colors[3] }}>{{ 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.dwd_weather_warnings_105554000_vorwarnstufe", "warning_" ~ loop.index ~ "_headline") %}
{% set description = state_attr("sensor.dwd_weather_warnings_105554000_vorwarnstufe", "warning_" ~ loop.index ~ "_description") %}
{% set level = state_attr("sensor.dwd_weather_warnings_105554000_vorwarnstufe", "warning_" ~ loop.index ~ "_level") %}
{% set time_start = state_attr("sensor.dwd_weather_warnings_105554000_vorwarnstufe", "warning_" ~ loop.index ~ "_start") %}
{% set time_end = state_attr("sensor.dwd_weather_warnings_105554000_vorwarnstufe", "warning_" ~ loop.index ~ "_end") %}
**<font color={{ level_colors[3] }}>{{ headline }}</font>**
{{ time_start.strftime("%A %H:%M") ~ " - " ~ time_end.strftime("%A %H:%M") }}
*{{ description|trim }}*
{% if not loop.last %}***{% endif %}
{% endfor %}
{% endif %}

Was mach ich falsch, mein code hat mal funktioniert. seit 3-4 wochen nicht mehr.

@sunnewliner
@baxter12

Ich hatte hier mal den neuen Code gepostet

1 „Gefällt mir“

Ich habe auch mehrer Fehlerhafte Lösungen im Netz gefunden. Daher hier meine aktuelle Konfig:

{% set level_colors = {0:'#c5e566', 1:'#ffeb3b', 2:'#fb8c00', 3:'#e53935', 4:'#880e4f', 20:'#fe68fe', 50:'#fe68fe'} %}
{% set current_count = state_attr("sensor.gemeinde_steina_aktuelle_warnstufe", "warning_count") %}
{% set advance_count = state_attr("sensor.gemeinde_steina_vorwarnstufe", "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.gemeinde_steina_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_headline") %}
    {% set description = state_attr("sensor.gemeinde_steina_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_description") %}
    {% set level = state_attr("sensor.gemeinde_steina_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_level") %}
    {% set time_start = state_attr("sensor.gemeinde_steina_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_start") | as_timestamp %}
    {% set weekday_start = time_start | timestamp_custom("%w", True) | int %}
    {% set time_end = state_attr("sensor.gemeinde_steina_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_end") | as_timestamp %}
    {% set weekday_end = time_end | timestamp_custom("%w", True) | int %}
**<font color={{ level_colors[level] }}>{{ 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.gemeinde_steina_vorwarnstufe", "warning_" ~ loop.index ~ "_headline") %}
    {% set description = state_attr("sensor.gemeinde_steina_vorwarnstufe", "warning_" ~ loop.index ~ "_description") %}
    {% set level = state_attr("sensor.gemeinde_steina_vorwarnstufe", "warning_" ~ loop.index ~ "_level") %}
    {% set time_start = state_attr("sensor.gemeinde_steina_vorwarnstufe", "warning_" ~ loop.index ~ "_start") | as_timestamp%}
    {% set weekday_start = time_start | timestamp_custom("%w", True) | int %}
    {% set time_end = state_attr("sensor.gemeinde_steina_vorwarnstufe", "warning_" ~ loop.index ~ "_end") | as_timestamp %}
    {% set weekday_end = time_end | timestamp_custom("%w", True) | int %}
**<font color={{ level_colors[level] }}>{{ 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 %} 

Heute gibts ne Warnung:

fehlermeldung

was für ein Badge wählst du aus ?

:crayon:by HarryP: Zusammenführung Doppelpost (bitte “bearbeiten” Funktion nutzen)

Einfach auf einer Seite ein neues Markdown hinzufügen und dann in dem Markdown den Code einfügen:

und dann hier den Code einfügen:

danke fürs aufklären , habs geschafft… dann muss ich nur die aktuelle warnstufe und vornwarnstufe gegen meine entiäten anpassen ?

image

habs mal unterm Wetter gesetzt… keine warnungen aktuell , ist das bei dir auch so hellblau ?

:crayon:by HarryP: Zusammenführung Doppelpost

UPDATE, das klappt nicht ! @sunnewliner @maxe

image

image
hier die aktuelle warnung.! wird mit deinem Code auf HA nicht angezeigt… KEINE WARNUNG erscheint.

:crayon:by HarryP: Zusammenführung Doppelpost (bitte “bearbeiten” Funktion nutzen)

Welchen Code hast du verwendet? Den hier?

Hast du den region name richtig gesetzt?

@sunnewliner von ihm den Code genutzt

1 „Gefällt mir“

@maxe kann aber gerne mal deinen nutzen… muss nur wissen was in “stadt_xy” rein muss ?

und oft kommt “sensor.” vor was muss da rein ?

und bei "_akutelle_warnstufe " da setze ich meine entiäten rein oder ?

@maxe wäre dir umso mehr dankbar
Wenn du mir dein code entsprechend anpasst, bin da seit wochen mit dran ohne erfolg.

sensor.kreis_borken_aktuelle_warnstufe

sensor.kreis_borken_vorwarnstufe

:crayon:by HarryP: Zusammenführung Doppelpost (bitte “bearbeiten” Funktion nutzen)

Du musst nur stadt_xy mit deinem Kreis ersetzen:
{% set sensor_region_name = "kreis_borken" %}

Sonst nix anpassen.

überall dann ? aus stadt_xy

“kreis_borken” ?