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).

Figure 3: A convenient web GUI helps you set up the temperature sensor.

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.

Figure 4: Just a few parameters let you prepare Tasmota for transferring data to Home Assistant.

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.

Figure 5: Hardly distinguishable from commercial products: the web-based user interface of Tasmota.

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).

Figure 6: A few simple steps are all it takes to integrate the MQTT protocol into Home Assistant.

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.

Figure 7: Home Assistant presents the integrated sensors in a clear-cut and neat way.

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

  1. "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/
  2. Sonoff Basic R2 Power: https://tasmota.github.io/docs/devices/Sonoff-Basic/#sonoff-basic-r2
  3. Getting Started: https://tasmota.github.io/docs/Getting-Started/
  4. Tasmota repository: https://tasmota.github.io
  5. Wiring Tasmota: https://tasmota.github.io/docs/DS18x20/

The Author

Gerhard Schauer is a self-employed electronics engineer living in the southern part of Germany. He writes maker articles because learning by doing and maintaining control of technology is the "right" way.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Tasmota

    Flashing IoT devices with new firmware lets you wield control and keep them out of the cloud.

  • ESPHome

    With an ESP32 or Raspberry Pi Pico W microcontroller board, you can easily create your own home automation devices. Thanks to ESPHome, you don't even have to be a programmer.

  • WiFi Thermo-Hygrometer

    A WiFi sensor monitors indoor humidity and temperature and a Node-RED dashboard reports the results, helping you to maintain a pleasant environment.

  • Controlling a Smart Plug

    You could spend hundreds of dollars on specialized IoT appliances and fixtures, or you could just hack a smart plug and talk to it with your Linux system.

  • Home Assistant

    Home Assistant brings an open standards approach to home automation and control.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News