Created
July 27, 2023 21:35
-
-
Save nxcre/2f27d479ba30284ecdc8af4b013f20ef to your computer and use it in GitHub Desktop.
Markdown Card for the NINA integration. It uses ha-alert elements with the corresponding severity to display each active warning.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type: conditional | |
conditions: | |
- entity: binary_sensor.katastrophenwarnung | |
state: 'on' | |
card: | |
type: entity-filter | |
entities: | |
- binary_sensor.warning_city_01 | |
- binary_sensor.warning_city_02 | |
- binary_sensor.warning_city_03 | |
- binary_sensor.warning_city_04 | |
- binary_sensor.warning_city_05 | |
- binary_sensor.warning_city_06 | |
- binary_sensor.warning_city_07 | |
- binary_sensor.warning_city_08 | |
- binary_sensor.warning_city_09 | |
- binary_sensor.warning_city_10 | |
state_filter: | |
- 'on' | |
card: | |
type: markdown | |
title: MELDUNGEN (Production) | |
content: >- | |
{# --- Loop through the entities with state 'on' --- #} | |
{% for item in config.entities %} | |
{# --- SETTINGS --- #} | |
{% set show_recommend_action = true %} | |
{% set show_timeframe = true %} | |
{% set show_source = false %} | |
{% set show_timestamp_sent = false %} | |
{% set default_source = 'NINA' %} | |
{% set minor_severity = "info" %} | |
{% set moderate_severity = "info" %} | |
{% set default_severity = "success" %} | |
{# --- Initialise attribute values --- #} | |
{% set headline = state_attr(item.entity, "headline")|default('Meldung', true) %} | |
{% set description = state_attr(item.entity, "description")|default('', true)|trim %} | |
{% set recommended_actions = state_attr(item.entity, "recommended_actions")|default('', true)|trim %} | |
{% set warn_timeframe = "" %} | |
{% set level = state_attr(item.entity, "severity")|default(default_severity, true) %} | |
{% set sender = state_attr(item.entity, "sender")|default(default_source, true) %} | |
{# --- Set severity --- #} | |
{% if level == "Extreme" %} {% set severity = "error" %} | |
{% elif level == "Severe" %}{% set severity = "warning" %} | |
{% elif level == "Moderate" %}{% set severity = moderate_severity %} | |
{% elif level == "Minor" %}{% set severity = minor_severity %} | |
{% else %}{% set severity = default_severity %} {% endif %} | |
{# --- Check attribute content --- #} | |
{% set has_start = (not not state_attr(item.entity, 'start')|default(false, true)) %} | |
{% set has_sent = (not not state_attr(item.entity, 'sent')|default(false, true)) %} | |
{% set has_end = (not not state_attr(item.entity, 'end')|default(false, true)) %} | |
{% set has_expires = (not not state_attr(item.entity, 'expires')|default(false, true)) %} | |
{% set has_recommended_actions = (not not state_attr(item.entity, 'recommended_actions')|default(false, true)) %} | |
{# --- Fill timestamp variables --- #} | |
{% if has_sent %} | |
{% set time_sent = as_timestamp(state_attr(item.entity, "sent")) %} | |
{% else %} | |
{% set time_sent = as_timestamp("1970-01-01T00:00:00+00:00") %} | |
{% endif %} | |
{% set num_weekday_sent = time_sent | timestamp_custom("%w", True) | int %} | |
{% set weekday_sent = "" ~ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][num_weekday_sent-1] %} | |
{% if has_start %} | |
{% set time_start = as_timestamp(state_attr(item.entity, "start")) %} | |
{% else %} | |
{% set time_start = as_timestamp("1970-01-01T00:00:00+00:00") %} | |
{% endif %} | |
{% set num_weekday_start = time_start | timestamp_custom("%w", True) | int %} | |
{% set weekday_start = "" ~ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][num_weekday_start-1] %} | |
{% if has_end %} | |
{% set time_end = as_timestamp(state_attr(item.entity, "end")) %} | |
{% else %} | |
{% set time_end = as_timestamp("1970-01-01T00:00:00+00:00") %} | |
{% endif %} | |
{% set num_weekday_end = time_end | timestamp_custom("%w", True) | int %} | |
{% set weekday_end = "" ~ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][num_weekday_end-1] %} | |
{% if has_expires %} | |
{% set time_expires = as_timestamp(state_attr(item.entity, "expires")) %} | |
{% else %} | |
{% set time_expires = as_timestamp("1970-01-01T00:00:00+00:00") %} | |
{% endif %} | |
{% set num_weekday_expires = time_expires | timestamp_custom("%w", True) | int %} | |
{% set weekday_expires = "" ~ ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'][num_weekday_expires-1] %} | |
{# --- Format recommended_actions for warning --- #} | |
{% if has_recommended_actions %} | |
{% set recommended_actions = "<br/>**Empfehlung:** " ~ recommended_actions ~ "<br/>" %} | |
{% endif %} | |
{# --- Format custom timeframe for warning --- #} | |
{% if show_timeframe %} | |
{% set warn_timeframe = "<br/>**" ~ weekday_sent ~ ", " ~ time_sent | timestamp_custom("%H:%M Uhr") %} | |
{% if has_start %} | |
{% set warn_timeframe = "<br/>**" ~ weekday_start ~ ", " ~ time_start | timestamp_custom("%H:%M Uhr") %} | |
{% endif %} | |
{% if has_end %} | |
{% set warn_timeframe = warn_timeframe ~ " - " ~ weekday_end ~ ", " ~ time_end | timestamp_custom("%H:%M Uhr") ~ "**<br/>" %} | |
{% elif has_expires %} | |
{% set warn_timeframe = warn_timeframe ~ " - " ~ weekday_expires ~ ", " ~ time_expires | timestamp_custom("%H:%M Uhr") ~ "**<br/>" %} | |
{% else %} | |
{% set warn_timeframe = "" %} | |
{% set show_timestamp_sent = true %} | |
{% endif %} | |
{% endif %} | |
{# --- Construct ha-alert elements --- #} | |
<ha-alert alert-type="{{ severity }}" title="{{ headline }}"> | |
{{ description }} <br/> | |
{{ recommended_actions }} | |
{{ warn_timeframe }} | |
{% if show_timestamp_sent %} | |
<br/>`{{ time_sent | timestamp_custom("Meldung vom: %d.%m.%Y, %H:%M Uhr") }}` | |
{% endif %} | |
{% if show_source %} | |
<br/>`Quelle: {{ sender }}` | |
{% endif %}</ha-alert> | |
{% endfor %} |
Hi nxcre,
thanks for the template.
You don't need a helper to hide the card. Just use show_empty: false
in the entity-filter.
# uncomment next line if you want to hide the card in case of no warnings
#show_empty: false
I do however show the card and added a note if there are no warnings.
{% if config.entities | length < 1 %}
**<font color=#44739e>Keine Warnungen</font>**
{% endif %}
Maybe you want to add these things to your gist for the benefit of others
Can someone explain me how I can filter minor and maybe moderate warnings here?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello nxcre,
Thank you very much for the great extension. It took me a little longer to understand the helper but now it works.
Would a wish be possible? The message is now displayed... but it can also happen that this message lasts for several hours. Reading this every time and wasting space for it is perhaps worthy of improvement. Would it perhaps be possible to show only the headline and then, by clicking on it, to show the explanation as an option in the config? I would not be able to do that. Greetings