Using Tasmota Devices with Home Assistant and MQTT

Tasmota is a small open source home automation software that can be flashed onto any expressive chipset and used to control lighting, fans, switches etc using both HTTP and MQTT protocols over Wi-Fi.



How to use Tasmota with Home Assistant

In a previous tutorial I  covered the setup of tasmota on Sonoff switches and you should read that tutorial before continuing if you haven’t setup Tasmota before.

I also covered how to add an MQTT device to home assistant both manually and automatically.

In this tutorial I want to concentrate on the setting up Tasmota to work with home assistant, and how to setup home assistant to work with Tasmota so that Tasmota devices are auto discovered by home assistant.

The Tasmota setup is identical with that described in the referenced tutorial above but you will need to have a Tasmota firmware version of 9.2 or higher for auto detection and setup  by home assistant.

If you are using a version lower than 9.2 you can upgrade but I recommend you see my Tasmota upgrade notes as it is not always a straightforward process. See upgrading Tasmota notes.

If you want to continue  using a version lower than 9.2 you can still use it with homea ssistant but you will need to either manually set up the device in home assistant using the configuration.yaml file or use the older SetOption19 feature.

Home Assistant Device Setup

Traditional device setup is done using the configuration.yaml file and this method still works.

Automatic Tasmota device detection  has been available using the MQTT device detection feature that relied on using the SetOption 0 command on the Tasmota device console.

tasmota-console

Type SetOption19 0 on the command line and hit enter.

tasmota-console-setoption19

There is also a video here.

Besides the broker name and port etc the most important configuration which is different for home assistant is the device name and friendly name as these are detected by home assistant and used to name the switch/sensor on the dashboard. This is part of the other configuration menu option

In the screen shot below I have called mine switch_3 but you should really be more descriptive like bedroom light main.

tasmota-config-1

This is how it appears on the Home assistant dashboard.

switch_3-dashboard

The actual topic naming and order prefix/topic or topic/prefix or topicbase/prefix/topic is not important for auto detection by home assistant.

tasmota-config

Guidelines for choosing a structure are given in the setup tutorial

Home Assistant Configuration

On home assistant you need to have the MQTT Integration and also

mqtt-auto-discovery

You also need to install and enable the Tasmota integration.
When done you should see the devices show up on the dashboard under integrations.

tasmota-devices-integration

If you go to devices you should see all of the devices found and if you click a device it open up a menu where you can control the device,see data and also add it to the main dashboard.

tasmota_devices

below shows part of the device management screen

homeassistant-manage-devices

 

Device Configuration information Storage in Home Assistant

Home Assistant doesn’t appear to store the device configuration information anywhere but instead publishes to the MQTT broker as a retained message.

This means that when it restarts it receives the configuration data from broker when it subscribes to that topic.

For this to work reliably the broker needs to be configured with a persistent data store.

mosquitto-conf-persistent

On my broker I did a scan for retained topics and saw the following, remembering that I have 4 Tasmota devices.

tasmota_discovery

If we look in more detail at the conf topic for one of the devices we see this:

tasmota_config_data

Common Questions and Answers

Q- What is SetupOption19?

A- This is a configuration option on tasmota which when executed with send confg data to the MQTT broker which allows home assistant to auto detect the device. It doesn’t require the Tasmota integration.

Q- Why not use SetupOption19 instead of the Tasmota integration?

A- SetupOption19 is likely to be discontinued and so is not recommended any more.

Summary

To use a Tasmota device with home assistant and have the device auto detected by home assistant then configure the device as normal but pay attention the the device name and device friendly name.

For auto detection to work the device needs firmware version 9.2 or above.

On home assistant the MQTT and Tasmota integrations need to be installed and configured.

Related tutorials and resources.

 

Please Let me Know if you found it Useful
[Total: 1 Average: 5]

Leave a Reply

Your email address will not be published. Required fields are marked *