SonOff POW

Two weeks later then I ordered on banggood.com, my SonOff POW is arrived. I bought it to measure electricity consumption of my water heater and to control it remotely.

SonOff POW

I started testing with my table lamp. I could start controlling it with eWeLink Android client in a couple of minutes. I could not just turn on and off my 230 V device in a single click on my phone but see current electricity consumption as well as scheduling future events.

Wiring

SonOff connects to its own IoT cloud provided by itead. Commands can be issued exclusively over its cloud. This is good because it's Plug&Play but privacy is another question. With some hack, you can change your cloud endpoint to a self hosted nodejs one, for example.

Because I did not found a way to communicate with my SonOff from a Bash script, neither via its cloud nor directly inside my LAN,  I started to investigate Tasmata firmware. Okay, actually I found a way, but it seemed it is too complicated especially if I taken into account that privacy concerns. Maybe I'm paranoid but I want to keep my infrastructure manageable only by me.

Tasmata is an open-source, free firmware with Web UI and MQTT support. It also has a quite good documentation.

With Tasmata firmware, SonOff provide a Web UI with a REST API and can connect to MQTT message borker to send telemetry data and receive commands. If you are message bus enthusiast you can find an easy-to-use MQTT server solution here. In my case, this telemetry data would be a really good fit to collect metrics from my boiler or my temperate sensors, but now I wanted to go only with REST.

Because I'm lazy and I didn't want to solder, I chosen OTA (Over-the-Air) firmware upload. Most of the available documentations on the Internet sad I won't be able to go with OTA because of my too new firmware version. I thought it's already doesn't matter so I updated the firmware in its official way with eWeLink to the latest 2.0.4 version.

What was really weird is WiFi MAC address what was changing after each of the firmware updates. I use MAC address filtering on my wireless network for extra security which in this case caused some problems when SonOff POW tried to connect to my LAN wirelessly always with a new MAC. SonOff has only two LED which cannot provide so much information about the events inside, especially MAC address changing.

Important takeaway: If you use MAC authentication on your WiFi turn it off before you start to play with SonOff.

I'm a Windows user but in Tasmata Wiki there are Linux guide so I grabbed an Ubuntu VM and attached a USB wireless adapter. I also grabbed a wireless AP and configured it as the guide sad to provide network with indebuurt1 SSID. This is the so called temporary network which must be hardcoded to the SonOff devices. With Tasmata FW you will be able to override this as well.

To keep it simple, this indebuurt1 AP was connected to my home network where my VM was bridged to on wire.

At this point, there's no magic, I just followed the Tasmata guide: brew, git, pip3, wget, unzip, bla bla bla. I won't copy that here :)

Then I started sonota.py too, turned on my SonOff, pressed the button while WiFi AP appeared and I connected to it. Fine. I thought this is easy and I'll done soon but no. No because when my device started downloading new firmware by OTA from my VM, I got python exception. Why?

I tried again several times. At a point something happened and it seemed my device bricked. When I pushed the button my lamp turned on and off what was followed by the red LED on SonOff but that's it.

I already soldered cables to flash from serial when I found this page about the button usage.

serial connectors

Very useful. I played a bit with the button and successfully initiated AP mode. I connected to that AP, opened http://192.168.4.1 and just realised I have a minimal version of Tasmata firmware installed. Fine.

Minimal Tasmata

I changed WiFi network parameters to my home network. I downloaded normal version and In a second round I uploaded it via web. Success.

normal tasmata

At this point, I have set up in the configuration point this is a POW device, calibrated it as described here and that's it. I'm sure, this is not an industrial grade device: measurements might be not the most precise ones ever but fairly okay.

The best part was when I finally integrated electricity consumption of my water heater into my existing Grafara with a little Bash script.

$ curl 'http://sonoff/cm?cmnd=Status+8' -qs

{
   "StatusSNS":{
      "Time":"2018-03-04T10:37:10",
      "ENERGY":{
         "Total":9.857,
         "Yesterday":4.307,
         "Today":5.550,
         "Power":1769,
         "Factor":0.96,
         "Voltage":231,
         "Current":8.009
      }
   }
}

Below diagram shows the evening when and after my family had a shower: my boiler has a cca. 1.7 kW heater which is around 8 A on 243 V. One evening caused 7.59 kWh consumption.

grafana

Ah and one more thing: Tasmata firmware can send logs into syslog-ng. With it I can collect logs at the same place as I do it with my other network elements.

Reference: