A few months ago we purchased a new, bigger place. With this comes an excuse to automate-all-the-things!

Hardware

For controlling the lights, I decided to use the sonoff mini for this project opposed to the sonoff basic that I have used in the past.

The form factor is small, the screw terminals are far better by a factor of 1000-1. Whats more, custom firmware can be flashed OTA without the need to expose the serial pins *. However, flashing OTA on any OS other than Windows is troublesome (we’ll get to that)

  • Sonoff Mini can still be flashed using serial, see tasmota sonoff-mini

Flashing using OTA method on Linux (AKA cUrl method)

This won’t be a detailed instruction from start to finish, but there are a few requisites before we can begin:

  • eWelink firmware on the Sonoff is running at least 3.1
  • DIY mode jumper is inserted
  • You have a Wifi AP or Mobile Hotspot with the SSID sonoffDiy and password 20170618sn
  • Your Linux machine and the Sonoff is connected to the same hotspot/AP
  • Your Linux machine is running some form of webserver (lighttpd is a lightweight choice)
  • Your Linux machine has the IP address of 192.168.10.10

Download one of the pre-compiled binaries eg. (tasmota-lite.bin) from the tasmota releases and copy it into /var/www/html/sonoff/tasmota-lite.bin

Obtain the deviceid of the sonoff mini

We will use avahi-browse to obtain the deviceid and the IP address of the sonoff

avahi-browse -t _ewelink._tcp --resolve

should return

+ wlp1s0 IPv4 eWeLink_10000qwerty                            _ewelink._tcp        local
= wlp1s0 IPv4 eWeLink_10000qwerty                            _ewelink._tcp        local
   hostname = [eWeLink_10000qwerty.local]
   address = [192.168.10.11]
   port = [8081]

Our device id 10000qwerty

Enable OTA updates

curl http://192.168.10.11:8081/zeroconf/ota_unlock -d '{"deviceid":"10000qwerty","data":{}}' 

should return

{"seq":2, "error": 0}

Get sha256sum of firmware

$ sha256sum /var/www/html/sonoff/tasmota-lite.bin

returns (obviously, this will differ based on which file you use)

aa413f499233901f74502558561a1304e2a3d7ab72259740b377f52775adbb5d

Flash firmware

curl http://192.168.10.11:8081/zeroconf/ota_flash -d '{"deviceid":"10000qwerty","data":{"downloadUrl":"http://192.168.10.10/sonoff/tasmota-lite.bin", "sha256sum":"aa413f499233901f74502558561a1304e2a3d7ab72259740b377f52775adbb5d"}}' 

should return

{"seq": 4, "error": 0}

Once completed, you can connect to the wifi hotspot the tasmota firmware starts and perform the tasmota initial configuration

What’s next?

In the next installment, we will run our own MQTT server and write some basic Python wrappers to perform some basic Hello World tasks such as Turning On and Off the light and reading the GPIO switch state via MQTT.