Posted on 23 Comments

Vlog #63: Australia, worst place in the world for DIY home automation

Is it true that DIY electrical work can invalidate your home insurance policy? Can you go to prison for replacing the plug on a power board?

In Australia: yes. With the harshest restrictions in the world, Australian regulations don’t let you do anything unless you complete a 4 year apprenticeship, complete some certifications, and become a licensed electrician. It doesn’t matter that I’ve designed satellite payloads and that products I’ve designed have had more than a million units manufactured. Without completing a 4 year apprenticeship, there is no legal path for me to become certified to replace the plug on a power board.

Crazy.

And to top it off, clauses in your insurance policy that don’t seem to have anything to do with electrical safety can allow your insurer to refuse any claims that could be related to DIY electrical work.

If you’re into home automation, check out Rob’s YouTube channel, The Hook Up.

Posted on 32 Comments

#31: Sonoff Tasmota installation and configuration

Make the Sonoff smart power controller even more awesome by installing the Tasmota open source firmware.

Tasmota adds many new features, and allows you to integrate Sonoffs into an existing home automation system without relying on external cloud services. It includes MQTT support, Belkin WeMo emulation, easy configuration using a web browser, and you don’t even need a compiler or IDE to install it.

Note: Since this video was released, the Tasmota project has changed its build process so that the binaries are now called “tasmota” instead of “sonoff”. I have edited the text instructions below to match, but screenshots and the video still refer to the old name.

Step 1: Prepare hardware for flashing

To load new firmware onto a Sonoff, you need four pieces of hardware:

  1. A compatible Sonoff model or equivalent (more than 50 devices are supported by Tasmota)
  2. A USB-to-Serial converter that can run in 3.3V mode (don’t use a 5V converter!)
  3. Jumper wires or a programming adapter to connect the USB-to-Serial converter to the Sonoff
  4. A computer with WiFi. You can use a mobile phone for the WiFi steps if you prefer.

You can make the connections using jumper wires and the instructions in my previous video, or you can use my handy little programming adapter. Both methods do exactly the same thing: my programming adapter just makes it neat and easy.

Make sure the Sonoff is totally disconnected from any mains power.

Don’t proceed unless you have done that! Connecting your computer to a Sonoff while it is connected to mains is extremely dangerous.

Details of the electrical connection are shown in the previous episode, so check that out if you need more information.

Step 2: Download Tasmota

The Tasmota firmware and its documentation is available at github.com/arendst/Sonoff-Tasmota, including both firmware and pre-compiled binary releases. If you want to compile the code yourself that’s fine, but you don’t need to if you just want the latest version. The binary releases are at:

 github.com/arendst/Sonoff-Tasmota/releases

There is a big list of binaries for each release, which can be confusing if you don’t know which one you need. The binaries fall into several categories which are outlined on the releases page.

For most devices, you should choose the binary called “tasmota.bin” which includes all the features required for the majority of compatible hardware.

The binaries with 2-letter country codes appended, such as “tasmota-IT.bin”, have the exact same functionality as the standard “tasmota.bin” but with different languages for the user interface. If you want to run Tasmota in a language other than English, select the appropriate “tasmota-XX.bin” file.

Whichever version you select, download it to your computer.

I prefer to rename the binary file so that it includes the release version, such as “tasmota-8_4_0.bin”. That way if I come back to it later, I can see what version I downloaded.

Step 3: Download and install esptool

Esptool is a utility that can be used to read and write the flash memory on devices using the ESP8266 and ESP8285 microcontrollers, including all current Sonoff models. It’s written in Python so you will need a working Python environment on your computer.

You can download esptool from github.com/espressif/esptool.

Follow the instructions on that page to install it on your computer.

Step 4: Find serial device

Your USB-to-Serial converter connects to your computer by USB, and appears to the computer as a virtual serial port. The exact location of the virtual serial port will vary depending on the type of converter that you have, what operating system you use, and which physical USB port you plug the converter into.

