-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathESPHome_thermostat_Code.yaml
256 lines (230 loc) · 7.28 KB
/
ESPHome_thermostat_Code.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
esphome:
name: "thermostat-kitchen"
platform: ESP8266
board: d1_mini
on_boot:
priority: -100.0
then:
- switch.turn_on: dallas_power
- lambda: "id(oled_contrast).publish_state(0.4);"
substitutions:
room: Kitchen # Room Name
entity_heater: input_boolean.tut_thermo_fire ### Change for your 'Heating' Entity
entity_cooler: input_boolean.tut_thermo_cool ### Change for your 'Cooling' Entity
default_low: "20"
default_hi: "28"
wifi:
networks:
- ssid: !secret wifi_ssid
password: !secret wifi_password
logger:
logs:
climate: none
sensor: none
# dallas.sensor: none
api:
ota:
platform: esphome
i2c:
frequency: 400kHz
switch:
- platform: gpio
id: dallas_power
name: "Dallas Power"
pin:
number: GPIO03
- platform: template
id: heat_cool
optimistic: true
- platform: gpio
id: relay_heater
pin: D0
inverted: true
- platform: gpio
id: relay_cooler
pin: D5
inverted: true
- platform: template
id: brightness
optimistic: true
binary_sensor:
- platform: template
id: fire
- platform: template
id: cool
- platform: gpio
id: button
pin:
number: D4
inverted: true
on_press:
then:
- switch.toggle: heat_cool
on_click:
- min_length: 1000ms
max_length: 20000ms
then:
- switch.toggle: brightness
climate:
- platform: thermostat
min_cooling_off_time: 0s
min_cooling_run_time: 0s
min_heating_off_time: 0s
min_heating_run_time: 0s
min_idle_time: 0s
visual:
min_temperature: 15 °C
max_temperature: 30 °C
name: "${room} Thermostat"
id: this_thermostat
sensor: internal_temperature
### Updated for ESPHome v2022.10.0 Onwards
default_preset: Home ### NEW! Use this to set Preset
# on_boot_restore_from: memory ### Use this to "Restore From Memeory" (A Saved State) OR...
on_boot_restore_from: default_preset ### Use this to set Preset to start on every Boot
preset:
- name: Home
default_target_temperature_low: $default_low
default_target_temperature_high: $default_hi
mode: AUTO
###########################################
cool_action:
- switch.turn_on: relay_cooler
- lambda: id(cool).publish_state(true);
- homeassistant.service:
service: homeassistant.turn_on
data:
entity_id: $entity_cooler
heat_action:
- switch.turn_on: relay_heater
- lambda: id(fire).publish_state(true);
- homeassistant.service:
service: homeassistant.turn_on
data:
entity_id: $entity_heater
idle_action:
- switch.turn_off: relay_cooler
- switch.turn_off: relay_heater
- lambda: id(cool).publish_state(false);
- lambda: id(fire).publish_state(false);
- homeassistant.service:
service: homeassistant.turn_off
data:
entity_id: $entity_cooler
- homeassistant.service:
service: homeassistant.turn_off
data:
entity_id: $entity_heater
one_wire:
- platform: gpio
pin: D3
sensor:
- platform: template
id: oled_contrast
- platform: dallas_temp
id: internal_temperature
update_interval: 2s
address: 0xf53c01f0959bd428
- platform: homeassistant
id: internal_humidity
entity_id: sensor.ironman_humidity
- platform: rotary_encoder
id: encoder
pin_a:
number: D6
mode: INPUT_PULLUP
pin_b:
number: D7
mode: INPUT_PULLUP
on_clockwise:
- if:
condition:
switch.is_on: brightness
then:
- sensor.template.publish:
id: oled_contrast
state: !lambda "return id(oled_contrast).state + 0.02;"
- lambda: |-
id(oled1).set_contrast( id(oled_contrast).state );
else:
- if:
condition:
switch.is_on: heat_cool
then:
- climate.control:
id: this_thermostat
target_temperature_high: !lambda "return id(this_thermostat).target_temperature_high + 0.5;"
else:
- climate.control:
id: this_thermostat
target_temperature_low: !lambda "return id(this_thermostat).target_temperature_low + 0.5;"
on_anticlockwise:
then:
- if:
condition:
switch.is_on: brightness
then:
- sensor.template.publish:
id: oled_contrast
state: !lambda "return id(oled_contrast).state - 0.02;"
- lambda: |-
id(oled1).set_contrast( id(oled_contrast).state);
else:
- if:
condition:
switch.is_on: heat_cool
then:
- climate.control:
id: this_thermostat
target_temperature_high: !lambda "return id(this_thermostat).target_temperature_high - 0.5;"
else:
- climate.control:
id: this_thermostat
target_temperature_low: !lambda "return id(this_thermostat).target_temperature_low - 0.5;"
display:
- platform: ssd1306_i2c
id: oled1
update_interval: 1.0s
contrast: 0.4
model: "SH1106 128x64"
rotation: 180
address: 0x3C
lambda: |-
if (id(fire).state) {id(ani_fire).next_frame(); it.image(0, 0, id(ani_fire));}
else if (id(cool).state) {id(ani_fan).next_frame(); it.image(0, 0, id(ani_fan));}
else {it.image(0, 0, id(home_thermometer));}
it.print(64, 0, id(font1), TextAlign::TOP_CENTER, "${room}");
it.printf(128, 0, id(font4), TextAlign::TOP_RIGHT, " %.1f%% ", id(internal_humidity).state);
it.printf(64, 4, id(font2), TextAlign::TOP_CENTER, " %.1f°", id(internal_temperature).state);
it.printf(0, 64, id(font3), TextAlign::BASELINE_LEFT, "L:%.1f°", id(this_thermostat).target_temperature_low);
it.printf(128, 64, id(font3), TextAlign::BASELINE_RIGHT, "H:%.1f°", id(this_thermostat).target_temperature_high);
if (id(brightness).state) {it.image(56, 51, id(bulb));}
else if (id(heat_cool).state) {it.image(56, 51, id(arrow_right));}
else {it.image(56, 51, id(arrow_left));}
animation:
- file: "_icons/thermostat/fan.gif"
id: ani_fan
- file: "_icons/thermostat/fire.gif"
id: ani_fire
image:
- file: "_icons/thermostat/home-thermometer.png"
id: home_thermometer
- file: "_icons/thermostat/arrow-left-circle-outline.png"
id: arrow_left
- file: "_icons/thermostat/arrow-right-circle-outline.png"
id: arrow_right
- file: "_icons/thermostat/lightbulb-on-outline.png"
id: bulb
font:
- file: "_fonts/nasalization.ttf"
id: font1
size: 12
- file: "_fonts/refsan.ttf"
id: font2
size: 42
- file: "_fonts/refsan.ttf"
id: font3
size: 13
- file: "_fonts/refsan.ttf"
id: font4
size: 10