blob: b1922d5813ba83df2d8a53f2c3dd3ae56dbfa555 (
plain)
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
|
# https://esphome.io/guides/configuration-types.html#substitutions
substitutions:
name: kauf-plug # **** CHANGE DEVICE NAME TO SOMETHING UNIQUE PER DEVICE. RENAME YAML FILE TO SAME NAME. ****
# **** USE DASHES (-) INSTEAD OF SPACES OR UNDERSCORE (_). USE ONLY LOWER CASE LETTERS. ****
friendly_name: Kauf Plug # **** CHANGE FRIENDLY NAME TO SOMETHING UNIQUE PER DEVICE ****
# substitutions for power monitoring calibration. Allows end users to change calibration in their yaml and still
# incorporate this file as a package to get all the updates we release.
current_resistor_val: "0.001"
voltage_divider_val: "2401"
sub_hlw_model: HLW8012
power_cal_val1_in: "0.0"
power_cal_val1_out: "0.0"
power_cal_val2_in: "333.8"
power_cal_val2_out: "60"
current_cal_val1_in: "0.0"
current_cal_val1_out: "0.0"
current_cal_val2_in: "0.6"
current_cal_val2_out: "0.515"
voltage_cal_val1_in: "0.0"
voltage_cal_val1_out: "0.0"
voltage_cal_val2_in: "302.1"
voltage_cal_val2_out: "117.1"
# set power monitoring mode in yaml, selecting the "yaml_configured" option in the select entity will cause these
# values to be used after next reboot.
# https://esphome.io/components/sensor/hlw8012.html#configuration-variables
sub_change_mode_every: "1"
sub_update_interval: 10s
sub_initial_mode: CURRENT
# GPIO definitions
sub_pm_sel_pin: GPIO12
sub_pm_cf_pin: GPIO5
sub_pm_cf1_pin: GPIO14
sub_button_pin: GPIO13
sub_blue_led_pin: GPIO2
sub_red_led_pin: GPIO0
sub_relay_pin: GPIO4
# https://esphome.io/components/esphome.html
esphome:
name: $name
# https://esphome.io/components/esphome.html#esphome-creators-project
project:
name: "Kauf.PLF10"
version: "2.073(m)"
min_version: 2024.11.0
# https://esphome.io/components/esp8266.html
esp8266:
board: esp01_1m
restore_from_flash: true
early_pin_init: false
# https://esphome.io/components/wifi.html
wifi:
# **** ENTER WI-FI CREDENTIALS HERE, USING SECRETS.YAML RECOMMENDED ****
ssid: initial_ap # !secret my_wifi_ssid
password: asdfasdfasdfasdf # !secret my_wifi_pass
# default is 20, 17 is recommended.
output_power: 17
ap:
captive_portal: # https://esphome.io/components/captive_portal.html
web_server: # https://esphome.io/components/web_server.html
logger: # https://esphome.io/components/logger.html
api: # https://esphome.io/components/api.html
ota: # https://esphome.io/components/ota.html
platform: esphome
safe_mode:
# https://esphome.io/components/status_led.html
# red led, blink when not connected to wifi or Home Assistant
status_led:
pin:
number: GPIO0
inverted: true
# https://esphome.io/components/binary_sensor/index.html
binary_sensor:
# button input toggles relay and thereby blue led
# https://esphome.io/components/binary_sensor/gpio.html
- platform: gpio
id: button_in
name: $friendly_name Button
pin:
number: GPIO13
mode:
input: true
pullup: true
inverted: true
filters:
- delayed_on: 100ms
on_press:
then:
switch.toggle: relay
# https://esphome.io/components/switch/index.html
# https://esphome.io/components/switch/gpio.html
switch:
# blue LED follows relay power state
- platform: gpio
id: blue_led
pin:
number: GPIO2
inverted: true
restore_mode: RESTORE_DEFAULT_ON
# relay output
- platform: gpio
id: relay
name: $friendly_name
pin: GPIO4
restore_mode: RESTORE_DEFAULT_ON
# automatically make blue led equal relay state
on_turn_on:
- switch.turn_on: blue_led
on_turn_off:
- switch.turn_off: blue_led
# clock input from Home Assistant used to calculate total daily energy
# https://esphome.io/components/time.html#home-assistant-time-source
time:
- platform: homeassistant
id: homeassistant_time
# https://esphome.io/components/sensor/index.html
sensor: # Power monitoring sensors output to Home Assistant
# https://esphome.io/components/sensor/hlw8012.html
- platform: hlw8012
id: hlw_main
sel_pin:
number: $sub_pm_sel_pin
inverted: True
cf_pin: $sub_pm_cf_pin
cf1_pin: $sub_pm_cf1_pin
current_resistor: $current_resistor_val
voltage_divider: $voltage_divider_val
change_mode_every: $sub_change_mode_every
update_interval: $sub_update_interval
initial_mode: $sub_initial_mode
model: $sub_hlw_model
power:
name: ${friendly_name} Power
unit_of_measurement: W
id: wattage
filters:
- calibrate_linear:
- $power_cal_val1_in -> $power_cal_val1_out
- $power_cal_val2_in -> $power_cal_val2_out
current:
name: ${friendly_name} Current
unit_of_measurement: A
id: current
filters:
- calibrate_linear:
- $current_cal_val1_in -> $current_cal_val1_out
- $current_cal_val2_in -> $current_cal_val2_out
voltage:
name: ${friendly_name} Voltage
unit_of_measurement: V
id: voltage
filters:
- calibrate_linear:
- $voltage_cal_val1_in -> $voltage_cal_val1_out
- $voltage_cal_val2_in -> $voltage_cal_val2_out
# Reports the total Power so-far each day, resets at midnight
# https://esphome.io/components/sensor/total_daily_energy.html
- platform: total_daily_energy
name: ${friendly_name} Total Daily Energy
power_id: wattage
filters:
- multiply: 0.001 ## convert Wh to kWh
unit_of_measurement: kWh
|