If you have the Arduino IDE installed, a good way to find the location of the virtual serial port is to start the IDE, look at the ports list in Tools -> Port, then plug in the converter and check the ports list again to see if a new port has appeared.

On my Mac, the port appeared at /dev/tty.usbmodem14201, so I’ll use that in the following examples.

Step 5: Put Sonoff into bootloader mode

Disconnect power from the Sonoff, hold the GPIO0 pin low, and reconnect power. Then release GPIO0. This process is explained in detail in the previous video.

This will put the Sonoff into a mode where it waits for new firmware to be loaded.

OPTIONAL Step 5b: Back up original firmware

If you want to make a backup of the original firmware so you can restore it back to factory-original later, jump to the addendum near the bottom and then return here. Otherwise, carry on!

Step 6: Upload the Tasmota firmware

Open a terminal, and go into the directory where you have the Tasmota binary. Use esptool to push it to the Sonoff using the serial port location that you found earlier:

esptool.py -p /dev/tty.usbmodem14201 write_flash -fs 1MB -fm dout 0x0 tasmota-8_4_1.bin
  • The “-p” parameter sets the serial port
  • The “write_flash” command tells esptool to send new data to the flash memory
  • The “-fs” parameter is the flash size. Put this parameter in if you know it. If you don’t, you can omit this parameter and esptool will attempt to auto-detect the flash size for you
  • The “-fm” parameter is the flash mode to use
  • The “0x0” parameter tells esptool to start writing into flash from address 0
  • The final argument is the binary image to load

Uploading the binary takes about 30 seconds.

While esptool is doing the upload it will report useful information about the hardware in your Sonoff, including the MAC address. This can be extremely useful if you want to put a DHCP static lease into your router fix your Sonoff to a specific IP address. You can copy and paste the MAC address out of the terminal and save it in a document or spreadsheet for future reference if you want to.

Step 7: Connect to Sonoff via WiFi

Disconnect the Sonoff power power, then reconnect it. When the Tasmota firmware starts up and doesn’t find any existing configuration, it goes into a setup mode and creates its own WiFi network. The network will have a name similar to “Tasmota-6392”, with the 4 digits based on the last part of the unique MAC address of the Sonoff hardware.

On your computer or smartphone, go into WiFi settings and look for a network with a name similar to this. Make a note of the network name, because you will need it in a moment!

Connect to the Sonoff’s WiFi network without any username or password. Your computer should then automatically open a captive portal, with a WiFi configuration screen for the Sonoff.

Enter the WiFi settings for your normal network into the Sonoff. You can enter them directly, or you can click the “Show wifi networks” link to have the Sonoff scan for available networks so that you can select the right one and then enter the password manually.

Enter the details, and click “Save”.

The Sonoff will then reboot and attempt to connect to your normal WiFi network.

This will cause your computer to drop off the temporary WiFi network that was created by the Sonoff, and reconnect to your normal network.

Step 8: Connect to Tasmota configuration interface

Open a web browser, and enter the address of the Sonoff using the network name that you noted in Step 7 with “.local” added to the end. For example, the address could be something like

tasmota-6392.local

This will open a configuration interface where you can view information about the device, change its settings, backup and restore the configuration, install firmware updates, and control the output.

Many of the configuration options are explained in the video. Explore the menus and set up the Sonoff to suit your home automation system.

Addendum: Reconfiguring from scratch

If your home WiFi changes or you take the Sonoff to another location, it will keep trying to connect to the network that you originally configured and you won’t be able to control it.

If this happens, you don’t need to re-flash Tasmota. Instead, you can put it into WiFi recovery mode.

Tasmota can use the button on the Sonoff to put it into special modes. If you quick-press the button 4 times, it will restart the setup process and create its own WiFi network again just like in step 7. Then you can connect to its WiFi, and give it new details so it can connect to your main WiFi network again. Your other settings will be retained so you don’t need to set them again.

