Home Assistant controls microcontrollers over MQTT
Setting Up Tasmota
Before proceeding, you first need to connect the temperature sensor to one of the GPIOs used for flashing (RX/TX), which is now free. You can do this with a pull-up resistor and the 3.3V and GND connections [5]. After wiring the elements, it's time to configure the sensor; its name will have already appeared in the GUI (Figure 3).
You also need to assign a password for the web GUI and activate MQTT (Figure 4), which you will be using to deliver the data to Home Assistant. The broker and topic are configured in the corresponding entries in the web interface, where you will also find the Tasmota console, which lets you issue commands directly and set up the parameterization.
At this point at the latest, I recommend studying the very good documentation from Tasmota's GitHub repository. For this project, I used a command that makes the later integration with Home Assistant by autodiscovery very easy by telling Tasmota to announce all available topics (setoption19 on
). At the end of the day, Tasmota advertises itself in the GUI as a web switch with a temperature sensor (Figure 5). You can also view the MQTT publishing in the Console, if needed.
Integration
To make the components available in Home Assistant, you now need to set up MQTT integration in the GUI. To do so, all you need is the IP address and port of the broker you are using; by default, this is set to 1883. After the setup, the new MQTT devices should be displayed (Figure 6).
After clicking on the entities URL, both the switch and the temperature sensor are shown as available Home Assistant entities, and you can now use them in the usual way (Figure 7). In combination with the relay in the Sonoff module, the familiar automation features of Home Assistant can now be used to implement, say, a simple thermostat control.
Conclusions
The Tasmota option associated with Home Assistant's autodiscovery of MQTT integration easily makes this DIY solution as convenient as the commercial counterparts described in the previous article. Homebrewing turns out to be worthwhile – and great fun, too.
Infos
- "Z-Wave Home Assistant" by Gerhard Schauer, Linux Magazine, issue 248, July 2021, pg.56, https://www.linuxpromagazine.com/Issues/2021/248/Z-Wave-Home-Assistant/
- Sonoff Basic R2 Power: https://tasmota.github.io/docs/devices/Sonoff-Basic/#sonoff-basic-r2
- Getting Started: https://tasmota.github.io/docs/Getting-Started/
- Tasmota repository: https://tasmota.github.io
- Wiring Tasmota: https://tasmota.github.io/docs/DS18x20/
« Previous 1 2
Buy this article as PDF
(incl. VAT)