forked from jesserockz/athom-configs
-
Notifications
You must be signed in to change notification settings - Fork 8
/
athom-smart-plug.yaml
412 lines (368 loc) · 11.4 KB
/
athom-smart-plug.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
substitutions:
name: "athom-smart-plug"
friendly_name: "Smart Plug"
# Allows ESP device to be automatically lined to an 'Area' in Home Assistant. Typically used for areas such as 'Lounge Room', 'Kitchen' etc
room: ""
device_description: "athom smart plug"
project_name: "Athom Technology.Smart Plug"
project_version: "v1.0.2"
relay_restore_mode: RESTORE_DEFAULT_OFF
sensor_update_interval: 10s
# Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16.
current_limit : "10"
# Define a domain for this device to use. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs)
dns_domain: ""
# Set timezone of the smart plug. Useful if the plug is in a location different to the HA server. Can be entered in unix Country/Area format (i.e. "Australia/Sydney")
timezone: ""
# Set the duration between the sntp service polling ntp.org servers for an update
sntp_update_interval: "6h"
# Network time servers for your region, enter from lowest to highest priority. To use local servers update as per zones or countries at: https://www.ntppool.org/zone/@
sntp_server_1: "0.pool.ntp.org"
sntp_server_2: "1.pool.ntp.org"
sntp_server_3: "2.pool.ntp.org"
# Enables faster network connections, with last connected SSID being connected to and no full scan for SSID being undertaken
wifi_fast_connect: "false"
# Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
log_level: "INFO"
# Enable or disable the use of IPv6 networking on the device
ipv6_enable: "false"
# Hide the ENERGY sensor that shows kWh consumed, but with no time period associated with it. Resets when device restarted and reflashed.
hide_energy_sensor: "true"
esphome:
name: "${name}"
friendly_name: "${friendly_name}"
comment: "${device_description}"
area: "${room}"
name_add_mac_suffix: true
min_version: 2024.6.0
project:
name: "${project_name}"
version: "${project_version}"
on_boot:
- priority: 600
then:
- select.set_index:
id: power_mode
index: !lambda |-
return id(restore_mode)-1;
- lambda: |-
switch(id(restore_mode))
{
case 1:{
id(relay).turn_off();
break;
}
case 2:{
id(relay).turn_on();
break;
}
default:{
break;
}
}
esp8266:
board: esp8285
restore_from_flash: true
preferences:
flash_write_interval: 5min
api:
ota:
- platform: esphome
logger:
level: ${log_level}
baud_rate: 0
mdns:
disabled: false
web_server:
port: 80
network:
enable_ipv6: ${ipv6_enable}
wifi:
# This spawns an AP with the device name and mac address with no password.
ap: {}
# Allow rapid re-connection to previously connect WiFi SSID, skipping scan of all SSID
fast_connect: "${wifi_fast_connect}"
# Define dns domain / suffix to add to hostname
domain: "${dns_domain}"
captive_portal:
dashboard_import:
package_import_url: github://athom-tech/athom-configs/athom-smart-plug.yaml
# Dentra Components - Adds 'Platform - Energy Statistics'
# https://github.com/dentra/esphome-components/tree/master/components/energy_statistics
# external_components:
# - source: github://dentra/esphome-components
globals:
- id: total_energy
type: float
restore_value: yes
initial_value: '0.0'
- id: restore_mode
type: int
restore_value: yes
initial_value: "3"
select:
- platform: template
name: "Power On State"
id: "power_mode"
optimistic: true
options:
- Always Off
- Always On
- Restore Power Off State
on_value:
then:
- lambda: |-
id(restore_mode)=i+1;
binary_sensor:
- platform: status
name: "Status"
entity_category: diagnostic
- platform: gpio
pin:
number: 3
mode: INPUT_PULLUP
inverted: true
name: "Power Button"
disabled_by_default: true
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at least 0.2s
then:
- switch.toggle: relay
- timing:
- ON for at least 4s
then:
- button.press: Reset
sensor:
- platform: uptime
name: "Uptime Sensor"
id: uptime_sensor
entity_category: diagnostic
internal: True
# Reports the WiFi signal strength/RSSI in dB
- platform: wifi_signal
name: "WiFi Signal dB"
id: wifi_signal_db
update_interval: 60s
entity_category: diagnostic
# Reports the WiFi signal strength in %
- platform: copy
source_id: wifi_signal_db
name: "WiFi Signal Percent"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: diagnostic
device_class: ""
- platform: hlw8012
sel_pin:
number: GPIO12
inverted: True
cf_pin: GPIO4
cf1_pin: GPIO5
voltage_divider: 780
current:
name: "Current"
id: current
unit_of_measurement: A
accuracy_decimals: 2
filters:
- calibrate_linear:
- 0.0000 -> 0.0110 # Relay off no load
- 0.0097 -> 0.0260 # Relay on no load
- 0.9270 -> 0.7570
- 2.0133 -> 1.6330
- 2.9307 -> 2.3750
- 5.4848 -> 4.4210
- 8.4308 -> 6.8330
- 9.9171 -> 7.9830
# Normalize for plug load
- lambda: if (x < 0.0260) return 0; else return (x - 0.0260);
on_value_range:
- above: ${current_limit}
then:
- switch.turn_off: relay
voltage:
name: "Voltage"
id: voltage
unit_of_measurement: V
accuracy_decimals: 1
filters:
- skip_initial: 2
power:
name: "Power"
id: socket_my_power
unit_of_measurement: W
accuracy_decimals: 1
filters:
- calibrate_linear:
- 0.0000 -> 0.5900 # Relay off no load
- 0.0000 -> 1.5600 # Relay on no load
- 198.5129 -> 87.8300
- 434.2469 -> 189.5000
- 628.6241 -> 273.9000
- 1067.0067 -> 460.1000
- 1619.8098 -> 699.2000
- 2043.0282 -> 885.0000
# Normalize for plug load
- lambda: if (x < 1.5600) return 0; else return (x - 1.5600);
change_mode_every: 1
update_interval: 5s
# Shows the Energy kWh since the device was last started
energy:
name: "Energy"
id: energy
unit_of_measurement: kWh
accuracy_decimals: 3
filters:
# Multiplication factor from W to kW is 0.001
- multiply: 0.001
on_value:
then:
- lambda: |-
static float previous_energy_value = 0.0;
float current_energy_value = id(energy).state;
id(total_energy) += current_energy_value - previous_energy_value;
previous_energy_value = current_energy_value;
id(total_energy_sensor).update();
# internal: ${hide_energy_sensor}
# Shows the TOTAL/Lifetime Energy kWh used by the device, may reset to zero upon firmware updates
- platform: template
name: "Total Energy"
id: total_energy_sensor
unit_of_measurement: kWh
device_class: "energy"
state_class: "total_increasing"
icon: "mdi:lightning-bolt"
accuracy_decimals: 3
lambda: |-
return id(total_energy);
update_interval: ${sensor_update_interval}
- platform: total_daily_energy
name: "Total Energy Since Boot"
power_id: socket_my_power
unit_of_measurement: kWh
accuracy_decimals: 3
restore: true
filters:
- multiply: 0.001
# Dentra Components - Define the id of the sensor providing 'Total Energy' used
# - platform: "energy_statistics"
# total: total_energy_sensor
# # Dentra Components - Adds Energy Today. Persistents if restarted, unlike 'total_daily_energy'
# energy_today:
# name: "Total Energy Today"
# id: total_energy_today
# accuracy_decimals: 3
# icon: mdi:hours-24
# # Dentra Components - Adds Energy Yesterday
# energy_yesterday:
# name: "Total Energy Yesterday"
# id: total_energy_yesterday
# accuracy_decimals: 3
# # Dentra Components - Adds Energy Week
# energy_week:
# name: "Total Energy Week"
# id: total_energy_week
# accuracy_decimals: 3
# # Dentra Components - Adds Energy Month
# energy_month:
# name: "Total Energy Month"
# id: total_energy_month
# accuracy_decimals: 3
button:
- platform: restart
name: "Restart"
entity_category: config
- platform: factory_reset
name: "Reset"
id: Reset
entity_category: config
- platform: safe_mode
name: "Safe Mode"
internal: false
entity_category: config
switch:
- platform: gpio
name: "Plug"
pin: GPIO14
id: relay
restore_mode: ${relay_restore_mode}
on_turn_on:
- light.turn_on: blue_led
on_turn_off:
- light.turn_off: blue_led
light:
- platform: status_led
name: "Status LED"
id: blue_led
disabled_by_default: true
pin:
inverted: true
number: GPIO13
text_sensor:
- platform: wifi_info
ip_address:
name: "IP Address"
entity_category: diagnostic
ssid:
name: "Connected SSID"
entity_category: diagnostic
mac_address:
name: "Mac Address"
entity_category: diagnostic
# Creates a sensor showing when the device was last restarted
- platform: template
name: 'Last Restart'
id: device_last_restart
icon: mdi:clock
entity_category: diagnostic
# device_class: timestamp
# Creates a sensor of the uptime of the device, in formatted days, hours, minutes and seconds
- platform: template
name: "Uptime"
entity_category: diagnostic
lambda: |-
int seconds = (id(uptime_sensor).state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
if ( days > 3650 ) {
return { "Starting up" };
} else if ( days ) {
return { (String(days) +"d " + String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
} else if ( hours ) {
return { (String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
} else if ( minutes ) {
return { (String(minutes) +"m "+ String(seconds) +"s").c_str() };
} else {
return { (String(seconds) +"s").c_str() };
}
icon: mdi:clock-start
time:
- platform: sntp
id: sntp_time
# Define the timezone of the device
timezone: "${timezone}"
# Change sync interval from default 5min to 6 hours (or as set in substitutions)
update_interval: ${sntp_update_interval}
# Set specific sntp servers to use
servers:
- "${sntp_server_1}"
- "${sntp_server_2}"
- "${sntp_server_3}"
# Publish the time the device was last restarted
on_time_sync:
then:
# Update last restart time, but only once.
- if:
condition:
lambda: 'return id(device_last_restart).state == "";'
then:
- text_sensor.template.publish:
id: device_last_restart
state: !lambda 'return id(sntp_time).now().strftime("%a %d %b %Y - %I:%M:%S %p");'