Skip to content

Commit

Permalink
Merge pull request #57 from mdecourcy/master
Browse files Browse the repository at this point in the history
generate markdown card with loop
  • Loading branch information
finity69x2 authored Apr 20, 2023
2 parents fbb67d9 + 9e7534c commit bd77be5
Showing 1 changed file with 17 additions and 116 deletions.
133 changes: 17 additions & 116 deletions lovelace/alerts_tab
Original file line number Diff line number Diff line change
@@ -1,132 +1,33 @@
#########################################################################################
title: "Alerts"

type: custom:vertical-layout
layout:
max_cols: 4
theme: Backend-selected
title: Alerts
path: nws-alerts
badges: []
cards:
- type: custom:stack-in-card
cards:
- type: entities
title: Severe Weather Alerts
show_header_toggle: false
entities: sensor.nws_alerts
- type: conditional
conditions:
- entity: sensor.nws_alerts
state_not: '0'
card:
type: markdown
content: >
---

# NWS First Active Alert
{% if state_attr('sensor.nws_alerts', 'title') != None and state_attr('sensor.nws_alerts', 'title').split(' - ')[0] is defined %}

## {{ states.sensor.nws_alerts.attributes.title.split(' - ')[0] }}

{{ state_attr('sensor.nws_alerts', 'display_desc').split('\n\n-\n\n')[0] }}

{% else %}
none
{% endif %}
- type: conditional
conditions:
- entity: sensor.nws_alerts
state_not: "0"
- entity: sensor.nws_alerts
state_not: "1"
card:
type: markdown
content: >
---

# NWS Second Active Alert
{% if state_attr('sensor.nws_alerts', 'title').split(' - ')[1] is defined %}

## {{ states.sensor.nws_alerts.attributes.title.split(' - ')[1] }}

{{ state_attr('sensor.nws_alerts', 'display_desc').split('\n\n-\n\n')[1] }}

{% else %}
none
{% endif %}
- type: conditional
conditions:
- entity: sensor.nws_alerts
state_not: "0"
- entity: sensor.nws_alerts
state_not: "1"
- entity: sensor.nws_alerts
state_not: "2"
card:
type: markdown
content: >
---

# NWS Third Active Alert
{% if state_attr('sensor.nws_alerts', 'title').split(' - ')[2] is defined %}

## {{ states.sensor.nws_alerts.attributes.title.split(' - ')[2] }}

{{ state_attr('sensor.nws_alerts', 'display_desc').split('\n\n-\n\n')[2] }}

{% else %}
none
{% endif %}
- type: conditional
conditions:
- entity: sensor.nws_alerts
state_not: "0"
- entity: sensor.nws_alerts
state_not: "1"
- entity: sensor.nws_alerts
state_not: "2"
- entity: sensor.nws_alerts
state_not: "3"
card:
type: markdown
content: >
---

# NWS Fourth Active Alert
{% if state_attr('sensor.nws_alerts', 'title').split(' - ')[3] is defined %}

## {{ states.sensor.nws_alerts.attributes.title.split(' - ')[3] }}

{{ state_attr('sensor.nws_alerts', 'display_desc').split('\n\n-\n\n')[3] }}

{% else %}
none
{% endif %}
entities:
- sensor.nws_alerts
- type: conditional
conditions:
- entity: sensor.nws_alerts
state_not: "0"
- entity: sensor.nws_alerts
state_not: "1"
- entity: sensor.nws_alerts
state_not: "2"
- entity: sensor.nws_alerts
state_not: "3"
- entity: sensor.nws_alerts
state_not: "4"
card:
type: markdown
content: >
content: |
{% set num_alerts = states('sensor.nws_alerts') | int %}
{% for alert_num in range(num_alerts) %}
---

# NWS Fifth Active Alert
{% if state_attr('sensor.nws_alerts', 'title').split(' - ')[4] is defined %}

## {{ states.sensor.nws_alerts.attributes.title.split(' - ')[4] }}

{{ state_attr('sensor.nws_alerts', 'display_desc').split('\n\n-\n\n')[4] }}

{% else %}
# NWS Alert {{ alert_num + 1 }}
{% if state_attr('sensor.nws_alerts', 'title').split(' - ')[alert_num] is defined %}
## {{ states.sensor.nws_alerts.attributes.title.split(' - ')[alert_num] }}
{{ state_attr('sensor.nws_alerts', 'display_desc').split('\n\n-\n\n')[alert_num] }}
{% else %}
none
{% endif %}

{% endif %}
{% endfor %}
- type: entities
title: NWS Alerts History
show_header_toggle: false
Expand All @@ -148,4 +49,4 @@ cards:
- variable.nws_alerts_event_ids.history_7
- variable.nws_alerts_event_ids.history_8
- variable.nws_alerts_event_ids.history_9
- variable.nws_alerts_event_ids.history_10
- variable.nws_alerts_event_ids.history_10

0 comments on commit bd77be5

Please sign in to comment.