Skip to content

Commit 33aecc8

Browse files
Add markdown card example
1 parent 6b0c141 commit 33aecc8

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,47 @@ actions:
8989
mode: single
9090
```
9191

92+
### Markdown card example
93+
94+
A markdown card you can add to dashboards showing the state of all your Label State sensors, thanks [@bcjmk](https://github.com/bcjmk)
95+
96+
![Markdown Card](https://raw.githubusercontent.com/andrew-codechimp/ha-label-state/main/images/markdown-card-example.png "Markdown Card")
97+
98+
```yaml
99+
{%- set integration_name = 'label_state' %}
100+
{%- set binary_sensors = integration_entities(integration_name) | select('match', '^binary_sensor\.') | list %}
101+
102+
# {{ integration_name.replace('_', ' ').title() }} Status
103+
104+
{%- if binary_sensors %}
105+
Items to check: {{ binary_sensors | count }}
106+
107+
{%- for sensor in binary_sensors %}
108+
{%- set label_name = state_attr(sensor, 'label_name') %}
109+
{%- set monitored_entities = label_entities(label_name) %}
110+
{%- set problem_ids = state_attr(sensor, 'entities') or [] %}
111+
{%- set sensor_state = states(sensor) %}
112+
<details>
113+
<summary><b>{{ state_attr(sensor, 'friendly_name') or sensor }}</b> &mdash; {% if sensor_state == 'off' %}✅ All OK{% elif sensor_state == 'on' %}⚠️ ALERT{% else %}❓ {{ sensor_state }}{% endif %}</summary>
114+
115+
**Monitored Entities:**
116+
{%- if monitored_entities %}
117+
{%- for entity in monitored_entities %}
118+
- {% if entity in problem_ids %}⚠️ {% endif %}[{{ state_attr(entity, 'friendly_name') or entity }}](/history?entity_id={{ entity }}) ({{ states(entity) }})
119+
{%- endfor %}
120+
{%- else %}
121+
- ❓ No entities found with label '{{ label_name }}'
122+
{%- endif %}
123+
124+
</details>
125+
126+
{%- endfor %}
127+
{%- else %}
128+
❓ No binary sensors found for the integration '{{ integration_name }}'.
129+
{%- endif %}
130+
```
131+
132+
92133
### Translations
93134

94135
You can help by adding missing translations when you are a native speaker. Or add a complete new language when there is no language file available.

images/markdown-card-example.png

37 KB
Loading

0 commit comments

Comments
 (0)