Skip to content

Sonoff switches

Alex Lennon edited this page Apr 16, 2019 · 20 revisions

Espurna is the firmware that's been flashed onto the Sonoff switches (both the basic model and the POW2 power measuring unites) that can be wired into the mains cable supply of any device (fan, computer, laser cutter, kettle, etc).

NB. The release build of Espurna does not support client mDNS name resolution. This means you can't use a local DNS name of the form mqtt.local for the MQtt broker server. We wish to do this rather than track IP addresses so it is necessary to update a Sonoff device with a boiler-plate Espurna build with a custom build with mDNS turned on. I have archived build here. You can use the OTA build here for over-the-air update using the Espurna webUI but settings seem to be lost in the process.

To rebuild the Espurna firmware with Platform.IO follow the instructions here. The change you need to make to enable mDNS is here.

Table of known devices

host device ssid thing (ip number) mDNS
ESPURNA-8E010B ITEAD_SONOFF_POW_R2 DoESLiverpool VR computer 10.3.141.199 Y
ESPURNA-8E30FD ITEAD_SONOFF_POW_R2 DoESLiverpool Sophia laser 10.0.38.12 Y
ESPURNA-8DFA32 ITEAD_SONOFF_POW_R2 DoESLiverpool Gerald laser 10.0.38.11
ESPURNA_4EAD1D ITEAD_SONOFF_POW DoESLiverpool Coffee machine 10.3.141.164
ESPURNA_8DF40E ITEAD_SONOFF_POW_R2 DoESLiverpool Coffee machine (2) 10.0.38.3 Y
ESPURNA-A7A42B ITEAD_SONOFF_BASIC DoESLiverpool Electric Hob
ESPURNA-5A7CD9 ITEAD_SONOFF_POW_R2 DoESLiverpool Ultimaker Felicity 10.3.141.122 Y
ESPURNA-8DFE16 ITEAD_SONOFF_POW_R2 DoESLiverpool Ultimaker Adam 10.0.38.7 Y
ESPURNA-5483B8 ITEAD_SONOFF_POW_R2 DoESLiverpool CNC Machine 10.0.38.6 Y
ESPURNA-6821B6 ITEAD_SONOFF_POW_R2 DoESLiverpool Fridge 10.0.38.5 Y

Operating through a webpage or MQTT

The mDNS lookup on the espurna/sonoff plugs doesn't work, so we have to program in the ip number directly.

mqtt.local on DoESLiverpool wifi is 10.0.29.167 (this can change, which is a problem) mqtt.local on DoESLiverpool-MQTT is 10.3.141.1 (stable as it's the Rpi wifi, but weak signal from one device without an )

The last 3 bytes of the mac address is written on the box. If it successfully connects, you can get the ipnumber of it by doing: mosquitto_sub -v -h mqtt.local -t "+/ip" Commands to set the plug start are: mosquitto_pub -t ESPURNA_A6F5FA/[relay|led]/+/set -m [1|0]

You can then get on to the espurna dashboard (a webpage served by the sonoff/esp8266 device) at that ipnumber with username admin, password bubbl1n0 where you can get a very comprehensive web interface to chane any settings, like wifi connections, power reading interval, pre-programmed on-off schedule, etc.

Wiring and setting up

To set one up, cut a cable and wire up the connections remembering that there is a Live Brown bear under the Neutral Blue sky on the Green/Yellow Earth.

Then connect to its hotspot, password is fibonacci, then go to 192.168.4.1 where the user is admin, password is fibonacci. The page forces you to change it immediately, so set it to bubbl1n0.

Because we want lots of good data, go to Sensors and set the Read interval to 1 second, Report every 1, and then Save. Go to MQTT and do Enable MQTT (easy to forget this one), set MQTT Broker to 10.0.29.167 or 10.3.141.1 depending on wifi network to be connected to and Save. Go to Switches and set Boot mode to Always ON (esp if it's for power monitoring rather than control). Go to WIFI and then add either the DoESLiverpool or DoESLiverpool-MQTT network. It's useful to write the lower 6 hex characters of the mac address onto the box with an indelible marker that are used to create its default device name.

Tip: It is useful to note down part of the mac address early so if it doesn't connect to the MQTT-broker you can still find your device using a command like "sudo arp-scan 10.0.38.0/24" and then set it properly.

Clone this wiki locally
You can’t perform that action at this time.