Experiments with smart house equipment

As usual men, I have 3 goals: plant a tree, grow a son, ant build the house. First one is done, second one is in progress, so it’s time to start third one. I’m little bit IT guy, so thinking about smart house. Digging around the internet, I found cheap smart switches, whose may help to improve house characteristics, ant make it smarter. Here they are:

I ordered some of them, to test build quality, and possibility to integrate with central smart house control system. From first view, they looks futuristic, have touch interface, works on wifi, let’s try to integrate with home automation system.

By default, these switches can be controlled over smart phone app, or directly by touch button. App is created by manufacturer, and has no possibility to integrate with home automation system. Also, communication works over internet with third party server, which stands over the ocean, so it’s not the best idea to trust this design. So, lets improve this design, with opensource solutions. Browsing github, I found project, which are ideal for my requirements: https://github.com/arendst/Sonoff-Tasmota

Main features required: works ower wifi, can be controlled over MQTT broker, and best of the best: can be flashed/upgraded over OTA. Few weeks ago, when I discovered this project, firmware upgrade procedure was (or I thought that it was) complicated, as additional programming pins should be soldered. This is not big issue, as these devices has lot of space to solder programming pins, but later I had big success, finding that these devices can be upgraded over OTA: over-the-air upgrade. So let’s start to hack this device:

First of all, I need to prepare laptop for this task:

  1. install python 3.5 in windows 10 (yes, I know, windows is not the best option for home use, but this is another topic) 🙂
  2. download magic sonOTA script: https://github.com/mirko/SonOTA
  3. install required libraries for sonOTA: pip3 install –user -r requirements.txt
  4. start the magic stript: python sonota.py, read instructions in console and let the magic happen.

In short, this script will push opensource firmware over OEM upgrade channel. Detailed instruction are written in hithub, so I don’t rewrite it here. After upgrade, smart switch was connected to home wifi network, got IP address and publishes web page, where you can configure various settings, as mqtt server address, smart switch hostname and other fancy stuff.

In my lab, I have Raspberry, running Openhab as smart home automation system, ant Mosquitto as MQTT server. So the last step, is to integrate smart switch to the smart home. As this smart switch has MQTT support, this task is easy. first of all, I created new item in Openhab:

Switch jungiklis <light> {mqtt=”>[openhab:Light/sonoff/cmnd/power:command:ON:1],>[openhab:Light/sonoff/cmnd/power:command:OFF:0],<[openhab:Light/sonoff/POWER:state:ON:ON],<[openhab:Light/sonoff/POWER:state:OFF:OFF]”}

Second, include this item to sitemap:

Frame label=”Apsvietimas”{
Switch item=jungiklis label=”ApÅ¡vietimas” mappings=[ON=”Ä®jungtas”, OFF=”IÅ¡jungtas”]

Vualia, now I can control room light with touch button, or over my phone via Openhab, or can create some automation script, and let smart home control lights automatically, is it not fancy? 🙂