forked from wernerhp/ha.integration.load_shedding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
card2.yaml
85 lines (78 loc) · 3.75 KB
/
card2.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
type: vertical-stack
cards:
- type: entities
entities:
- entity: sensor.load_shedding_stage_cape_town
- entity: sensor.load_shedding_stage_eskom
- type: markdown
content: >
{% set stage_sensor = "sensor.load_shedding_stage_eskom" %}
{% set area_sensor = "sensor.load_shedding_area_eskde_14_milnertoncityofcapetownwesterncape" %}
{% set start_time = state_attr(stage_sensor, "start_time") %}
{% set end_time = state_attr(stage_sensor, "end_time") %}
{% set area_schedule = state_attr(area_sensor, "forecast") %}
{% if area_schedule %}
{% set start_time = area_schedule[0].start_time %}
{% set end_time = area_schedule[0].end_time %}
{% if is_state(area_sensor, "off") %}
{% set starts_in = timedelta(minutes=state_attr(area_sensor, "starts_in")) %}
{% if is_state_attr(stage_sensor, "stage", 0) or starts_in.seconds > 86400 %}
<ha-alert alert-type="success">{{ states(stage_sensor) }}</ha-alert>
{% elif not is_state_attr(stage_sensor, "stage", 0) and 0 < starts_in.seconds <= 86400 %}
<ha-alert alert-type="warning">Load Shedding starts in {{ starts_in.seconds // 3600 }}h{{ (starts_in.seconds // 60) - (starts_in.seconds // 3600 * 60) }}m ({{ as_timestamp(start_time) | timestamp_custom("%H:%M", True) }})</ha-alert>
{% endif %}
{% else %}
{% set ends_in = timedelta(minutes=state_attr(area_sensor, "ends_in")) %}
{% if is_state_attr(stage_sensor, "stage", 0) or ends_in.seconds > 86400 %}
<ha-alert alert-type="success">{{ states(stage_sensor) }}</ha-alert>
{% elif not is_state_attr(stage_sensor, "stage", 0) and 0 < ends_in.seconds <= 86400 %}
<ha-alert alert-type="error">Load Shedding ends in {{ ends_in.seconds // 3600 }}h{{ (ends_in.seconds // 60) - (ends_in.seconds // 3600 * 60) }}m ({{ as_timestamp(end_time) | timestamp_custom("%H:%M", True) }})</ha-alert>
{% endif %}
{% endif %}
{% endif %}
{% set area_forecast = state_attr(area_sensor, "forecast" )%}
{% if area_forecast %}
<table width="100%" border=0>
<tbody>
<tr>
<td width="34px"><ha-icon icon="mdi:calendar"></ha-icon></td>
<td align="left" colspan=3>Forecast : : {{ state_attr(area_sensor, "friendly_name") }}</td>
</tr>
{% for forecast in area_forecast[:3] %}
<tr>
<td></td>
<td align="left">
{{ as_timestamp(forecast.start_time) | timestamp_custom("%-d %B", True) }}
</td>
<td align="left">
{{ as_timestamp(forecast.start_time) | timestamp_custom("%H:%M", True) }} - {{ as_timestamp(forecast.end_time) | timestamp_custom("%H:%M", True) }}
</td>
<td align="right">Stage {{ forecast.stage }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% set area_schedule = state_attr(area_sensor, "schedule" )%}
{% if area_schedule %}
<table width="100%" border=0>
<tbody>
<tr>
<td width="34px"><ha-icon icon="mdi:calendar"></ha-icon></td>
<td align="left" colspan=3>Schedule : : {{ state_attr(area_sensor, "friendly_name") }}</td>
</tr>
{% for slot in area_schedule[:3] %}
<tr>
<td></td>
<td align="left">
{{ as_timestamp(slot.start_time) | timestamp_custom("%-d %B", True) }}
</td>
<td align="left">
{{ as_timestamp(slot.start_time) | timestamp_custom("%H:%M", True) }} - {{ as_timestamp(slot.end_time) | timestamp_custom("%H:%M", True) }}
</td>
<td align="right">Stage {{ slot.stage }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}