If you press and hold the button for more than 40 seconds, Tasmota will clear all its settings, reboot, create a WiFi network, and begin the setup process from scratch.

Other things you can do with the button are explained at github.com/arendst/Sonoff-Tasmota/wiki/Button-usage

Addendum: Backing up and restoring original EWeLink firmware

If you want to keep the option of returning the Sonoff to factory-original condition, you can download the original firmware out of its flash memory and save it for later use. Obviously this has to be done BEFORE you flash Tasmota onto it!

Do everything up to Step 5, but DON’T continue with Step 6. Instead, use esptool to determine the flash size of the Sonoff. Using your own serial port address, run a command like this:

esptool.py -p /dev/tty.usbmodem142101 flash_id

This will give a result that looks something like this:

jon@Jonathans-MacBook-Pro:~/Downloads$ esptool.py -p /dev/tty.usbmodem142101 flash_id
esptool.py v2.6-beta1
Serial port /dev/tty.usbmodem142101
Connecting….
Detecting chip type… ESP8266
Chip is ESP8266EX
Features: WiFi
MAC: dc:4f:22:2b:c8:63
Uploading stub…
Running stub…
Stub running…
Manufacturer: e0
Device: 4014
Detected flash size: 1MB
Hard resetting via RTS pin…

You can see the result “Detected flash size: 1MB” near the end.

The Sonoff will have reset back into normal mode, so put it back into bootloader mode in the usual way, then use a command like this to download the existing flash memory and save it in a local file:

esptool.py -p /dev/tty.usbmodem142101 read_flash 0x0 0x100000 sonoff-ewelink.bin

Pay attention to the value “0x100000” above. That example will read the flash starting at address 0, and continuing on to the 1MB point. If you have a 2MB flash, you’d use “0x200000”, for example.

On my laptop, it looks like this:

jon@Jonathans-MacBook-Pro:~/Downloads$ esptool.py -p /dev/tty.usbmodem142101 read_flash 0x0 0x100000 sonoff-ewelink.bin
esptool.py v2.6-beta1
Serial port /dev/tty.usbmodem142101
Connecting….
Detecting chip type… ESP8266
Chip is ESP8266EX
Features: WiFi
MAC: dc:4f:22:2b:c8:63
Uploading stub…
Running stub…
Stub running…
1048576 (100 %)
1048576 (100 %)
Read 1048576 bytes at 0x0 in 94.0 seconds (89.2 kbit/s)…
Hard resetting via RTS pin…

After it’s finished, you will have the original flash memory saved on your computer in a file called “sonoff-ewelink.bin”.

Then continue with installing Tasmota.

Later, if you change your mind and want to put the original firmware back in place, you can follow the normal steps for installing Tasmota but instead use the file you saved. The command will look similar to this, but with your serial port address substituted:

esptool.py -p /dev/tty.usbmodem142101 write_flash -fm dout 0x0 sonoff-ewelink.bin
Posted on 1 Comment

Video of my conference talk “Open Source Superhumans”

I spent last week in Christchurch, New Zealand, for the always amazing linux.conf.au conference. It’s my annual pilgrimage: I’ve attended every single LCA since 2002, and this year I presented a talk about my work using DIY home automation projects to help a couple of old friends who have Duchenne Muscular Dystrophy and rely on electric wheelchairs for mobility.

This was a very difficult talk to give because it tells a story that is both tragic and uplifting. The projects I’ve worked on with Nick and Chris Fryer have been some of the most rewarding things I’ve ever done, but along with that came the terrible grief of Nick’s death last year.

Many people have the preconception that home automation is “expensive toys for rich lazy people”, but this talk shows that it’s far more than that.

If you personally benefit from the use of home automation, or have friends or family members who do, I’d love to hear about it. Please comment here or post in the forum, but of course please be respectful of privacy and don’t reveal personal information about anyone else unless they are OK with it.

Posted on 5 Comments

