2019 Tech Tutorial Advent Calendar Day 12: Controlling Mains Appliances from Local MQTT broker using Sonoff/Tasmota (Patreon)
Content
"Sonoff" devices are cheap Wi-Fi controlled "smart switches" often used for smart home automation (Not to be confused with "Sonos" devices, which are an excellent Wi-Fi connected speaker system!). I thought they might be a useful way I could trigger power to mains devices in an escape room, by subscribing to MQTT messages published by my Node-RED ER control software.
The problem is that Sonoff switches don't work locally - they require a permenant internet connection, and are triggered from an external Sonoff server. That might be great if you want to integrate with Amazon Alexa or Google Home, but not so great if you'd rather have the security and control of using them on a private network or controlled by a local server application.
Fortunately, there's a (relatively) easy solution - using an FTDI programmer you can reprogram the ESP chip inside the Sonoff to use a custom Tasmota firmware instead - that lets you connect to a local Wi-Fi / MQTT broker instead, which can be triggered by your Node-RED flow. The new firmware also provides a web interface that you can connect directly to the IP address of your smart switch from, say, your mobile device to toggle power on/off. It's a little bit of a fiddly process, but, for the price, you end up with a pretty flexible Wi-Fi enabled mains relay.
You can buy a Sonoff basic switch for around $5 from https://www.banggood.com/custlink/DmmvAcybbb
You'll also need an FTDI programmer to flash new firmware onto the Sonoff chip, which is around $2.50: https://www.banggood.com/custlink/v33DQcEQkE
Download the latest Tasmota firmware from https://github.com/arendst/Tasmota/releases
The software I used to flash the new firmware onto the Sonoff is called "Tasmotiser", available from https://github.com/tasmota/tasmotizer/releases
A full guide is also available from https://tasmota.github.io/docs/#/installation/