-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharlecplug.yaml
145 lines (123 loc) · 4.09 KB
/
arlecplug.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
substitutions:
device_name: "smartplug1"
name: "SmartPlug1"
esphome:
name: ${device_name}
bk72xx:
board: wb2s
framework:
version: dev
# Enable Home Assistant API
api:
encryption:
key: !secret hass_key
ota:
platform: esphome
password: !secret hass_password
web_server:
port: 80
auth:
username: !secret web_server_user
password: !secret web_server_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot in case wifi connection fails
ap:
ssid: ${device_name}
password: !secret wifi_password
captive_portal:
logger:
binary_sensor: # the button
- platform: gpio
pin: P11
name: ${device_name} button
id: button
device_class: window
# when button is pressed, toggle the switch on/off
on_press:
then:
- switch.toggle: relay
switch: # the relay
- platform: gpio
pin: P6
name: ${name}
id: relay
restore_mode: always off # default when power is turned on
icon: mdi:power-socket-au
# synchronise the LED with the relay
on_turn_on:
then:
- output.turn_on: button_led
on_turn_off:
then:
- output.turn_off: button_led
output: # the light in the button
- platform: gpio
id: button_led
pin: P26
# restore_mode: always off # default when power is turned on
#
# PC191HA sensors - power monitoring and wifi signal
#
sensor:
- platform: wifi_signal # report wi-fi signal strength from this end
name: $name WiFi Signal
id: ${device_name}_wifi_signal
update_interval: 30s # how often to report wifi signal strength
# PC191HA includes a BL0937 chip for measuring power consumption
# and BL0937 is a variation of hlw8012, but using inverted SEL pin functionality
- platform: hlw8012
model: BL0937 # note that the model must be specified to use special calculation parameters
sel_pin: # I believe that cf_pin reports either Voltage or Current depending on this select pin
inverted: true # determine whether true reports Voltage
number: P24
cf_pin: # current or voltage (ele_pin: 7)
inverted: true # the logic of BL0937 is opposite from HLW8012
number: P7
cf1_pin: # Power (vi_pin: 8)
inverted: true # the logic of BL0937 is opposite from HLW8012
number: P8
update_interval: 15s # How often to measure and report values
# PC191HA measures and returns Voltage OR Current according to the value of sel_pin,
# but it can change the value of sel_pin periodically
initial_mode: "VOLTAGE" # reports VOLTAGE or CURRENT
change_mode_every: 4 # how many times to report before swapping between
# reporting Voltage or Current. Note that the first value reported should be ignored as inaccurate
# Adjust according to the actual resistor values on board to calibrate the specific unit
voltage_divider: 775 # LOWER VALUE GIVES LOWER VOLTAGE
current_resistor: 0.0009 # HIGHER VALUE GIVES LOWER WATTAGE
#
# how the power monitoring values are returned to ESPHome
#
voltage:
name: $name Voltage
id: ${device_name}_voltage
unit_of_measurement: V
accuracy_decimals: 1
filters:
- skip_initial: 2
power:
name: $name Power
id: ${device_name}_power
unit_of_measurement: W
accuracy_decimals: 2
filters:
- skip_initial: 2
# power should simply be current x voltage -- except that the pc191ha doesn't follow that formula.
# Setting current_resistor to give an accurate Amperage does NOT also give the correct Wattage
# so here I calculate current from power and voltage
- platform: template
name: $name Current
id: ${device_name}_current
unit_of_measurement: A
accuracy_decimals: 2
update_interval: "30s"
lambda: |-
return (id(${device_name}_power).state / id(${device_name}_voltage).state);
filters:
- skip_initial: 2
- platform: uptime
name: $name Uptime
id: ${device_name}_uptime
update_interval: "30s"