46 January & February 2021 http://www.elektormagazine.com
rest, I now had to do automations inside ESPHome. This programming
and configuring is done in the YAML file of the thermostat’s ESPHome
project (see “Home Automation Made Easy” [3]).Measure Room Temperature
First, declare the temperature sensor that measures the room tempera-
ture. As the sensor used is a DS18B20 (originally from Dallas, now Maxim
or even Analog Devices) connected to GPIO pin 5, and since ESPHome
has a special Dallas component, this translates to the following entries:dallas:
- pin: GPIO5sensor:
- platform: dallas
address: 0x6D00000C24013928
name: “Measured temperature”
id: t_room
filters:
- offset: 0.0The first line tells ESPHome to include its Dallas 1-wire communica-
tion module and connect GPIO5 to it. The sensor then is of the dallas
platform. The address is optional. However, if you specify it, it must
be correct; you can get it from the ESPHome log (don’t use mine, it is
unique). Specifying an id (t_room, pun not intended) is required here
because we will need to refer to the sensor from somewhere else insideI added a potentiometer with a voltage limiting resistor because the Wi-Fi
module cannot handle voltages higher than 1.1 V. I kept the two pushbut-
tons and the three LEDs as they might come in handy at some point.
It was a lucky coincidence that the AC/DC module was just small
enough to fit under the plastic knob support of the potentiometer. The
potentiometer, power switch and mains terminal block were recovered
from the old thermostat (Figure 3). I had to replace the relay by a 5 V
type as the old thermostat’s relay was a 48-V type. I did not manage
to fit the desktop thermostat’s relay, but, lucky me once more, the old
thermostat’s relay was a type from an industry-standard family that
is still available and that exists in 5 V.
Putting it all on a PCB that fitted in the original enclosure required a
lot of measuring, but I succeeded in the end. All the SMT components
including the Wi-Fi module went on the bottom side of the board
(Figure 4), while all the through-hole parts found a place on the top
side. A little bit extra board surface was gained by obstructing a couple
of unused mounting holes of the enclosure. The fitting also implied
cutting away some plastic obstacles inside the enclosure. To route all
the tracks, a flexible approach of recommended isolation standards
was unfortunately unavoidable.
Software
The ESPHome firmware that I had compiled for my first setup also
required rethinking. Instead of simply exposing all the sensors and
actuators of the thermostat and letting Home Assistant take care of the
ESP-12E
GPIO16
GPIO14
GPIO12
GPIO13 GPIO15GPIO10MOD1
CH_ PDGPIO2GPIO0GPIO4GPIO5GPIO9RESTCS0MISO MOSISCLKADCVCC GNDRXTX^2221161718192010 11 12 13 141591 2 3 4 5 6 7 8K2
1
2
3
4
5K1
1 2 3 4 5 6R4
10k+3V3R11
120kP1
47kC3
100nR3
10kS2 S1 R2
220
LED3YELLOWLED1REDLED2GREENR10
10kR9
220R8
10kR7
10kR1
220R6
1kDS18B 20IC212R5 3
10k C1
100nT12N7002 SD
GRY211006Re1 D1
1N4148N
L
NC
COM
NOS3
LM1117-3.3
IC1
C4
1+3V3IRM-02-5AC/DC1
LN+5V200519-001TXD
RXD
RST
GND
P0C2
100nC5(^100) 6V3
Figure 2: Basically, the new discreetly
connected thermostat is the Elektor
Desktop Thermostat from 2018
with a new power supply. Also, a
potentiometer was added for setting
the target temperature.