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.
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
- 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
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 times||Function||LED behaviour|
|1||toggle the relay ON/OFF||blinks twice|
|2||toggle the 2nd relay ON/OFF (if available)||blinks twice|
|3||Smart WiFi config using the Android app||LED blinks|
|4||Set Sonoff in AP mode||LED blinks|
|5||WPS setup||LED blinks|
|6||restarts the Sonoff|
|7||OTA download of firmware||steady lit up|
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.
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:
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:
with a JSON type message:
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.
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.