forked from LocalBytes/esphome-localbytes-plug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
localbytes-plug-pm.yaml
306 lines (278 loc) · 6.46 KB
/
localbytes-plug-pm.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
packages:
minimal: !include minimal.yaml
wifi:
power_save_mode: high
time:
- platform: homeassistant
timezone: Asia/Hong_Kong
web_server:
port: 80
api:
services:
- service: calibrate_voltage
variables:
actual_value: float
then:
- lambda: |-
id(voltage_multiply) = actual_value / id(voltage).raw_state;
- number.set:
id: voltage_factor
value: !lambda "return id(voltage_multiply);"
- service: calibrate_power
variables:
actual_value: float
then:
- lambda: |-
id(power_multiply) = actual_value / id(power).raw_state;
- number.set:
id: power_factor
value: !lambda "return id(power_multiply);"
- service: calibrate_current
variables:
actual_value: float
then:
- lambda: |-
id(current_multiply) = actual_value / id(current).raw_state;
- number.set:
id: current_factor
value: !lambda "return id(current_multiply);"
globals:
- id: voltage_multiply
type: float
restore_value: true
initial_value: "0.3"
- id: power_multiply
type: float
restore_value: true
initial_value: "0.133"
- id: current_multiply
type: float
restore_value: true
initial_value: "0.805"
binary_sensor:
# Push Button (Toggles Relay When Pressed)
- platform: gpio
pin:
number: GPIO3
mode: INPUT_PULLUP
inverted: true
name: "Button"
on_click:
- max_length: 1s
then:
if:
condition:
switch.is_off: disable_button
then:
switch.toggle: relay
- min_length: 1.5s
max_length: 5s
then:
switch.toggle: disable_led
- min_length: 8s
max_length: 12s
then:
switch.toggle: disable_button
- platform: status
name: "Server Status"
switch:
# Relay (As Switch)
- platform: gpio
name: ""
icon: "mdi:${main_icon}"
pin: GPIO14
id: relay
restore_mode: "${default_state}"
on_turn_on:
if:
condition:
switch.is_off: disable_led
then:
light.turn_on:
id: led
on_turn_off:
- light.turn_off:
id: led
- platform: template
name: "Disable LED"
id: disable_led
icon: "mdi:led-variant-off"
restore_mode: "${default_state}"
optimistic: true
on_turn_on:
#Flash twice
- light.turn_off: led
- delay: 0.1s
- light.turn_on: led
- delay: 0.1s
- light.turn_off: led
- delay: 0.1s
- light.turn_on: led
- delay: 0.1s
#Final state
- light.turn_off: led
on_turn_off:
#Flash twice
- light.turn_on: led
- delay: 0.1s
- light.turn_off: led
- delay: 0.1s
- light.turn_on: led
- delay: 0.1s
- light.turn_off: led
- delay: 0.7s
#Final state
- if:
condition:
switch.is_on: relay
then:
light.turn_on: led
- platform: template
name: "Disable Button"
id: disable_button
icon: "mdi:toggle-switch-off-outline"
restore_mode: "${default_state}"
optimistic: true
on_turn_on:
#Flash thrice
- light.turn_off: led
- delay: 0.15s
- light.turn_on: led
- delay: 0.15s
- light.turn_off: led
- delay: 0.15s
- light.turn_on: led
- delay: 0.15s
- light.turn_off: led
- delay: 0.15s
- light.turn_on: led
- delay: 0.15s
#Final state
- if:
condition:
switch.is_off: relay
then:
light.turn_off: led
on_turn_off:
#Flash thrice
- light.turn_on: led
- delay: 0.15s
- light.turn_off: led
- delay: 0.15s
- light.turn_on: led
- delay: 0.15s
- light.turn_off: led
- delay: 0.15s
- light.turn_on: led
- delay: 0.15s
- light.turn_off: led
- delay: 0.7s
#Final state
- if:
condition:
switch.is_on: relay
then:
light.turn_on: led
sensor:
# WiFi Signal Sensor
- platform: wifi_signal
name: "WiFi Status"
update_interval: 60s
# Power Monitoring
- platform: hlw8012
id: power_monitor
sel_pin:
number: GPIO12
inverted: true
cf_pin: GPIO4
cf1_pin: GPIO5
update_interval: 5s
voltage:
name: "Voltage"
id: voltage
unit_of_measurement: V
accuracy_decimals: 1
filters:
- lambda: return x * id(voltage_multiply);
power:
name: "Power"
id: power
unit_of_measurement: W
accuracy_decimals: 1
filters:
- lambda: return x * id(power_multiply);
current:
name: "Current"
id: current
unit_of_measurement: A
accuracy_decimals: 3
filters:
- lambda: return x * id(current_multiply);
# Total daily energy sensor
- platform: total_daily_energy
name: "Daily Energy"
power_id: power
filters:
# Multiplication factor from W to kW is 0.001
- multiply: 0.001
unit_of_measurement: kWh
# Make calibration factor data readable/setable from home assistant
number:
- platform: template
name: "Voltage Calibration Factor"
id: voltage_factor
icon: "mdi:sine-wave"
min_value: 0
max_value: 10
step: 0.001
entity_category: diagnostic
mode: box
lambda: |-
return id(voltage_multiply);
set_action:
lambda: |-
id(voltage_multiply) = x;
- platform: template
name: "Power Calibration Factor"
id: power_factor
icon: "mdi:flash"
min_value: 0
max_value: 10
step: 0.001
entity_category: diagnostic
mode: box
lambda: |-
return id(power_multiply);
set_action:
lambda: |-
id(power_multiply) = x;
- platform: template
name: "Current Calibration Factor"
id: current_factor
icon: "mdi:current-ac"
min_value: 0
max_value: 10
step: 0.001
entity_category: diagnostic
mode: box
lambda: |-
return id(current_multiply);
set_action:
lambda: |-
id(current_multiply) = x;
# Relay State LED
output:
- platform: esp8266_pwm
id: state_led
pin:
number: GPIO13
inverted: true
light:
- platform: binary
output: state_led
id: led
button:
- platform: restart
name: "Restart"
- platform: factory_reset
name: "Restart with Factory Default Settings"