-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshunt (1).yaml
328 lines (276 loc) · 7.63 KB
/
shunt (1).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
esphome:
name: shunt
friendly_name: shunt
esp32:
board: esp32-c3-devkitm-1
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "x"
ota:
- platform: esphome
password: "x"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Shunt Fallback Hotspot"
password: "x"
captive_portal:
i2c:
sda: GPIO8
scl: GPIO9
scan: true
id: bus_a
frequency: 400kHz
sensor:
- platform: ina219
address: 0x40
# shunt_resistance: 0.1 ohm
shunt_resistance: 0.0015 ohm
current:
name: "INA219 Current"
id: current
on_value_range:
- below: -0.05
then:
- sensor.duty_time.reset: charging_time
power:
name: "INA219 Power"
bus_voltage:
name: "INA219 Bus Voltage"
id: voltage
shunt_voltage:
name: "INA219 Shunt Voltage"
max_voltage: 32.0V
# max_current: 3.2A
max_current: 50A
update_interval: 2s
- platform: template
name: "Wattage calculated"
id: wattage_calculated
unit_of_measurement: "W"
device_class: "power"
state_class: "measurement"
lambda: |-
if (float (id(current).state) > 0) {
return (float (id(voltage).state) * float (id(current).state)) * (float (id(efficiency).state) / 100 );
}
else {
return (float (id(voltage).state) * float (id(current).state) );
}
accuracy_decimals: 2
update_interval: 2s
# wattage smoothed out
- platform: template
name: "Wattage calculated avg"
id: wattage_calculated_avg
unit_of_measurement: "W"
device_class: "power"
state_class: "measurement"
lambda: |-
if (float (id(amp_average).state) > 0) {
return (float (id(voltage).state) * float (id(amp_average).state)) * (float (id(efficiency).state) / 100 );
}
else {
return (float (id(voltage).state) * float (id(amp_average).state) );
}
accuracy_decimals: 2
update_interval: 2s
# current smoothed out
- platform: template
name: "Amp average"
id: amp_average
unit_of_measurement: "A"
device_class: "current"
state_class: "measurement"
filters:
- sliding_window_moving_average:
window_size: 30
send_every: 2
lambda: |-
return float (id(current).state) ;
accuracy_decimals: 2
update_interval: 2s
- platform: template
name: "SOC percentage"
id: soc_percentage
unit_of_measurement: "%"
state_class: "measurement"
lambda: |-
return float ((id(battery_soc).state) / float (id(max_cap).state)) * 100;
accuracy_decimals: 2
update_interval: 2s
#time to full discharge
- platform: template
name: "time to discharge"
id: time_to_discharge
unit_of_measurement: "s"
device_class: "duration"
update_interval: 2s
filters:
- sliding_window_moving_average:
window_size: 5
send_every: 5
lambda: |-
if (float (id(current).state) > 0) {
return 0;
} else {
return float ((id(battery_soc).state) / abs(float (id(wattage_calculated_avg).state))) * 60 * 60;
}
#time to full charge
- platform: template
name: "time to charge"
id: time_to_charge
unit_of_measurement: "s"
device_class: "duration"
update_interval: 5s
filters:
- sliding_window_moving_average:
window_size: 15
send_every: 2
lambda: |-
if (float (id(current).state) < 0) {
return 0;
} else {
return float (((id(max_cap).state) - (id(battery_soc).state)) / abs(float (id(wattage_calculated).state))) * 60 * 60;
}
# state of charge in available Wh with hardcoded max value here 640
- platform: integration
name: "Battery SOC"
id: battery_soc
sensor: wattage_calculated
integration_method: "left"
time_unit: h
restore: true
device_class: energy
filters:
- clamp:
max_value: 640
ignore_out_of_range: false
- platform: template
name: "Tailing charge average"
unit_of_measurement: "A"
id: tailpower
state_class: "measurement"
update_interval: 2s
device_class: "current"
accuracy_decimals: 2
lambda: |-
return float (id(current).state);
# filters:
# - median:
# window_size: 60
# send_every: 1
filters:
- sliding_window_moving_average:
window_size: 60
send_every: 1
- platform: template
name: "Low voltage"
unit_of_measurement: "V"
id: lowvoltage
state_class: "measurement"
update_interval: 2s
device_class: "voltage"
accuracy_decimals: 2
lambda: |-
return float (id(voltage).state);
filters:
- median:
window_size: 5
send_every: 1
# on_value_range:
# - below: !lambda 'return id(lowreset).state;'
# then:
# - sensor.integration.reset: battery_soc
# reset SOC naar 0 als de batterij spanning laag is. Kan beter in HA gebeuren
- platform: duty_time
id: charging_time
name: Charging Time
sensor: battery_charging
update_interval: 2s
button:
- platform: template
name: Battery SOC Reset
on_press:
then:
- sensor.integration.reset: battery_soc
# - platform: template
# name: Battery SOC to max
# on_press:
# then:
# - lambda: |-
# id(battery_soc).publish_state(640);
number:
- platform: template
name: Battery capacity
id: max_cap
unit_of_measurement: "Wh"
mode: "box"
max_value: 1500
min_value: 0
step: 0.2
optimistic: true
restore_value: True
- platform: template
name: Charge efficiency factor
id: efficiency
unit_of_measurement: "%"
mode: "box"
max_value: 100
min_value: 80
step: 1
optimistic: true
restore_value: True
- platform: template
name: Low voltage reset
id: lowreset
unit_of_measurement: "V"
mode: "box"
max_value: 12
min_value: 9
step: 0.1
optimistic: true
restore_value: True
binary_sensor:
- platform: template
name: "Battery is Charging"
id: battery_charging
lambda: |-
if (id(current).state > 0.05) {
return true;
} else {
return false;
}
font:
- file: 'fonts/Tahoma.ttf'
id: font1
size: 16
glyphs:
['&', '@', '!', ',', '.', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0',
'1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z','å', 'ä', 'ö', '/','º','µ','³','€']
display:
- platform: ssd1306_i2c
model: "SSD1306 128x64"
address: 0x3C
id: my_display
update_interval: 0.5s
rotation: 180
lambda: |-
// it.printf(0, 0, id(font1), "irr %.0fW/m2", id(irradiance).state);
it.printf(0, 0, id(font1), TextAlign::TOP_LEFT, "%2.1fv", id(voltage).state);
it.printf(60, 0, id(font1), TextAlign::TOP_CENTER, "%2.1fi", id(current).state);
it.printf(128, 0, id(font1), TextAlign::TOP_RIGHT, "%2.1fp", id(wattage_calculated).state);
it.printf(0, 17, id(font1), TextAlign::TOP_LEFT, "SoC %2.1f %%", id(soc_percentage).state);
it.printf(70, 17, id(font1), TextAlign::TOP_LEFT, "%", id(soc_percentage).state);
it.printf(0, 34, id(font1), "Stored %2.1f Wh", id(battery_soc).state);