-
Notifications
You must be signed in to change notification settings - Fork 14
/
coffee-maker.yaml
134 lines (124 loc) · 3.91 KB
/
coffee-maker.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
substitutions:
device_id: coffee-maker
device_name: Coffee Maker
board: nodemcuv2
ip_address: !secret coffee_maker_ip
api_key: !secret coffee_maker_key
pwd: !secret coffee_maker_pwd
packages:
device_base: !include ./packages/device_base_esp8266.yaml
binary_sensor:
- platform: gpio
id: power_light
pin:
number: D5
mode: INPUT
inverted: True
filters:
- delayed_on: 50ms
- delayed_off: 50ms
- platform: gpio
id: bold_light
pin:
number: D6
mode: INPUT
inverted: True
filters:
- delayed_on: 50ms
- delayed_off: 50ms
interval:
- interval: 1s
then:
- lambda: |-
// Coffee tastes better if allowed to "bloom" (wet the coffee and then let it sit for 30 seconds to release any trapped CO2 before completing brewing)
// This logic automates this process regardless of how the coffee maker was turned on
static int brewStage = 0; // 0=Off, 1=Pre-Wet, 2=Bloom, 3=Brew
static unsigned long brewStageChange = 0;
static bool isBoldBrew = false;
// Coffee maker was off but now is on so it is in the pre-wet stage
if (id(power_switch).state && brewStage == 0) {
brewStage = 1; //Pre-Wet
brewStageChange = millis() + 75000;
isBoldBrew = id(bold_switch).state;
}
// Coffee should be wet now so turn off and let it bloom
else if (id(power_switch).state && brewStage == 1 && millis() >= brewStageChange) {
id(power_switch).turn_off();
brewStage = 2; //Bloom
brewStageChange = millis() + 45000;
}
// Coffee has bloomed so turn back on to finish brewing
else if (!id(power_switch).state && brewStage == 2 && millis() >= brewStageChange) {
if (isBoldBrew && !id(bold_switch).state) {
id(bold_switch).turn_on();
}
id(power_switch).turn_on();
brewStage = 3; //Brew
}
// Manually powered off during Pre-Wet stage
else if (!id(power_switch).state && brewStage == 1) {
brewStage = 0;
}
// Manualy powered on during Bloom stage
else if (id(power_switch).state && brewStage == 2) {
brewStage = 3;
}
// Done brewing
else if (!id(power_switch).state && brewStage == 3) {
brewStage = 0;
}
switch:
- platform: template
id: power_switch
name: "Coffee Maker"
icon: mdi:coffee
lambda: 'return id(power_light).state;'
turn_on_action:
then:
- lambda: |-
if (!id(power_light).state) {
id(power_switch_physical).turn_on();
delay(200);
id(power_switch_physical).turn_off();
delay(100);
}
turn_off_action:
then:
- lambda: |-
if (id(power_light).state) {
id(power_switch_physical).turn_on();
delay(200);
id(power_switch_physical).turn_off();
delay(100);
}
- platform: gpio
id: power_switch_physical
pin: D0
inverted: true
- platform: template
id: bold_switch
name: "Coffee Maker Bold Setting"
icon: mdi:coffee
lambda: 'return id(bold_light).state;'
turn_on_action:
then:
- lambda: |-
if (!id(bold_light).state) {
id(bold_switch_physical).turn_on();
delay(200);
id(bold_switch_physical).turn_off();
delay(100);
}
turn_off_action:
then:
- lambda: |-
if (id(bold_light).state) {
id(bold_switch_physical).turn_on();
delay(200);
id(bold_switch_physical).turn_off();
delay(100);
}
- platform: gpio
id: bold_switch_physical
pin: D1
inverted: true