Thoughts of a geek

24 December 2018

Smart homes and ESP8266s

Filed under: Computers, Electronics — Tags: , , , — qwandor @ 11:42 pm

I’ve recently been playing with a bunch of smart home stuff, based around the Google Home ecosystem. I have a Google Home, Google Home Hub and JBL Link View in various rooms, a Chromecast and Chromecast Audio, a Nest thermostat, a bunch of cheap smart light bulbs, and some Sonoff switches for the ceiling lights. It’s pretty cool: I can control the lights and music all around the house by voice, from the smart displays, or from my phone.

But there are a few things missing. As cool as voice control is, sometimes I just want to press a button and have it run some preset action, like turning all the living room lights off late at night when I’m heading up to bed (without waking up my housemates), or turning on all the fairy lights for a party (when the background noise is too loud for voice control to work reliably, and it’s a bit awkward anyway).

Happily, AliExpress has lots of ESP8266 dev boards from as little as £1.70. The ESP8266 is a little microcontroller with a WiFi stack and fairly low power requirements that makes creating WiFi-attached gadgets pretty easy. It can be programmed (among other options) in C++ with with the Arduino libraries. For a nicer development than the standard Arduino IDE I used PlatformIO, which adds a proper IDE and dependency management.

My first approach was a stand-alone button. This can be battery powered, and stays in a low-power standby state (or entirely off, with a little extra support circuitry) until it is reset, at which point it starts up, connects to WiFi, sends a command, and goes back into standby (or powers down). This works well, though I didn’t get as far as finding a nice way to package it up. Without making custom hardware it’s a little bulky, with the battery and everything.

An ESP8266 dev board connected to a Li-ion battery.
An ESP8266 dev board connected to a rechargable battery.

So I tried a different approach. The Sonoff RF Bridge is widely available on AliExpress and elsewhere for under £10. It contains an ESP8285 (basically the same as the ESP8266 but with built-in flash) and a 433MHz remote transmitter and receiver controlled by a separate microcontroller, connected over the serial port with a documented protocol. With the stock firmware it can clone your existing remotes to control whatever devices you may have controlled by 433 MHz remotes, which was not very useful to me. However, the firmware can easily be replaced by simply opening the case (4 screws) and soldering on a 4 pin serial header to the labelled row of holes on the PCB. AliExpress also has lots of nice wall-mounted 433MHz RF buttons that look like normal light switches and can last a long time on a small battery.

With that in mind, I built some replacement firmware for the Sonoff RF Bridge, that lets you pair it with many such buttons, and associate each one with a different command to send. This works really well! I have the RF bridge sitting plugged into USB power somewhere out of the way, connected to my WiFi, and waiting for signals from the buttons I now have mounted around the house to send commands.

A Sonoff RF Bridge connected to USB power.
My RF Bridge glowing happily in the corner.

What I haven’t mentioned so far is how I send commands. Google Home doesn’t yet have a proper API to connect buttons like this, but what there is an API for is sending Google Assistant commands from other devices. These can be either voice or text; of course in this case I went with text. So when one of the buttons is pressed, I can send an arbitrary Google Assistant command, like “turn off the living room lights”. It takes a couple of seconds to respond, but otherwise works pretty well.

If you’d like to try either of the above, you can get the source code here, along with some more documentation of how to set it up. Once you’ve flashed it onto your device there’s a web interface which should make it easy to connect to your WiFi, authenticate your Google account and set up whatever commands you want.

If you do try it, please let me know if it’s useful! Or if you have any trouble getting it working or find any bugs, let me know too.

Next up (and in the same repository above, if you can’t wait), how I control lots of fairy lights. Until then, have fun, and Merry Christmas!

Advertisements

1 Comment »

  1. […] to make them mains powered, and controlled from Google Home. And as I mentioned in a previous post, I’ve been playing with ESP8266s recently, so I built a controller based on the D1 mini […]

    Pingback by Fairy light controller | Thoughts of a geek — 25 May 2019 @ 12:34 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: