-
Notifications
You must be signed in to change notification settings - Fork 0
/
hackem-powermeter.yaml
191 lines (176 loc) · 3.97 KB
/
hackem-powermeter.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
bk72xx:
board: cbu
framework:
version: latest
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "Power Meter Fallback Hotspot"
password: !secret wifi_fallback_password
esphome:
name: hackem-powermeter
friendly_name: "Hackem Power Meter"
api:
encryption:
key: !secret doorlock_apikey
ota:
password: !secret ota_pass
status_led:
pin:
number: P15
inverted: true
uart:
baud_rate: 4800
rx_pin: RX1
tx_pin: TX1
stop_bits: 1
id: uart_bus
logger:
baud_rate: 0
button:
- platform: restart
name: Restart
- platform: template
name: "Cut off the power"
on_press:
- switch.turn_off: switch_relay
sensor:
- platform: template
id: apparent
name: Apparent power
device_class: "power"
state_class: "measurement"
unit_of_measurement: "VA"
accuracy_decimals: 1
- platform: template
id: reactive
name: Reactive power
device_class: "power"
state_class: "measurement"
unit_of_measurement: "VAR"
accuracy_decimals: 1
- platform: template
id: pf
name: Power factor
device_class: "power"
state_class: "measurement"
accuracy_decimals: 2
- platform: bl0942
uart_id: uart_bus
voltage:
name: 'BL0942 Voltage'
id: voltage
current:
name: 'BL0942 Current'
id: current
power:
name: 'BL0942 Power'
id: active
filters:
multiply: -1
on_value:
- sensor.template.publish:
id: apparent
state: !lambda 'return id(voltage).state * id(current).state;'
- sensor.template.publish:
id: reactive
state: !lambda 'return sqrt(pow(id(apparent).state, 2) - pow(id(active).state, 2));'
- sensor.template.publish:
id: pf
state: !lambda 'return id(active).state / id(apparent).state;'
energy:
name: 'BL0942 Energy'
accuracy_decimals: 2
frequency:
name: "BL0942 Frequency"
accuracy_decimals: 2
update_interval: 5s
time:
- platform: homeassistant
binary_sensor:
- platform: gpio
pin:
number: P17
inverted: true
mode:
input: true
pullup: true
name: Button
filters:
- delayed_on: 10ms
internal: true
on_click:
- min_length: 1000ms
max_length: 5000ms
then:
- switch.toggle: switch_relay
- min_length: 50ms
max_length: 1000ms
then:
- homeassistant.event:
event: esphome.button_pressed
data:
message: Power Meter Button Clicked
output:
- platform: gpio
pin:
number: P24
id: 'relay_on'
- platform: gpio
pin:
number: P26
id: 'relay_off'
- platform: gpio
pin:
number: P9
inverted: true
id: 'led'
- platform: template
id: bridge_relay
type: binary
write_action:
- if:
condition:
lambda: return (state == 1);
then:
- output.turn_on: led
- output.turn_off: relay_off
- output.turn_on: relay_on
- delay: 80ms
- output.turn_off: relay_on
- light.turn_on:
id: btn_led
effect: "None"
else:
- light.turn_off:
id: btn_led
- output.turn_off: relay_on
- output.turn_on: relay_off
- delay: 80ms
- output.turn_off: relay_off
- light.turn_off: btn_led
- light.turn_on:
id: btn_led
effect: "Blink"
switch:
- platform: output
id: switch_relay
name: "Switch"
output: 'bridge_relay'
restore_mode: RESTORE_DEFAULT_ON
disabled_by_default: true
light:
- platform: binary
name: "Button LED"
id: btn_led
output: led
internal: true
effects:
- strobe:
name: Blink
colors:
- state: true
duration: 200ms
- state: false
duration: 200ms