Everything you need to get Home Assistant running and controlling a Tasmotized Sonoff

Everything you need to get Home Assistant running and controlling a Tasmotized Sonoff


Home Automation is awesome. There are a lot of different ways to make your dumb home more smarter. Using a hub is the most smartest place to start. When it comes to Smart Home Hubs, there are a lot of choices. My choice is Home Assistant. I like HA because it’s open source, free, very well supported, and compatible with 1000 different devices and counting.


One of the best parts about Home Assistant is how frequently it gets updated. Last I checked they were getting an updated version out every 2 weeks. The downside of such rapid change is that tutorials (like the ones I make) can become outdated pretty fast.


There are a bunch of different ways to run Home Assistant. https://home-assistant.io/docs/installation/

Of all the options there is one that is quite a bit different than the rest; Hass.io.  What makes Hass.io so different?  Basically Hass.io makes a Home Assistant Pi a lot more similar to an off-the-shelf Hub like SmartThings, Harmony, Wink, etc, because you don’t really ever have to use the command line.  All the other methods for running Home Assistant require some level of command line use, and management of all the different other programs you might use with Home Assistant like Mosquitto for MQTT, or Samba for accessing your configs. Even updating Home Assistant itself, editing the configuration file can, and even restarting the pi can be done in Hass.io!  Wow.


There are already some good videos about the basic install of Hassio.  And it really is pretty easy, so I’m only going to do the quick version here.



  1. If you’re coming from an older install backup all your yaml files.
  2. Raspberry pi & new or formatted sd card at least 32g, Class10.
  3. Download Hass.io for Rpi3 image
  4. Write Hassio image to the card – Using Etcher
  5. If you want to use Wifi there’s a process for that:
    1. WiFi setup only: open the file system-connections/resin-sample (from the resin-boot volume on the SD card) with a text editor. Change ssid to be your network name and psk to be your password.
  6. Put the SD in the pi, connect your ethernet cable and plug in the pi.
  7. In a browser either go to Hassio.local or your.pi.IP:8123
  8. Done


Now, while it’s updating HA, in your router, set the IP of your pi static (or reserved). If you don’t do that and your router restarts it could re-assign IP addresses and if your pi’s IP changes the other devices won’t be able to find it. If you’re coming from an old install set the new pi to the IP address of the old pi so your devices will know where to find it.


Set up Mosquitto:

Hassio manages other useful programs as “Add-ons”.  In my setup the most important Add-on is Mosquitto. That’s the MQTT broker, and almost all my devices use MQTT. Most importantly all my Tasmotized Sonoffs use MQTT.   

If you’re coming from an old install, use the same user/pw so your old devices can reconnect. Every add-on has a “website” link that will take you to more detailed instructions on how to install and setup that add on.  Some don’t require any setup, some require a little, some require a bit more, but all of them are easier than they used to be. You don’t need to have a user and password for MQTT, but I do. After setting the initial options, save and start Mosquitto. There is a step that needs to be done in the configuration.yaml file. So in order to do that step, we’re going to install what I think is one of the coolest most useful add-ons for Hassio – the Configurator. I would have called it the Configure-inator, but they didn’t ask me.


Set up Configurator:

The Configurinator lets you edit yaml files from the web interface. Most importantly you can edit your configuration.yaml but also all the other yaml files as well. It’s a really good idea to put a username and password on this since anyone who can see your web interface would have access to you config files. It’s not that someone would purposely mess with your config.  It’s much more likely someone in your family would accidently get into the config and mess it up while trying to turn on the Christmas lights.

There isn’t much configuration needed for the configurator-inator. But, one cool thing you can do is make a new button on the side bar so you can go straight to the configure-inator. And you can use the configurator to do it! Paste these lines into your configuration.yaml file:

   title: Configurator
   icon: mdi:wrench
   url: http://hassio.local:3218


Now that we have the configurator set up and we can edit the config.yaml we can finish setting up Mosquitto. You need to add these lines. It doesn’t matter where in the file you put them. The alignment does matter though, so make sure the main heading is all the way to the left and the other lines are indented properly.

 broker: core-mosquitto
 username: YOUR_USERNAME
 password: YOUR_PASSWORD


You don’t have to use a username/password. Just put a hashtag in front of those lines and Home Assistant will ignore them. That’s a nice way to do it because if you decide later you do want to use those lines, you just remove the hashtag. In order for changes to the config file to take effect you have to restart home assistant. That’s another thing they’ve added to Hassio; a really easy way to reload different components or restart the whole system.  If you’ve made big changes to the config file it’s probably a good idea to hit the verify config button before you restart HA.

