-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathathom-smart-plug-v3.yaml
216 lines (201 loc) · 4.89 KB
/
athom-smart-plug-v3.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
---
substitutions:
name: "athom-smart-plug-v3"
friendly_name: "Athom Smart Plug V3"
comment: "Athom ESP32-C3 Smart Plug"
# Time between sensor updates
update_interval: "10s"
# Current Limit in amps
current_limit: "10"
# Icon to show in Home Assistant
switch_icon: "mdi:power-socket-au"
# Underlying restore mode for the switch
switch_restore_mode: "RESTORE_DEFAULT_OFF"
packages:
base: !include modules/base.yaml
esphome:
min_version: 2024.6.0
project:
name: "Athom Technology.Smart Plug V3"
version: "v1.1.1-scsole"
platformio_options:
board_build.mcu: esp32c3
board_build.variant: esp32c3
board_build.flash_mode: dio
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;
}
}
esp32:
board: esp32-c3-devkitm-1
flash_size: 4MB
variant: ESP32C3
framework:
type: arduino
dashboard_import:
package_import_url: github://scsole/esphome-device-configs/athom-smart-plug-v3.yaml
import_full_config: false
globals:
- id: restore_mode
type: int
restore_value: yes
initial_value: "3" # 1 = Always_Off, 2 = Always_On, 3 = Restore_State
select:
- platform: template
name: "Power On State"
id: power_mode
optimistic: true
icon: mdi:electric-switch
options:
- Always Off
- Always On
- Restore State
on_value:
then:
- lambda: |-
id(restore_mode) = i + 1;
entity_category: config
binary_sensor:
- platform: gpio
pin:
number: GPIO3
mode: INPUT_PULLUP
inverted: true
name: Button
disabled_by_default: true
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at least 0.1s
then:
- switch.toggle: relay
- timing:
- ON for at least 4s
then:
- button.press: factory_reset_button
- platform: template
name: "Overcurrent"
id: overcurrent
device_class: problem
entity_category: diagnostic
publish_initial_state: true
uart:
rx_pin: GPIO20
baud_rate: 4800
parity: EVEN
sensor:
- platform: cse7766
voltage:
name: "Voltage"
filters:
- throttle_average: ${update_interval}
disabled_by_default: true
current:
name: "Current"
filters:
- throttle_average: ${update_interval}
on_value_range:
- above: ${current_limit}
then:
- switch.turn_off: relay
- binary_sensor.template.publish:
id: overcurrent
state: true
disabled_by_default: true
power:
name: "Power"
id: power_sensor
filters:
- throttle_average: ${update_interval}
energy:
name: "Energy"
unit_of_measurement: kWh
filters:
- throttle: ${update_interval}
# Multiplication factor from W to kW is 0.001
- multiply: 0.001
disabled_by_default: true
apparent_power:
name: "Apparent Power"
filters:
- throttle_average: ${update_interval}
disabled_by_default: true
reactive_power:
name: "Reactive Power"
filters:
- throttle_average: ${update_interval}
disabled_by_default: true
power_factor:
name: "Power Factor"
filters:
- throttle_average: ${update_interval}
disabled_by_default: true
- platform: total_daily_energy
name: "Total Daily Energy"
power_id: power_sensor
unit_of_measurement: kWh
device_class: energy
accuracy_decimals: 3
filters:
# Multiplication factor from W to kW is 0.001
- multiply: 0.001
- platform: integration
name: "Total Energy"
id: total_energy
sensor: power_sensor
time_unit: h
integration_method: right
restore: true
state_class: total_increasing
unit_of_measurement: kWh
device_class: energy
accuracy_decimals: 3
filters:
# Multiplication factor from W to kW is 0.001
- multiply: 0.001
switch:
- platform: gpio
name: Switch
pin: GPIO5
id: relay
restore_mode: ${switch_restore_mode}
icon: ${switch_icon}
on_turn_on:
- binary_sensor.template.publish:
id: overcurrent
state: false
button:
- platform: template
name: Reset Total Energy
on_press:
- sensor.integration.reset: total_energy
entity_category: config
light:
- platform: status_led
name: Status LED
pin:
number: GPIO6
inverted: true
entity_category: config
disabled_by_default: true