Markdown-card, brauche Professionelle Hilfe

Ein hallo an alle,

Ich bräuchte mal Hilfe von einem Profi:
Ich habe mir eine Markdown Karte angelegt, die mir die Unwetter Warnungen anzeigt - Code hab ich ausm Netz.
Funktioniert auch, allerdings möchte ich die Karte so bearbeiten daß sie mir aus Platzgründen nur das Wichtigste anzeigt.
Den ausführlichen Text konnte ich rauslöschen.
Jetzt möchte aber noch die Warnstufe (Zahl) bearbeiten. Da soll stehen „Warnstufe 2“.


Wenn nicht möglich, dann die Zahl weg.

Ausserdem soll sich die gesamte Karte dynamisch in der Länge je nach Text automatisch anpassen.
(Der (rote) Text ist manchmal einzeilig/zweizeilig)
Hier der Code:

type: markdown
content: >-
  {% set current_count = state_attr("sensor.stadt_pforzheim_aktuelle_warnstufe",
  "warning_count") %}

  {% set advance_count = state_attr("sensor.stadt_pforzheim_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_pforzheim_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_headline") %}
      {% set description = state_attr("sensor.stadt_pforzheim_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_level") %}
      {% set time_start = state_attr("sensor.stadt_pforzheim_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_pforzheim_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_end") | as_timestamp %}
      {% set weekday_end = time_end | timestamp_custom("%w", True) | int %}
  **<font color=red><font size=4>{{ headline }}</font>** 


  *<font color=yellow><font size=5>{{
  ['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_pforzheim_vorwarnstufe", "warning_" ~ loop.index ~ "_headline") %}
      {% set description = state_attr("sensor.stadt_pforzheim_vorwarnstufe", "warning_" ~ loop.index ~ "_description") %}
      {% set level = state_attr("sensor.stadt_pforzheim_vorwarnstufe", "warning_" ~ loop.index ~ "_level") %}
      {% set time_start = state_attr("sensor.stadt_pforzheim_vorwarnstufe", "warning_" ~ loop.index ~ "_start") | as_timestamp%}
      {% set weekday_start = time_start | timestamp_custom("%w", True) | int %}
      {% set time_end = state_attr("sensor.stadt_pforzheim_vorwarnstufe", "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 %} 
grid_options:
  columns: 12
  rows: 3
visibility:
  - condition: states
    entity: sensor.stadt_pforzheim_aktuelle_warnstufe
    states: 0<

Ich weiß nicht ob meine Wünsche überhaupt machbar sind, aber ich frage halt mal.

Gruß Jürgen

Dafür dann das Level noch einbauen, z.b. vor die headline

  **<font color=red><font size=4>Warnstufe {{level}} - {{ headline }}</font>** 

Wenn du es auch für die Aktulle Warnstufe haben willst, musst du da auch das Level noch definieren

      {% set level = state_attr("sensor.stadt_pforzheim_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_level") %}

Wobei ich gerade sehe, dass du bei der description irgendwas mit dem level vermischt hast :thinking:

1 „Gefällt mir“

Denke auch bei der description hast du etwas vertauscht und die headline soll doch sicherlich nicht nur die Nummer (Warnstufe) enthalten, oder? Nimm die Zeile einfach heraus bzw. ersetze sie mit set level wie maxe schrieb.

Die Abfrage der Variable könnte dann so aussehen:

  {% if level is defined and level != "" %}
  *<font color=red><font size=4>Warnstufe {{ level }}</font>*
  {% endif %}

@jayjojayson
Eine Abfrage erfolgt ja schon früher

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

Und für die Vorwarnstufe

    {% if ((current_count != 0) and (advance_count != 0)) %}{% endif %}
    {% for i in range(advance_count) %
1 „Gefällt mir“

Stimmt, dann kann er gleich deine Zeile bei … einfügen

 **<font color=red><font size=4>Warnstufe {{level}} - {{ headline }}</font>**
1 „Gefällt mir“

Nein, einfach die beiden schon vorhandenen Zeilen

  **<font color=red><font size=4>{{ headline }}</font>** 

mit meiner ersetzen.

Und das mit dem Level der Aktuellen Warnstufe korrigieren.

Hi maxe und Jayjojayson,

Jetzt bin ich irgendwie verwirrt, wo muß was hin (Zeile?) und was muß weg (Zeile?) ?
Tut mir Leid, aber ich hab keine Ahnung vom Programmieren, kann bischen copy & paste, und verstehe manche Dinge, aber das hier sind für mich ???
Und ja, stimmt, habe im org. Code schon rumgepfuscht, wohl nicht so ganz erfolgreich.

Danke und gruß
Jürgen

Ich würde es mal so versuchen (ungetestet)

type: markdown
content: >-
  {% set current_count = state_attr("sensor.stadt_pforzheim_aktuelle_warnstufe",
  "warning_count") %}

  {% set advance_count = state_attr("sensor.stadt_pforzheim_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_pforzheim_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_headline") %}
      {% set description = state_attr("sensor.stadt_pforzheim_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_description") %}
      {% set level = state_attr("sensor.stadt_pforzheim_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_level") %}
      {% set time_start = state_attr("sensor.stadt_pforzheim_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_pforzheim_aktuelle_warnstufe", "warning_" ~ loop.index ~ "_end") | as_timestamp %}
      {% set weekday_end = time_end | timestamp_custom("%w", True) | int %}
  **<font color=red><font size=4>{{ headline }}</font>** 


  *<font color=yellow><font size=5>{{
  ['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>*
      Warnstufe {{ level }}
      {% 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_pforzheim_vorwarnstufe", "warning_" ~ loop.index ~ "_headline") %}
      {% set description = state_attr("sensor.stadt_pforzheim_vorwarnstufe", "warning_" ~ loop.index ~ "_description") %}
      {% set level = state_attr("sensor.stadt_pforzheim_vorwarnstufe", "warning_" ~ loop.index ~ "_level") %}
      {% set time_start = state_attr("sensor.stadt_pforzheim_vorwarnstufe", "warning_" ~ loop.index ~ "_start") | as_timestamp%}
      {% set weekday_start = time_start | timestamp_custom("%w", True) | int %}
      {% set time_end = state_attr("sensor.stadt_pforzheim_vorwarnstufe", "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>*
      Warnstufe {{ level }}
      {% if not loop.last %}
  ***
      {% endif %}
    {% endfor %}
  {% endif %} 
grid_options:
  columns: 12
  rows: 3
visibility:
  - condition: numeric_state
    entity: sensor.stadt_pforzheim_aktuelle_warnstufe
    above: 0
1 „Gefällt mir“

Hi maxe,

Super, ja, so funktioniert es. Auch mein „visibility“ Problem hast du nebenbei gelöst.
Ich sage mal danke und setze das auf gelöst.

Hätte da noch ne Frage, habe ganz unten unter den „grid_options“ die „rows: 3“ entfernt, wächst die Karte nun mit ?

Gruß Jürgen

ja einfach die Zeile weglassen, dann passt sich die Card automatisch an. row: auto müsste dort auch funktionieren.

Japp, du hattest fälschlicherweise Zustand anstelle von Nummerischen Zustand genommen.

wieder was gelernt, danke. :+1:

Da hatte ich schon rumprobiert, aber ohne Erfolg, auch hierfür ein Danke :+1:

Schönen Sonntag noch und Gruß

Jürgen