forked from 3ative/thermostat-project-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ESPHome_thermostat_Code.yaml
203 lines (178 loc) · 5.63 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
esphome:
name: "wand-thermostat-max-wz" # Name of the ESPHome device
platform: ESP8266
board: d1_mini
on_boot:
priority: -100.0
then:
- lambda: "id(oled_contrast).publish_state(0.4);"
- script.execute: activate_oled1
### Change these to configure the wall thermostat ###
substitutions:
room: "Test room" # Room name
climate_id: "climate.test_room" # The climate entity in Home Assistant which will be used for checking and setting target temperature
temperature_id: "Test room temperature" # sensor.${temperature_id} will be the temperature sensor in Home Assistant
encryption_key: "xxxxxxx" # The encryption key for communicating with Home Assistant
ota_password: "xxxxxxx" # The OTA password
ds18b20_address: "0xbe012275d68d1028" # This address needs to be replaced with the one from the logs after first flash
### Change these to configure the wall thermostat ###
wifi:
networks:
- ssid: !secret wifi_ssid
password: !secret wifi_password
# My mDNS seems to not work so this is necessary to use the ESPHome Dashboard
# manual_ip:
# static_ip: 192.168.2.240
# gateway: 192.168.2.1
# subnet: 255.255.255.0
logger:
logs:
sensor: none
api:
encryption:
key: ${encryption_key}
ota:
password: ${ota_password}
i2c:
frequency: 400kHz
switch:
- platform: template
id: brightness
optimistic: true
- platform: template
id: oled1_state
optimistic: true
binary_sensor:
- platform: gpio
id: button
pin:
number: D4
inverted: true
on_release:
then:
- if:
condition:
switch.is_on: oled1_state
then:
- switch.toggle: brightness
- script.execute: activate_oled1
else:
- script.execute: activate_oled1
dallas:
- pin: D3
update_interval: 15s
sensor:
- platform: template
id: oled_contrast
- platform: dallas
id: internal_temperature
address: ${ds18b20_address}
name: ${temperature_id}
# TODO Move offset to configuration block.
# TODO For now I can't figure out how to do proper float casting.
filters:
- offset: 0.0
- 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: oled1_state
then:
- script.execute: activate_oled1
- if:
condition:
switch.is_on: brightness
then:
- sensor.template.publish:
id: oled_contrast
state: !lambda "return id(oled_contrast).state + 0.1;"
- lambda: |-
id(oled1).set_contrast( id(oled_contrast).state );
else:
- homeassistant.service:
service: climate.set_temperature
data:
temperature: !lambda "return id(btt_target_temp).state + 0.5;"
entity_id: ${climate_id}
on_anticlockwise:
- if:
condition:
switch.is_on: oled1_state
then:
- script.execute: activate_oled1
- if:
condition:
switch.is_on: brightness
then:
- sensor.template.publish:
id: oled_contrast
state: !lambda "return id(oled_contrast).state - 0.1;"
- lambda: |-
id(oled1).set_contrast( id(oled_contrast).state);
else:
- homeassistant.service:
service: climate.set_temperature
data:
temperature: !lambda "return id(btt_target_temp).state - 0.5;"
entity_id: ${climate_id}
- platform: homeassistant
id: btt_target_temp
entity_id: ${climate_id}
attribute: temperature
text_sensor:
- platform: homeassistant
id: btt_heating_state
entity_id: ${climate_id}
attribute: hvac_action
display:
- platform: ssd1306_i2c
id: oled1
update_interval: 1.0s
contrast: 0.4
model: "SH1106 128x64"
rotation: 180
address: 0x3C
lambda: |-
it.print(64, 0, id(font1), TextAlign::TOP_CENTER, "${room}");
it.printf(63, 4, id(font2), TextAlign::TOP_CENTER, " %.1f°", id(internal_temperature).state);
it.printf(127, 64, id(font3), TextAlign::BASELINE_RIGHT, "Ziel: %.1f°", id(btt_target_temp).state);
if (id(brightness).state) {it.image(1, 49, id(bulb));}
else if (id(btt_heating_state).state == "idle") {it.image(1, 49, id(home_thermometer));}
else {id(ani_fire).next_frame(); it.image(1, 49, id(ani_fire));}
animation:
- file: "_icons/thermostat/fire.gif"
id: ani_fire
image:
- file: "_icons/thermostat/home-thermometer.png"
id: home_thermometer
- file: "_icons/thermostat/lightbulb-on-outline.png"
id: bulb
font:
- file: "_fonts/refsan.ttf"
id: font1
size: 12
- file: "_fonts/refsan.ttf"
id: font2
size: 42
- file: "_fonts/refsan.ttf"
id: font3
size: 13
script:
- id: activate_oled1
mode: restart
then:
- lambda: |-
id(oled1).turn_on();
id(oled1_state).turn_on();
- delay: 3s
- lambda: |-
id(oled1).turn_off();
id(oled1_state).turn_off();
id(brightness).turn_off();