-
Notifications
You must be signed in to change notification settings - Fork 0
/
powersensor.yaml
152 lines (147 loc) · 5.5 KB
/
powersensor.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
---
blueprint:
name: AWTRIX Power Sensor
description: >
This blueprint will show the current power consumption.
It uses a icons 630 (solar-green), 630 (solar-white-dyn), 630 (solar-static) that you need to install.
domain: automation
input:
awtrix:
name: AWTRIX Device
description: Select the Awtrix light device
selector:
device:
integration: mqtt
manufacturer: Blueforcer
model: AWTRIX 3
multiple: true
power_source:
name: Power Sensor
description: A sensor providing the current power received from your solar system.
selector:
entity:
domain:
- sensor
multiple: false
threshold_high:
name: Threshold for high solar production (W)
description: The threshold above which the energy production of your solar system should be visualized as high. Input in Watts (W).
selector:
number:
min: 0
max: 100000
unit_of_measurement: Watt
mode: slider
default: 400
threshold_low:
name: Threshold for low solar production (W)
description: The threshold below which the energy production of your solar system should be visualized as low. Input in Watts (W).
selector:
number:
min: 0
max: 100000
unit_of_measurement: Watt
mode: slider
default: 100
skip_if_zero_watts:
name: Hide solar production if at 0 Watts
description: 'This will not show the solar energy production on your awtrix if the production is below 0 Watts.'
selector:
boolean:
default: false
skip_during_night_hours:
name: Hide solar production during night time
description: 'This will not show the solar energy production on your awtrix during night hours (as specified below).'
selector:
boolean:
default: false
night_starts_after_time:
name: Night Time Start
description: Set the start of the night time.
default: 00:00:00
selector:
time: {}
night_ends_after_time:
name: Night Time End
description: Set the end of the night time.
default: 00:00:00
selector:
time: {}
mode: single
variables:
device_ids: !input awtrix
devices_topics: >-
{%- macro get_device_topic(device_id) %}
{{ states((device_entities(device_id) | select('search','device_topic') | list)[0]) }}
{%- endmacro %}
{%- set ns = namespace(devices=[]) %}
{%- for device_id in device_ids %}
{%- set device=get_device_topic(device_id)|replace(' ','') %}
{% set ns.devices = ns.devices + [ device ~ '/custom/solar_power'] %}
{%- endfor %}
{{ ns.devices }}
power_sensor: !input power_source
power_level: >-
{{ states[power_sensor].state | int(0) | abs }}
threshold_low: !input threshold_low
threshold_high: !input threshold_high
power_level_icon: >-
{%- if power_level > threshold_high %}{{630}}{%- endif %}
{%- if (power_level <= threshold_high) and (power_level > threshold_low) %}{{630}}{%- endif %}
{%- if power_level <= threshold_low %}{{630}}{%- endif %}
power_level_color: >-
{%- if power_level > threshold_high %}{{"#04FE04"}}{%- endif %}
{%- if (power_level <= threshold_high) and (power_level > threshold_low) %}{{"#FCFEFC"}}{%- endif %}
{%- if power_level <= threshold_low %}{{"#FF4E1A"}}{%- endif %}
power_level_text: >-
{%- if power_level > 1000 %}{{ ((power_level | float(default=0)) / 1000) | round(1)}} kW{%- else %}{{power_level | round(0)}} W{%- endif %}
skip_if_zero_watts: !input skip_if_zero_watts
skip_during_night_hours: !input skip_during_night_hours
payload: >-
{"icon":"{{ power_level_icon }}", "text": "{{ power_level_text }}", "color": "{{ power_level_color }}"}
night_start: !input night_starts_after_time
night_end: !input night_ends_after_time
trigger:
- platform: time_pattern
minutes: "/1"
condition:
action:
- choose:
- alias: "Skipping"
conditions:
- condition: template
value_template: >
{% set now_time = now().strftime("%H:%M") %}
{% set night_start = night_start %}
{% set night_end = night_end %}
{{ (skip_during_night_hours and ((now_time < night_end) or (now_time > night_start))) or (skip_if_zero_watts and (power_level == 0)) }}
sequence:
# It is night time, skipping sending solar power data to Awtrix Light.
- repeat:
for_each: "{{ devices_topics }}"
sequence:
- service: mqtt.publish
data:
qos: 0
retain: false
topic: "{{ repeat.item }}"
payload: '{}'
- alias: "Not skipping"
conditions:
- condition: template
value_template: >
{% set now_time = now().strftime("%H:%M") %}
{% set night_start = night_start %}
{% set night_end = night_end %}
{{ not((skip_during_night_hours and ((now_time < night_end) or (now_time > night_start))) or (skip_if_zero_watts and (power_level == 0))) }}
sequence:
- repeat:
for_each: "{{ devices_topics }}"
sequence:
- service: mqtt.publish
data:
qos: 0
retain: false
topic: "{{ repeat.item }}"
payload: >
{{ payload }}