-
Notifications
You must be signed in to change notification settings - Fork 0
/
scale.yaml
400 lines (366 loc) · 10.3 KB
/
scale.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
substitutions:
name: "smarte-scale"
calibration_raw_1: '-122224.1'
calibration_weight_1: '0.0'
calibration_raw_2: '2051382.0'
calibration_weight_2: '101.5'
esphome:
name: ${name}
platform: ESP8266
board: d1_mini
logger:
level: INFO
api:
encryption:
key: !secret key_api
ota:
- platform: esphome
password: !secret key_ota
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: .fritz.box
power_save_mode: NONE
manual_ip:
static_ip: 192.168.178.234
gateway: !secret gateway
subnet: !secret subnet
dns1: !secret dns1
time:
- platform: homeassistant
id: homeassistant_time
globals:
- id: saved_weight
type: float
restore_value: yes
initial_value: '0.0'
- id: calibration_raw_1
type: float
restore_value: yes
initial_value: '${calibration_raw_1}'
- id: calibration_weight_1
type: float
restore_value: yes
initial_value: '${calibration_weight_1}'
- id: calibration_raw_2
type: float
restore_value: yes
initial_value: '${calibration_raw_2}'
- id: calibration_weight_2
type: float
restore_value: yes
initial_value: '${calibration_weight_2}'
- id: tara_offset
type: float
restore_value: yes
initial_value: '0.0'
- id: auto_calibration_active
type: bool
restore_value: no
initial_value: 'false'
- id: calibration_step
type: int
restore_value: no
initial_value: '0'
- id: max_weight
type: float
restore_value: yes
initial_value: '0.0'
- id: last_calibration_time
type: std::string
restore_value: False
sensor:
- platform: hx711
name: "Rohwert HX711"
id: "rohwert_sensor"
dout_pin: GPIO12
clk_pin: GPIO13
update_interval: 0.2s
unit_of_measurement: "Raw"
accuracy_decimals: 0
filters:
- quantile:
window_size: 10
send_every: 1
send_first_at: 1
quantile: .9
on_value:
then:
- globals.set:
id: saved_weight
value: !lambda 'return x;'
- platform: template
name: "Conny's Gewicht"
id: "gewicht_sensor"
unit_of_measurement: "kg"
accuracy_decimals: 2
update_interval: 1s
filters:
- sliding_window_moving_average:
window_size: 5
send_every: 5
lambda: |-
float raw_value = id(saved_weight);
float weight = 0.0;
if (id(calibration_raw_2) != id(calibration_raw_1)) {
weight = (raw_value - id(calibration_raw_1)) *
(id(calibration_weight_2) - id(calibration_weight_1)) /
(id(calibration_raw_2) - id(calibration_raw_1));
}
weight -= id(tara_offset);
if (weight < 0.1) {
weight = 0.0;
}
if (weight > id(max_weight)) {
id(max_weight) = weight;
}
return weight;
- platform: template
name: "Kalibrierungsschritt"
id: calibration_step_sensor
lambda: 'return id(calibration_step);'
- platform: template
name: "Auto-Tara"
update_interval: 5s
lambda: |-
if (!id(binary_sensor_gewicht_stabil).state && id(gewicht_sensor).state < 1.0) {
id(tara_offset) = id(gewicht_sensor).state;
return id(tara_offset);
}
return id(tara_offset);
- platform: template
name: "Gewicht in Pfund"
unit_of_measurement: "lbs"
accuracy_decimals: 2
lambda: 'return id(gewicht_sensor).state * 2.20462;'
- platform: template
name: "Maximales Gewicht"
id: sensor_maximales_gewicht
unit_of_measurement: "kg"
accuracy_decimals: 2
lambda: 'return id(max_weight);'
- platform: template
name: "Durchschnittliches Gewicht"
unit_of_measurement: "kg"
accuracy_decimals: 2
update_interval: 60s
lambda: |-
static float sum = 0;
static int count = 0;
sum += id(gewicht_sensor).state;
count++;
return sum / count;
#- platform: adc
# pin: A0
# name: "Batterie Spannung"
# update_interval: 60s
# attenuation: 3
# filters:
# - multiply: 3.3
# unit_of_measurement: "V"
binary_sensor:
- platform: template
name: "Gewicht stabil"
id: binary_sensor_gewicht_stabil
device_class: moving
lambda: |-
static float last_weight = 0;
static uint32_t stable_start = 0;
float current_weight = id(gewicht_sensor).state;
if (abs(current_weight - last_weight) < 0.1) {
if (stable_start == 0) {
stable_start = millis();
} else if (millis() - stable_start > 3000) {
return false; // nicht in Bewegung
}
} else {
stable_start = 0;
}
last_weight = current_weight;
return true; // in Bewegung
- platform: template
name: "Gewichtsänderung Alarm"
device_class: motion
lambda: |-
static float last_weight = 0;
float current_weight = id(gewicht_sensor).state;
bool significant_change = abs(current_weight - last_weight) > 5.0;
last_weight = current_weight;
return significant_change;
number:
- platform: template
name: "Tara Offset"
id: tara_offset_number
min_value: -100.0
max_value: 100.0
step: 0.01
initial_value: 0.0
optimistic: true
entity_category: config
unit_of_measurement: "kg"
set_action:
then:
- globals.set:
id: tara_offset
value: !lambda 'return x;'
- platform: template
name: "Kalibrierung Raw 1"
id: calibration_raw_1_number
min_value: -2000000.0
max_value: 3000000.0
step: 1
optimistic: true
initial_value: ${calibration_raw_1}
entity_category: config
unit_of_measurement: "Raw"
set_action:
then:
- globals.set:
id: calibration_raw_1
value: !lambda 'return x;'
- platform: template
name: "Kalibrierung Gewicht 1"
id: calibration_weight_1_number
min_value: 0.0
max_value: 200.0
step: 0.01
optimistic: true
initial_value: ${calibration_weight_1}
entity_category: config
unit_of_measurement: "kg"
set_action:
then:
- globals.set:
id: calibration_weight_1
value: !lambda 'return x;'
- platform: template
name: "Kalibrierung Raw 2"
id: calibration_raw_2_number
min_value: -2000000.0
max_value: 3000000.0
step: 1
optimistic: true
initial_value: ${calibration_raw_2}
entity_category: config
unit_of_measurement: "Raw"
set_action:
then:
- globals.set:
id: calibration_raw_2
value: !lambda 'return x;'
- platform: template
name: "Kalibrierung Gewicht 2"
id: calibration_weight_2_number
min_value: 0.0
max_value: 200.0
step: 0.01
optimistic: true
initial_value: ${calibration_weight_2}
entity_category: config
unit_of_measurement: "kg"
set_action:
then:
- globals.set:
id: calibration_weight_2
value: !lambda 'return x;'
button:
- platform: template
name: "Manuel Tara"
on_press:
then:
- globals.set:
id: tara_offset
value: !lambda 'return id(gewicht_sensor).state;'
- number.set:
id: tara_offset_number
value: !lambda 'return id(gewicht_sensor).state;'
- platform: template
name: "Set Zero"
on_press:
then:
- number.set:
id: calibration_raw_1_number
value: !lambda 'return id(rohwert_sensor).state;'
- platform: template
name: "Set Max"
on_press:
then:
- number.set:
id: calibration_raw_2_number
value: !lambda 'return id(rohwert_sensor).state;'
- platform: template
name: "Start Auto-Kalibrierung"
on_press:
- globals.set:
id: auto_calibration_active
value: 'true'
- globals.set:
id: calibration_step
value: '0'
- logger.log: "Automatische Kalibrierung gestartet. Bitte Waage leeren."
- platform: template
name: "Nächster Kalibrierungsschritt"
on_press:
- lambda: |-
if (id(auto_calibration_active)) {
id(calibration_step)++;
if (id(calibration_step) == 1) {
id(calibration_raw_1) = id(rohwert_sensor).state;
id(calibration_weight_1) = 0.0;
ESP_LOGD("Auto-Kalibrierung", "Nullpunkt gesetzt. Bitte 10kg Gewicht auflegen.");
} else if (id(calibration_step) == 2) {
id(calibration_raw_2) = id(rohwert_sensor).state;
id(calibration_weight_2) = 10.0;
id(auto_calibration_active) = false;
auto time = id(homeassistant_time).now();
char buffer[64];
snprintf(buffer, sizeof(buffer), "%04d-%02d-%02d %02d:%02d:%02d", time.year, time.month, time.day_of_month, time.hour, time.minute, time.second);
id(last_calibration_time) = std::string(buffer);
ESP_LOGD("Auto-Kalibrierung", "Kalibrierung abgeschlossen.");
}
}
- sensor.template.publish:
id: calibration_step_sensor
state: !lambda 'return id(calibration_step);'
- text_sensor.template.publish:
id: last_calibration_sensor
state: !lambda 'return id(last_calibration_time);'
- platform: template
name: "Reset Maximales Gewicht"
on_press:
- lambda: 'id(max_weight) = 0;'
- sensor.template.publish:
id: sensor_maximales_gewicht
state: 0
switch:
- platform: restart
name: ${name} Reset
text_sensor:
- platform: template
name: "Kalibrierungsstatus"
lambda: !lambda |-
if (id(auto_calibration_active)) {
if (id(calibration_step) == 0) {
return {"Bitte Waage leeren und 'Nächster Schritt' drücken"};
} else if (id(calibration_step) == 1) {
return {"Bitte 10kg Gewicht auflegen und 'Nächster Schritt' drücken"};
}
}
return {"Kalibrierung inaktiv"};
- platform: template
name: "Letzte Kalibrierung"
id: last_calibration_sensor
icon: "mdi:clock-outline"
lambda: 'return id(last_calibration_time);'
- platform: template
name: "Kalibrierung gültig"
lambda: !lambda |-
if (id(calibration_raw_2) != id(calibration_raw_1) && id(calibration_weight_2) != id(calibration_weight_1)) {
return {"Gültig"};
} else {
return {"Ungültig"};
}
status_led:
pin:
number: D4
inverted: true