#30: Reflash ANY Sonoff, even if you don’t know the pinout

Sonoff is very popular for DIY home automation, but you can make it even better by loading new firmware onto it. Learn how to connect a USB-to-Serial converter to ANY model of Sonoff, even ones that haven’t been released yet!

This episode isn’t just a series of steps to follow: it’s a tutorial on how to reverse engineer the connections to the ESP8266 / ESP8285 microcontroller in an unknown circuit, and put it into bootloader mode ready to receive new software.

ESP8266 Strapping Pins

The strapping pins set the boot mode of the microcontroller. Typical ESP8266 circuits have an arrangement similar to this:

In the Sonoff, GPIO15 is pulled low to 0V, and GPIO2 and GPIO0 are pulled high to 3.3V.

If GPIO0 is held low (0V) during startup, the ESP8266 will go into bootloader mode and be ready to receive a new program uploaded via the serial connection on the TX and RX pins.

You can often find the appropriate connections on the PCB by tracing out the pins on the microcontroller. The relevant pins on the ESP8266 and ESP8285 can be found in these locations:

With only a couple of exceptions, most Sonoff models include a 4-pin header on the PCB that exposes GND, 3.3V, TX, and RX.

You can use a USB-to-Serial converter to connect this header to your computer by USB, so that you can upload a new program. You can make an adapter cable using these connections:

It’s a simple cable to hand-wire, but that can be annoying so to save time I designed a simple adapter that you can use between a USB-to-Serial adapter that uses the common “FTDI” pinout and the Sonoff:

The adapter makes it very easy to connect to most Sonoff models. Make sure you use a USB-to-Serial adapter that runs at 3.3V because it’s not safe to connect 5V. Doing so could damage the ESP8266 microcontroller.

Sonoff Basic Pinout

More detail to be added here soon.

Sonoff POW / TH10 / TH16 Connections

More detail to be added here soon.

Sonoff 4CH Pro Connections

More detail to be added here soon.

Sonoff Slampher Connections

More detail to be added here soon.

Sonoff B1 Connections

More detail to be added here soon.

Sonoff Touch Connections

More detail to be added here soon.

Posted on 3 Comments

#29: Assistive technology projects with Chris Fryer

Over the last 12 months I’ve been working with identical twins Nick and Chris Fryer, who have Duchenne muscular dystrophy, on a variety of assistive technology projects. This is a field where home automation can have an enormous benefit and dramatically improve people’s lives.

Unfortunately Nick died recently, so Chris and I have been continuing his projects and also starting some new ones.

This is just a brief look at some of the things we’re working on. There will be far more technical detail in later videos.

Chris’s channel: www.youtube.com/user/MrChrisfryer78/
Chris’s Patreon: www.patreon.com/chrisfryer/

Posted on 2 Comments

Shipping closed during December 2018

During December I’ll be taking a break from shipping orders from the SuperHouse and Freetronics online stores.

Any orders placed after December 4th, 2018 will be shipped right after Christmas, hopefully around December 28th and 29th. If you want to get something in time for Christmas, make sure you place your order now!

I’ll be back with more videos and a bunch of new products after Christmas.

See you then!

Posted on 13 Comments

New product: Sonoff Programming Adapter

If you want to load new software onto a Sonoff, you can use jumper wires to link a USB-to-Serial adapter to the programming header of the Sonoff. However, it’s easy to make a mistake, and loose jumper wires can be really annoying.

This cool little programming adapter simply plugs into a common FTDI-type header, and then plugs into your Sonoff.

No more jumper wires. No more looking up the pinout every time you have to connect them!

This little adapter is going to be featured in the next episode of SuperHouse, which will show how to put any Sonoff model (even new ones that haven’t been released yet) into programming mode.

Check it out in the online store.

Posted on Leave a comment

Livestream Q&A: Digging through my Eagle projects, part 3

Livestream going through my Eagle projects directory, opening each of them and explaining what they’re about.

Projects covered in this episode: