HomeHome AutomationUsing 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 with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

Smart Ideas with

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

client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image

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

Tuya SDK for beginners: Intro to Tuya Cloud API

0
Working with Tuya Cloud API. A guide to Cloud automation for beginners, get started with REST!

NEST your old thermostat under $5

0
Nest-ing up your older thermostat under $5

Nora – Google Assistant in NodeRED

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

Sonoff Zigbee Bridge – review

0
Sonoff line up will soon include Sonoff Zigbee Bridge and more Zigbee sensors - here is the first look

DIY Smart Washing Machine – for about 15 bucks!

0
Learn how to add washing machine notifications to your Google Home on the cheap

Smart Home

We’ve seen this before: SwitchBot K10+ PRO

0
This is an odd one. Building on the success of SwitchBot K10+ they released SwitchBot K10+ PRO - but is the experience actually better?

Is this the smart panel we have waited for?

0
ITEAD has released a new smart panel: Sonoff NSPanel Pro 120 - have they learned the lesson from the terrible launch of the original Pro? Let's see what's new.

Aqara FP1E detects motionless humans

0
This isn't exactly a new device, it's an interaction of the original Aqara presence sensor. Aqara FP1E brings Matter, ZigBee and new triggers to your smart home

SwitchBot S10: cleaning re-imagined!

0
SwitchBot S10 promises unattended vacuuming and mopping so you can focus on things you love and care for. Does it deliver?

Sonoff for households and gardens

0
ITEAD released two ZigBee devices to manage water in your household and gardens. Now you can monitor the flow and dispense water with Sonoff SWV and prevent water damage using the Sonoff Water Leak sensor with a twist.