Hassio/Home Assistant: Installing a Sonoff Switch (Tasmota Firmware)

The Sonoff switches that have been flashed with Tasmota Firmware are compatible with Home Assistant/Hassio. The following guide will take you through the steps to install the required components to allow you to use the switches for automations.

What you will need:

If you haven’t already seen my initial Hassio setup guide, please visit this link.

Option 1 – Installing using Wemo Emulation

Step 1 – Enable Belkin Wemo Emulation

Open your Sonoff Switch interface

Navigate to Configuration > Configure Other, select “Belkin WeMo” and click Save.

Step 2 – Restart your device

Restart your device and your switch will automatically be detected by Home Assistant and visible in the Overview page.

Step 2 – Customize the switch name (optional)

You can customize the name through clicking on the device and clicking on the settings cog.

Change the name and click Save.

The new name will now be reflected in the Home Assistant Overview screen.

Option 2 – Installing through MQTT

While this option takes a bit more effort, I’ve found this to be more reliable than the emulation option.

Step 1 – Enable MQTT on the Switch

As per the Option 1 above, navigate to Configuration > Configure Other, ensure that MQTT is selected as enabled and click Save. If you have enabled the emulation above, you can change it back to “None” to avoid duplicate devices detected.

Step 2 – Add MQTT configurations to Home Assistant configuration.yaml file

For each of the switches to be added, add in the details of the MQTT topics that will be used. I have used the following configurations for a device:

configuration.yaml

mqtt:
password: !secret mqtt_password

switch:
– platform: mqtt
name: “sonoff1795”
state_topic: “stat/sonoff-1795/RESULT”
value_template: ‘{{ value_json[“POWER1”] }}’
command_topic: “cmnd/sonoff-1795/POWER1”
availability_topic: “tele/sonoff-1795/LWT”
qos: 1
payload_on: “ON”
payload_off: “OFF”
payload_available: “Online”
payload_not_available: “Offline”
retain: true

Note: Be sure to include your mqtt_password in your secrets.yaml file.

Step 3 – Restart your device

Within Home Assistant, restart under Configuration > General > Restart.

Step 4 – Configure MQTT on the Sonoff Switch

Navigate to your Sonoff switch’s interface and go to Configuration > Configure MQTT. The details here should match what you have put in your configuration.yaml and secrets.yaml file.

Step 5 – Restart your device

Per Step 3. The switch should now be visible within the Home Assistant Overview screen.

Step 6 – Customize the switch name (optional)

Within Home Assistant, navigate to Configuration > Customization and select the newly installed Switch. Edit the name and click Save.

The new name will now be reflected in the Home Assistant Overview screen.

2 thoughts on “Hassio/Home Assistant: Installing a Sonoff Switch (Tasmota Firmware)

  1. Ilja

    Hey. I know this tutorial was just posted two weeks ago, but i believe it is outdated. I have been struggling to manually(without using Auto-discovery) configure my Sonoff Basic, but after carefully studying GitHub wiki(https://github.com/arendst/Sonoff-Tasmota/wiki/Commands#main), i finally made it. I’m using Sonoff-Tasmota 6.4.1 and Home Assistant 0.85.1, so my configuration looks like:
    /config/configuration.yaml:
    switch: !include switch.yaml

    /config/switch.yaml:
    – platform: mqtt
    name: “MY SONOFF”
    command_topic: “tasmota/sonoff_basic/cmnd/POWER1”
    state_topic: “tasmota/sonoff_basic/cmnd/POWER1”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    payload_available: “Online”
    payload_not_available: “Offline”
    retain: false

    Note, that during Sonoff Basic MQTT configuration you should use the following:
    Topic: sonoff_basic
    Full Topic: tasmota/%topic%/%prefix%/

    • matthew Post author

      Hi Ilja,

      This is great feedback and something to be constantly aware of as updates are made within Hass.io and Tasmota. I created this video a few weeks ago and at the time of the video I was on 6.3.0 for Tasmota and 0.84.6 for Hass.io. I’ll update my Hass.io and Tasmota and get back to you to see if any changes are required to the post.

      In the meantime, looking at your differences:

      Topic names: The topic names that have been configured should be visible through either the configurations or you can view them in the console (Tasmota main menu > Console). As the state of the device change, these topics will be updated and you can see any errors or the actual topics posted. These actual names should match your configuration and if your default settings are different, you should align the configuration to this.
      The other option is to check the configuration of the topics through Configuration > Configure MQTT. My full topic configuration is ‘%prefix%/%topic%/’ and this might be different for yours to align to the configuration you have suggested.

      Retain: If these messages are published with a RETAIN flag, the MQTT switch will receive an instant state update after subscription, and will start with the correct state. Otherwise, the initial state of the switch will be false / off.

      Thanks again for your feedback and I’ll update and post again when the updates are finished.

Comments are closed.