Home Home Automation Using Sonoff Tasmota software

Using Sonoff Tasmota software

Adding Tasmota experience to Sonoff devices.

Encouraged by the latest ESP hacks and your comments, I decided to take a look at the Sonoff Tasmota software too. I love to learn by trial and error and writing custom code for ESP based devices is a perfect way of experimenting and learning new skills, but sometimes you just want to add extra functionality to the device without writing a new driver each time. Sonoff Tasmota software is just that. If you wonder what can you do with the Tasmota Sonoff – take a look at the NEST-alike thermostat project.

Sonoff Tasmota software

The Sonoff Tasmota software can be flashed on most of the Sonoff devices. I’m going to use Sonoff Basic, which is, well… pretty basic. Out of the box, this $5 switch does 1 thing: turns the relay on and off. It has an Android/AppleOS support and integration with Alexa and Google Home.

Buy FT232RL Serial adapter

Buy it using these links to support NotEnoughTech.

This pretty basic gadget has an ESP8266 brain. This means, there is so much more potential inside that case. Before we get to the software part, take a look at the Sonoff Hacking guide where I show you how to backup and flash custom software.

The main advantages of the Sonoff Tasmota software include:

  • full local network compatibility
  • support for MQTT protocol
  • support for HTTP request
  • the utilisation of extra GPIO pins (GPIO14 on Sonoff basic)
  • support for most common sensors
  • OTA updates
  • Belkin WeMo and Phillips Hue emulation
  • Timers
  • Domoticz integration

As you can see, the list is impressive for free software that you can simply download off the internet. There is something missing on this list. There is no native integration for Alexa or Google Home. While this is a bummer (I’m pretty sure a commercial release of Sonoff Tasmota would include the licence for that), a bit of IFTTT tinkering will enable both.

Flashing Sonoff Tasmota

Easy Flash with Tasmotizer

Use the latest Tasmotizer Guide to flash and configure your tasmota device. It will save you time and headaches. Once flashed, send a config file (see that tutorial for details) with device configuration or follow the details below to configure your Sonoff manually.

This should take less than a minute. Once the firmware is flashed, disconnect the serial programmer and power the Sonoff Basic using the power cable (note that you won’t be able to get to the configuration page with the serial (RX/TX) connected.

Sonoff Tasmota Setup and configuration

To put the Sonoff Basic into the configuration mode you have to press the button four times (quickly, until the light is flashing). There is more than one function of the button, here is the breakdown:

Button press x timesFunctionLED behaviour
1toggle the relay ON/OFFblinks twice
2toggle the 2nd relay ON/OFF (if available)blinks twice
3Smart WiFi config using the Android appLED blinks
4Set Sonoff in AP modeLED blinks
5WPS setupLED blinks
6restarts the Sonoff 
7OTA download of firmwaresteady lit up
40secFactory reset 

Pick your way of adding the WiFi credentials and the Sonoff config page will be available under:

http://xxx.xxx.xxx.xxx/cn      //fill in the xxx with your Sonoff's IP

From there, things are pretty straightforward. Pick a menu, add your details, rinse and repeat until you are done.

Every menu option is clear and self-explanatory, you should not have any problems with the configuration. It’s worth noting your MQTT configuration, so you could set up the controls in NodeRED.

MQTT control

The full list of commands is available here. In a nutshell, to control the Sonoff device via MQTT protocol you have to configure the MQTT topics correctly.

Topic
%topic%  (sonoff)
sonoff/cmnd/power1   //controlling relay1 

Full topic
%topic%/%prefix%/
sonoff/stat/RESULT   //receiving status message

The query submitted back via MQTT looks like this:

object
  topic"sonoff/stat/RESULT"
  payload"{"POWER":"ON"}"
  qos0
  retainfalse
  _msgid"1fa18aa.7f0a575"

HTTP control

It is also possible (despite the MQTT being the default control protocol to control the Sonoff device with the HTTP requests. The requests will contain the username and password if you locked the Sonoff Tasmota web interface with it.

Here is an example:

http://xxx.xxx.xxx.xxx/cm?cmnd=Power%20TOGGLE
xxx.xxx.xxx.xxx = Sonoff's IP
Power = command type
TOGGLE = value

http://xxx.xxx.xxx.xxx/cm?&user=USERNAME&password=PASSWORD&cmnd=Power%20On
USERNAME,PASSWORD = use your web access credentials
xxx.xxx.xxx.xxx = Sonoff's IP
Power = command type
TOGGLE = value

The response given will contain a JSON object with the current device state. If you want to learn more about JSON I have the basic tutorial for you.

Sonoff Tasmota  – Google Home and Alexa integration

While the smart speaker functionality isn’t there, you can simply add the Alexa and the Google Home integration to your NodeRED setup. You can use IFTTT to send a web request, which in turn will transform your spoken command in a webhook.

Google Home, Sonoff Tasmota & IFTTT

Create an IFTTT trigger with a word phrase (don’t use Sonoff name, Google thinks you are saying “song off“):

Turn the switch $

And link this to a webhook:

https://(user):(pass)@NodeRED_IP:1880/sonoff

with a JSON type message:

{"sonoff":"{{TextField}}"}

Then use the HTTP POST (in) node in your NodeRED setup. The message containing ON/OFF will be stored under msg.payload.sonoff and you can use a function node to convert this for the full URL to control the Sonoff device:

var x = msg.payload.sonoff;
msg.url = "https://sonoff_IP/cm?cmnd=Power%20"+ x;
return msg;

Alexa, Sonoff Tasmota and NodeRED alexa-home node.

The alexa-home node is great, as you can add the devices very quickly. Log in and create a new device (ON/OFF) and drop the node into the NodeRED setup. The default message from the alexa-home is true/false – so I’m going to use switch node to monitor these replies and issue a correct URL for the HTTP POST request.

Buy Sonoff Basic R3

Buy it using these links to support NotEnoughTech.

Conclusion

Sonoff Tasmota firmware is a very quick and painless way of controlling Sonoff devices. It takes moments to set up and support for the MQTT and HTTP makes it compatible with most of the automation hubs. If you can live with the 3rd party smart speaker support you will be very happy with the transition to Tasmota based firmware.

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated in style with crypto-currency

Smart Ideas with

Automate your space in with these ecosystems and integrate it with other automation services

Learn NodeRED

NodeRED for beginners: 1. Why do you need a NodeRED server?

0
To server or not to server? That's a very silly question!

Best Automation Projects

ESP8266 WIFI lights under $5

0
Your Sonoff device can't do this!

Free wireless doorbell (Amazon Dash button hack)

0
The most terrifying situation I can imagine* is missing a parcel

New Amazon Dash Buttons

0
You can teach new buttons old tricks!

ESP8266 ceiling light – demo

0
Testing the ESP8266 as a WIFI light controller

Try Tasker and Raspberry Pi for your home automation needs!

0
Raspberry Pi can help you with your Tasker profiles

Smart Home

Best USB-C hack ever!

0
How to add USB-C charging to your old laptop without ruining it. USB-C hack for Lenovo Yoga

Sonoff Micro PLUS (USB-C hardware mod)

0
Sonoff Micro PLUS is a small modification that adds an USB-C port to Sonoff Micro - to make it even more useful!

Nora – Google Assistant in NodeRED

0
Integrate Google Assistant with NodeRED thanks to Nora - NodeRED home automation

“Inching” like a PRO (nodeRED edition)

0
Learn how to add inching to anything in NodeRED

Smart overnight charging with Tasker

0
Still keeping your phone plugged in overnight? Try smarter overnight charging with this profile