-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmokemonster.yaml
506 lines (467 loc) · 13.9 KB
/
smokemonster.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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
substitutions:
device_name: smokemonster
device_description: Smoke Monster
friendly_name: smokemonster
puck_interval: 20min
puck_motor_delay: 12s
prime_delay: 14s
ir_dwell: 5.5sec
binary_sensor:
# puck chucker position IR sensor, update template sensor
# This sensor will turn off the puck_chucker_advance motor
# after ${ir_dwell} time. The intention is to park it 180
# degrees from a full extension. We also want to reset any
# binary sensors to a known state and increment the "num_chucks"
# sensor to keep track of how many cycles we've gone through.
# IR beam break sensor array:
# 1 2 3 4
# black red orange black
# gnd ir_beam ir_recv gnd
# 1kOhmR->5v GPIO_4+370OhmR->5v
# documented
- platform: gpio
pin: GPIO4
id: puck_ir
internal: true
on_press:
then:
- delay: ${ir_dwell}
- switch.turn_off: puck_chucker_advance
- sensor.template.publish:
id: num_chucks
state: !lambda 'return (id(num_chucks).state + 1);'
- if:
condition:
switch.is_on: chucker_reset
then:
switch.turn_off: chucker_reset
- if:
condition:
sensor.in_range:
id: num_chucks
above: 3
then:
- binary_sensor.template.publish:
id: chucker_primed
state: ON
# This sensor tells us that 3 pucks are present in the smoke
# generator path. 3 are required to begin the smoke operation.
# documented
- platform: template
id: chucker_primed
name: Chucker Primed
# Reports if this device is Connected or not
# documented
- platform: status
id: statussensor
name: ${friendly_name} Status
output:
# blue - heater - 40A SSR
# This is the main heater element for the smoker box. This
# is controlled by the climate pid controller. In my version
# I have 2 x 500w elements, one of the two can be switched
# off manually... I may decide to make this controllable by
# smokemonster eventually.
# We are using "slow_pwm" here as the climate pid component
# requires a PWM output.
# documented
- platform: slow_pwm
pin: GPIO13
id: heater
period: 3s
switch:
# rotates the Puck Chucker until the IR sensor triggers
# useful to get back in sync...
# documented
- platform: template
id: chucker_reset
name: Puck Chucker Reset
optimistic: on
turn_on_action:
- switch.turn_on: puck_chucker_advance
# activates "puck_chucker_advance" until the binary_sensor
# "chucker_primed" is on (3 pucks in the smoke generator)
# documented
- platform: template
id: chucker_prime
name: Puck Chucker Prime
optimistic: on
turn_on_action:
then:
- while:
condition:
binary_sensor.is_off: chucker_primed
then:
- switch.turn_on: puck_chucker_advance
- delay: ${prime_delay}
- wait_until:
binary_sensor.is_on: chucker_primed
# enables the PID autotune feature
# documented
- platform: template
name: "PID Autotune"
id: pid_autotune
turn_on_action:
- climate.pid.autotune: pid_smoker
# green - puck chucker - 25A SSR
# JUN TUO TY-50B E212993
# 110-120v 4W electric motor
# 5/6 r/min CW/CCW
# documented
- platform: gpio
pin: GPIO16
name: "${friendly_name} Puck Chucker Advance"
id: puck_chucker_advance
restore_mode: ALWAYS_OFF
internal: false
on_turn_on:
then:
# when we turn on, we wait ${puck_motor_delay} and
# check to see if we've already been turned off
# if we haven't, it means the IR sensor has failed,
# we need to stop and raise an error.
# If we were successfully turned off by the IR sensor,
# then we need to check if we had a previous failure,
# and clear it.
- delay: ${puck_motor_delay}
- if:
condition:
switch.is_on: puck_chucker_advance
then:
- switch.turn_off: puck_chucker_advance
- text_sensor.template.publish:
id: puck_chucker_errors
state: "NO_IR"
else:
- if:
condition:
text_sensor.state:
id: puck_chucker_errors
state: "NO_IR"
then:
- text_sensor.template.publish:
id: puck_chucker_errors
state: "OK"
# The smoke generator "program"
# Turn on the heater, make sure we have 3 pucks loaded
# Mother_Chucker is responsible for dispensing a new puck
# every ${puck_interval}.
# documented
- platform: template
name: "Smoke Generator"
id: smoke_generator
optimistic: on
turn_on_action:
- switch.turn_on: smoke_generator_heat
#- switch.turn_on: chucker_prime
#- wait_until:
# binary_sensor.is_on: chucker_primed
#- switch.turn_on: mother_chucker
turn_off_action:
then:
- switch.turn_off: smoke_generator_heat
- switch.turn_off: mother_chucker
# While the smoke_generator is on, this will dispense a new
# puck every ${puck_interval}
# documented
- platform: template
name: Mother Chucker
id: mother_chucker
turn_on_action:
- while:
condition:
switch.is_on: smoke_generator
then:
- delay: ${puck_interval}
- switch.turn_on: puck_chucker_advance
# yellow - smoke generator heater - 40A SSR
# 120v 125W heating element
# reaches roughly 500*F, this causes the puck to burn
# and produce smoke
# documented
- platform: gpio
pin: GPIO17
name: Smoke Generator Heater
id: smoke_generator_heat
restore_mode: ALWAYS_OFF
- platform: restart
name: "${device_description} Restart"
### Switches for Setting and Getting PID Values in Home Assistant ###
### This needs work TODO ###
- platform: template
name: "PID Set"
turn_on_action:
- climate.pid.set_control_parameters:
id: pid_smoker
kp: !lambda
return id(p_coefficient).state;
ki: !lambda
return id(i_coefficient).state;
kd: !lambda
return id(d_coefficient).state;
- platform: template
name: "Get PID Values"
turn_on_action:
- homeassistant.service:
service: input_number.set_value
data:
entity_id: input_number.smoker1_p_coefficient
value: !lambda return id(kp).state;
- homeassistant.service:
service: input_number.set_value
data:
entity_id: input_number.smoker1_i_coefficient
value: !lambda return id(ki).state;
- homeassistant.service:
service: input_number.set_value
data:
entity_id: input_number.smoker1_d_coefficient
value: !lambda return id(kd).state;
### Switch to reset integral term for PID calculation ###
- platform: template
name: "Reset Integral"
turn_on_action:
- climate.pid.reset_integral_term: pid_smoker
sensor:
# keep track of how many puck advance cycles we've had good for
# statistics and also used to know if the smoke generator is
# "primed"
# documented
- platform: template
id: num_chucks
name: Number of Chucks
update_interval: 10s
# "accuracy_decimals: 0" effectively makes it an integer
accuracy_decimals: 0
unit_of_measurement: Count
# we grab the outside temperature from HA to display on the...display
# may use this at some point to pro-actively adjust temperature...
# documented
- platform: homeassistant
id: outside_temperature
entity_id: sensor.home_temp
internal: true
# the main cooking chamber temperature. PT100 Platinum Sensor, good up
# too 550*C. About 4x more than what this chamber will ever see
# documented
- platform: max31865
internal: true
name: "Chamber Temperature"
id: temp1
cs_pin: GPIO5
reference_resistance: 430
rtd_nominal_resistance: 100
rtd_wires: 3
filters:
- exponential_moving_average:
alpha: 0.09
# this being set to 60 may have caused me an issue with the PID loop
# not sure yet, re-running a quick PID tune. It does produce a lot
# of traffic on the debug log though, which stinks.
send_every: 1
update_interval: 1s
# PID stuff
- platform: pid
name: "PID Result"
type: RESULT
- platform: pid
name: "PID Integral Term"
type: INTEGRAL
- platform: pid
name: "PID Derivative Term"
type: DERIVATIVE
- platform: pid
name: "PID Proportional"
type: PROPORTIONAL
- platform: pid
name: "PID P Coefficient"
id: kp
type: KP
- platform: pid
name: "PID I Coefficient"
id: ki
type: KI
- platform: pid
name: "PID D Coefficient"
id: kd
type: KD
- platform: pid
name: "PID Output"
type: HEAT
### Sensors to read input numbers for PID tuning in Home Assistant ###
- platform: homeassistant
name: "P Coefficient"
entity_id: input_number.smoker1_p_coefficient
id: p_coefficient
- platform: homeassistant
name: "I Coefficient"
entity_id: input_number.smoker1_i_coefficient
id: i_coefficient
- platform: homeassistant
name: "D Coefficient"
entity_id: input_number.smoker1_d_coefficient
id: d_coefficient
# Reports how long the device has been powered (in minutes)
- platform: uptime
name: ${friendly_name} Uptime
filters:
- lambda: return x / 60.0;
unit_of_measurement: minutes
# Reports the WiFi signal strength
- platform: wifi_signal
name: ${friendly_name} Signal
update_interval: 60s
# this controls the main element and chamber temperature
# documented
climate:
- platform: pid
visual:
min_temperature: 150 °F
max_temperature: 350 °F
temperature_step: 1 °F
id: pid_smoker
name: "Smoker"
sensor: temp1
default_target_temperature: 275°F
heat_output: heater
control_parameters:
kp: 0.06629
ki: 0.00016
kd: 6.83407
time:
- platform: homeassistant
id: my_time
text_sensor:
# Reports the ESPHome Version with compile date
- platform: version
name: ${friendly_name} ESPHome Version
# log any time a puck advance takes longer than it should
# we assume that the IR sensor did not detect the cycle and
# we will want to know about this for troubleshooting the
# hardware
# documented
- platform: template
name: "Puck Chucker Errors"
id: puck_chucker_errors
# documented
esphome:
name: ${device_name}
comment: ${device_description}
platform: ESP32
board: mhetesp32devkit
on_boot:
priority: -100
# set these to some known, sane values
# may want to do something with this later to gracefully
# recover if we rebooted or something during a cook
# right now, there's no state between reboots
then:
- binary_sensor.template.publish:
id: chucker_primed
state: OFF
- sensor.template.publish:
id: num_chucks
state: '0'
- text_sensor.template.publish:
id: puck_chucker_errors
state: "OK"
# - switch.turn_on: chucker_reset
# web_server:
# port: 80
wifi:
# use_address: ${device_name}
use_address: 192.168.0.143
domain: !secret domain
power_save_mode: none
ssid: !secret wifissid
password: !secret wifipass
reboot_timeout: 0s
# fast_connect: on #we only have one WiFi AP so just use the first one that matches
ap:
ssid: "${device_name} Fallback Hotspot"
password: !secret wifipass
# Enable logging
logger:
baud_rate: 0
level: INFO
logs:
sensor: INFO
climate: INFO
i2c: NONE
ota:
password: !secret otapass
api:
password: !secret ha_api
reboot_timeout: 0s
i2c:
sda: GPIO21
scl: GPIO22
scan: True
spi:
miso_pin: GPIO19
mosi_pin: GPIO23
clk_pin: GPIO18
font:
- file: 'slkscr.ttf'
id: font1
size: 8
- file: 'BebasNeue-Regular.ttf'
id: font2
size: 24
- file: 'arial.ttf'
id: font3
size: 14
- file: 'materialdesignicons-webfont.ttf'
id: mdi
size: 24
glyphs: [
"\U000F0879", # mdi-hockey_puck
"\U000F02FF", # mdi-pot-outline
"\U000F065A", # mdi-pot-steam
"\U000F04A2", # mdi-signal
"\U000F0783", # mdi-signal-off
"\U000F0E2E", # mdi-fireplace
"\U000F0E2F", # mdi-fireplace-off
# "\U000", #
# "\U000", #
]
display:
- platform: ssd1306_i2c
model: "SH1106 128x64"
address: 0x3C
brightness: 0.7
lambda: |-
// top line
it.printf(0, 0, id(font1), TextAlign::TOP_LEFT, "SmokeMonster");
// Print time in HH:MM format
it.strftime(98, 0, id(font1), TextAlign::TOP_LEFT, "%H:%M", id(my_time).now());
// second line - set temp
it.printf(60, 30, id(font2), TextAlign::BASELINE_RIGHT, "%6.1f°", id(pid_smoker).target_temperature* (9.0/5.0) + 32.0);
// second line - middle, heater status
// if (id(myheater).state) {
// it.printf(70, 30, id(mdi), TextAlign::BASELINE_LEFT, "\U000F0E2E");
// } else {
it.printf(70, 30, id(mdi), TextAlign::BASELINE_LEFT, "\U000F0E2F");
// }
// second line - right, wifi status
if (id(statussensor).state) {
// online
it.printf(126, 30, id(mdi), TextAlign::BASELINE_RIGHT, "\U000F04A2");
} else {
// offline
it.printf(126, 30, id(mdi), TextAlign::BASELINE_RIGHT, "\U000F0783");
}
// bottom line - actual temp
it.printf(60, 60, id(font2), TextAlign::BASELINE_RIGHT, "%6.1f°", id(temp1).state* (9.0/5.0) + 32.0);
if (id(smoke_generator_heat).state) {
// lower middle, smoke generator
it.printf(70, 60, id(mdi), TextAlign::BASELINE_LEFT, "\U000F065A");
} else {
it.printf(70, 60, id(mdi), TextAlign::BASELINE_LEFT, "\U000F02FF");
}
// lower right, puck status
if (id(puck_chucker_advance).state) {
it.printf(126, 60, id(mdi), TextAlign::BASELINE_RIGHT, "\U000F0879");
} else {
it.printf(126, 60, id(font2), TextAlign::BASELINE_RIGHT, "%.0f", id(num_chucks).state);
}