Please, proceed carefully following the tips published in this blog, specially when Main Power is involved. I'm not responsible for any damages caused by what is written in this blog.
Thank you

Wednesday, 26 July 2017

Home Automation System - Configuring the SONOFF with Tasmota Firmware

I'm ready to test TASMOTA firmware, just uploaded on my SONOFF POW.

You can find the upload procedure in my last post (http://domoticsduino.blogspot.it/2017/07/home-automation-system-first-sonoff.html). It was fine...From now on we couldn't restore the original firmware and we couldn't use the EWeLink App anymore

Hoping that the SONOFF will power up :)

Now, I will plug all the things together...paying attention to the Main Power

I use the following diagram (thanks to the official site...):

To perform the first test, I used a plug connected to the INPUT terminals of the SONOFF (L = Line, N = Neutral, E = Earth). Then I took an old lamp holder, connected to the OUTPUT terminals. Last thing to do...find a load...here is it...an old 100W bulb.

I connected the plug and the SONOFF powered up. The blue led flashed a couple of times and then shut off.

The first thing to do is configure the WIFI connection; there are two ways to do this task: the one I followed is performed using the web console; the second one is performed writing the WIFI SSID and PASSWORD on a config file, prior to compile and upload the firmware (here you can find more detail https://github.com/arendst/Sonoff-Tasmota/wiki/Upload#preliminary-configuration)

So, I use the capabilities of the push button to transform the SONOFF into an Access Point and access it through the web console

Following this guide

I discover how to use the button. In particular, the "4 short presses" procedure permits me to activate the access point and the integrated web server, so it becomes reachable and configurable.

Then I push the button 4 times and a new Wifi connection brings on...SONOFF XXXX...I join this network using a PC and browse on a browser. The configuration panel is in front of my eyes

I typed the WiFi details, named the device, saved and restart.

After a couple of seconds, the SONOFF joined my home WIFI network and takes a DHCP assigned local IP.

Through this IP, I could get the configuration panel again.

Here is it:

Clicking on Toggle SWITCH the bulb lights up...the web page display the current power consumption...another click and the bulb turns off. The device is working as expected...thanks god :)

Reading the TASMOTA docs, I found a procedure to calibrate it.

See https://github.com/arendst/Sonoff-Tasmota/wiki/Sonoff-Pow#calibration

In the next step I'll try the MQTT protocol.

Stay tuned

Sunday, 23 July 2017

Home Automation System - The first SONOFF - Uploading firmware

Ladies and Gentlemen, I'm glad to introduce you my first sonoff: the SONOFF POW

After a rapid test with EWeLink App I'm sure the device is working well; I'm ready to upload the TASMOTA firmware, to enhance the sonoff functionalities, in particular the MQTT protocol.

I borrow from Piero the USB-Serial adapter, because mine is still "in transit"...

Here is it: one thing to check is the jumper near the 4 serial pin...it has to be in the 3.3V position...

I open the website https://github.com/arendst/Sonoff-Tasmota/wiki, download the software and follow the step-by-step procedure.

I like Arduino IDE and so I decided to use it, instead of PlatformIO, so I follow the section "Arduino IDE Preparation" on wiki (https://github.com/arendst/Sonoff-Tasmota/wiki/Prerequisite#arduino-ide-preparation).

Now, it's time to solder the serial pins on the sonoff, so the board will be removed from the plastic case. In the Sonoff POW the serial interface is at the end of fhe board, near the phisical button.

See Hardware Preparation

You have to pay attention at the serial connections between adapter and board...

TX -> RX
RX -> TX

Thanks to Piero again, I can use a connector with colored cables which is already configured for the sonoff mapping

Using a MicroUSB - USB cable, I plug the adapter in the PC and install the FTDI driver. The sonoff must be restarted in "programming mode", keeping its button pushed for 2 or 3 seconds.

During this phase (and everytime the serial connection is plugged), the sonoff MUST BE disconnected from Main Voltage

If everything is OK, the device is ready for the firmware upload process.

Using the Arduino IDE, in just a couple of minutes the firmware will be uploaded on device (see Upload).

Now we are ready to play the game :)

Saturday, 22 July 2017

Home Automation System - Discovering sonoff

In the last few months, thanks to Piero's suggest, I discovered some small device called SONOFF, by iTead https://www.itead.cc/smart-home.html

In simple words, they are low-cost wifi controlled relays. A basic switch is less than 5 euro!

The following products, among others, are the most interesting, for my purpose:

Sonoff Basic: a standard switch - https://www.itead.cc/smart-home/sonoff-wifi-wireless-switch.html

Sonoff Pow: a standard switch with power consumption measurement - https://www.itead.cc/smart-home/sonoff-pow.html

I bought them on eBay, for testing purpose.

These devices are easily configurable and ready to use; just connect them to the power. The onboard firmware let them be controlled by a mobile APP (iOS and Android), called EWeLink. A step by step procedure helps user to pair the device to the home wifi network (mandatory...). The devices will be controlled directly through internet, using an Amazon AWS server managed by iTead.

This is a simple guide: https://www.itead.cc/wiki/EWeLink_Introduction

This is a simple and rapid mode to operate with these devices; but if your home network is offline, they stop working.

Furthermore, to get all the capabilities of these devices, you need a custom firmware, because the original one is not so open. For example, you cannot integrate sonoff devices in a Home Automation System like OpenHAB or Domoticz

So, my first step was googling for "Sonoff Firmware"...Bingo!

To be simple, Sonoff is a device built on ESP 8266 chip, so it's easily programmable (as Arduino board) and you can find many free custom firmware: you choose it according to your needs or experience...

I chose this one:

Sonoff-Tasmota firmware: https://github.com/arendst/Sonoff-Tasmota

At the first glance, it seems the most complete, for my purposes..It allows to control the device by MQTT, Web and Serial Communication.

Please, take a look at the official Wiki page:


About MQTT, I can suggest you to take a look at the official website: http://mqtt.org. It is a very useful protocol to manage IoT messages.

In a nutshell, MQTT is a connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is based on a central service, called broker, which receives published messages and forward them to the subscriptors. Every message is published on a particular "topic" and only the subscriptors of that topic will received it.

So, we have to manage another service, the MQTT broker. But don't worry about that, it's very simple and also Raspberry PI is able to run this service (Mosquitto https://mosquitto.org is one of the best...). Just for testing purpose you can use a free public MQTT broker, but I discourage you to use it for your real Home Automation System

After choosing the firmware, just upload it on the chip.

WARNING...you will lose the original firmware and you will not be able to upload it back; will no longer be possibile to use the EWeLink app again

The custom firmware will be upload using the serial interface on the sonoff, through a 3.3V USB-Serial adapter. I bought one on banggood. You could upload the firmware using the Arduino IDE or PlatformIO. Please follow the step by step guide provide by the firmware developers.

Before, we spoke about Home Automation System. I suggest you 3 system I tried:

Home Assistant - https://home-assistant.io

There are many others...the final choice it's up to you. Internet has lots of information and guide to assist you...

I chose OpenHab v.2; in my opinion it's the most versatile one (but I could be wrong :) ).

Shortly I will publish the results of the first tests performed with SONOFF

So, please, Stay Tuned