While you’re still in the configuration.yaml paste in these lines, to set up a switch that will be connected to your sonoff:


   platform: mqtt

   name: “Sonoff Switch 01”

   command_topic: “cmnd/sonoff/power”

   state_topic: “stat/sonoff/POWER”

   qos: 1

   payload_on: “ON”

   payload_off: “OFF”

   retain: true


Set up Samba.

There’s one more add-on I’d put on the “do this first” list, and that is Samba. Samba makes a few important folders on you HA pi available to other computers on your network. That lets you copy new files into those folders, like icons or themes, for example. And it also gives you another way to access your config files to back them up or edit them if you somehow screwed up and lost access to the Configure-inator.

Of the add-ons we’ve done Samba is the easiest. Install it, set the options you want, including username and password, set the interface to eth0 if your pi is wired into your network, or wlan0 if you’re using the pi’s wifi. Save and start. That’s it.  


Now we’re going to install Tasmota on our Sonoff Basic.  

There are several ways to do this and good videos out there showing how. I’m going to use the Arduino IDE because it’s the method I’m most familiar with.  If you don’t already have it, grab the arduino IDE from the website and install it.  Next, open it and go to Preferences. In the Other Board Managers URL box paste this line:



Take note of the file path at the top of the Preference page that says “Sketchbook Location”.  We’re going to use that in a few minutes, after we download Tasmota.


Go to the Tasmota releases page: https://github.com/arendst/Sonoff-Tasmota/releases

Download the latest release Source code.zip, and extract it. Among the folders it creates you’ll find one called lib. Open that folder and copy everything inside it. Now navigate to the Sketchbook location (from the Preferences page) find the libraries folder and paste everything from the lib folder into this libraries folder. Now you’ll have all the libraries you need, right where you need them.

Now in the Sonoff-Tasmota folder find the sonoff folder, open it, and click the sonoff.ino file. That’ll open the Arduino IDE. Open the Tools menu, then Board, then Boards Manager. Search for ESP8266, and install it, or update it, if it’s already there.

Sonoff.ino has a bunch of connected documents. The one we need to edit (just a little) is called user_config.h, you can find it by clicking the little down arrow in the upper right hand corner.

In the user_config folder you can simply find the line that says WIFI_WPSCONFIG and change that to WIFIi_MANAGER. That way, when the sonoff starts up it will create a wifi network that you can connect to and then input your wifi SSID/PW, MQTT user/pw, and Project name.  If you’d rather just put that info in now you can do that too.

Next step is to connect the sonoff to your computer. You’ll need an FTDI adapter and some jumpers. There are 4 pins to connect between the FTDI and the sonoff. Ground, 3v, Rx and Tx. Rx and Tx stand for Receive and Transfer. You need the Transfer pin from the FTDI to connect to the Receive pin on the sonoff, and vice versa. That sometimes throws people off. Tx goes to Rx and Rx goes to Tx. Probably the easiest way to get the sonoff in programming mode is to connect the FTDI to the sonoff first, then hold down the on-board button, then plug the USB cable into your computer. If a new device shows up under Tools – Ports in your Arduino IDE, then you’re connected.  

Last step is to get all the upload settings correct in Tools. Here’s what you should have:


Board: Generic ESP8266 Module

Flash Mode: DOUT

Flash Size: 1M (no SPIFFS)

Debug port: disabled

Debug Level: None

IWIP Variant: v1.4 Prebuilt

Reset Method: nodemcu

Crystal Frequency: 26 MHz

Flash Frequency: 40 MHz

Upload Using: Serial

CPU Frequency: 80 MHz

Upload Speed: 115200

Port: (whichever port shows up new when you connect the FTDI adapter)


With all that set you’re ready to hit Upload and pray. If it fails to upload the most likely problem is that the board didn’t get into programming mode. So try that process again.  It used to be the libraries that messed everyone up, but that should be good now that we’ve copied all the right libraries into the Arduino Sketchbook libraries folder.


Hopefully it worked and uploaded on the first try! Now to finish the set up, you need to reset the sonoff by unplugging it then plugging it back in. Soon there will be a new SSID in your available networks called sonoff-something. Click that. It’ll open a window that will let you put in your home Wifi ID and Password. When that’s done it’ll restart and connect to your network. You’ll need to find the IP address of the sonoff by looking in your router or with Fing. Put that IP in your browser and it’ll open the Tasmota main page. Here you can go into Configuration and set up your MQTT broker information and make GPIO 14 ready to be a switch. Make sure your MQTT Topic matches what you put in the configuration.yaml.

That should do it!

Similar Posts