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 Y
ESPURNA-8E30FD ITEAD_SONOFF_POW_R2 DoESLiverpool Sophia laser Y
ESPURNA-8DFA32 ITEAD_SONOFF_POW_R2 DoESLiverpool Gerald laser
ESPURNA_4EAD1D ITEAD_SONOFF_POW DoESLiverpool Coffee machine
ESPURNA_8DF40E ITEAD_SONOFF_POW_R2 DoESLiverpool Coffee machine (2) Y
ESPURNA-5A7CD9 ITEAD_SONOFF_POW_R2 DoESLiverpool Ultimaker Felicity Y
ESPURNA-8DFE16 ITEAD_SONOFF_POW_R2 DoESLiverpool Ultimaker Adam 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 (this can change, which is a problem) mqtt.local on DoESLiverpool-MQTT is (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 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 or 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" and then set it properly.

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