Single button remote control for TASMOTA

This is just a quick reiteration of a simple project from 2016 to show how easy it is to use an ESP8266 to solve a real-world problem.

Our television is quite a few years old now and still working well, apart from one annoying problem; it no longer recognizes the on/off command from any of the 3 compatible remote controls that we have.  To get around this problem, I popped an ESP8266 into a junction box between the TV and the mains socket, loaded it up with TASMOTA (of course) and then used to connect our Googly Home Mini back to the ESP.  Now we can just say “Hey Gew Gull, T.V. on!” and everything works like a charm …well, mostly.  My better half mumbles quite a lot (it’s usually “Rhubarb, rhubarb …humbug …seat down”, or something along those lines), but both Goojle and I agree that she does mumble …and it doesn’t seem to matter whether it’s in English or Japanese.  This is a problem, because while I’m always willing to walk across the room to turn a television off, I’m somewhat reluctant to turn the da$”!@ thing back on (and if you have ever been subject to the brain-rotting onslaught of puerile slop served up on Japanese TV, you’ll know what I mean).  The whole point of the ESP was to fix it for her.

However, reading about all the latest and greatest microcontroller stuff over on CNX Software the other morning (over breakfast, while she was partaking of the aforementioned BRooPS),  I came across an article on a low-power LoRa-based dual switch unit, which reminded me strongly of the old 2016 ESP doorbell project. MOSFET power-latch schematic I suddenly realized that I not only had the answer to mumbling (no, not a gag  …don’t be cruel!), but I also had the hardware already built and sitting (somewhere fairly well down) in the “previous-projects” box.

With a television, radio and most lights, you already know the status of that device (whether it is on or off) and the issue is that you want to change that status (think of those light switches at the top and bottom of a flight of stairs …you don’t really notice whether the switch is currently up or down …you just know that in the middle of the night you need to flick the switch at the top to see your way down and then flick the one at the bottom to turn the light off again).  You just want to toggle the state.  One thing that we do know about TASMOTA is that it does “toggle” really well.  So basically, all we need to do is tweak the doorbell demo just a tiny bit to send the MQTT data to a different topic and with a payload of “TOGGLE”.  That shouldn’t be too difficult.

And it wasn’t.  I still had a ton of superfluous crud in the demo code to flash and fade the multitudinous LEDs on the Yellow Dev Board from the previous project, but I just left it in there (along with the OTA update functionality).  The main changes were to add the new topic:-


and add a static payload:-


Oh, and because I wanted the ESP to stay connected long enough to grab any OTA updates that I might be trying to fling at it, I extended the run time to a whopping 12 seconds and added a boolean flag to prevent the main loop from toggling the power to the TV 11,500 times while we were waiting for the OTA timeout.

The tl;dr summary of the doorbell hardware is that a single tact switch provides a pulse of power to the ESP8266, which is enough to bring it up to the state where it can turn on a MOSFET attached to GPIO16, which is connected directly across the tact switch and so latches the power to the ESP on, even when you remove your finger from the switch.  Once the ESP has connected to local WiFi, sent off its packet to the MQTT broker and handled any pending OTA update (or, most likely, timed out) it simply removes drive from the MOSFET gate, turning it off and thus powering itself down.  There is no “standby” current draw, as the whole unit is powered down.

One-button-remote in operation

All done and dusted in time for her birthday, neybothaman!




ESP32 + W5500 — Simple Working Example

Update June 2019  —  A couple of people have mentioned (both here and on GitHub) that they are having difficulty compiling the code for this project, with “invalid abstract return type” errors.  This turns out to be an upstream problem caused by a non-backward compatible modification of the Espressif  arduino/ESP32 library.   You can force the build to use an older (compatible) version of the library by changing a single line in your platformio.ini file:-

—  platform = espressif32
++  platform = espressif32@1.6.0

Thanks to @maniekQ for documenting this workaround.

Over the past couple of days, in the course of answering questions on the popular article on adding an ethernet port to the ESP8266, I found myself putting up a link to some new code for a work-in-progress project which simply replaces the ESP8266 with an ESP32 (which seems to make a lot of sense, given the falling cost of the ESP32 modules, nowadays).  ESP32 + W5500 moduleWhile that project is for an ESP-Now gateway, it seemed like there was a need for a nice, simple test and verify project where people can do a minimum of work with the hardware (an ESP32, a W5500 module, some jumper leads and a breadboard) and get a working result in a reasonably short time.  I’d said in various places that it shouldn’t take too much work to modify the code for the ESP-Now project to handle any of the examples shipped by default with the Arduino Ethernet library, so that’s what I’ve done.

Here’s the code (along with the pinouts in the README) for the simple “UdpNtpClient” example, munged very slightly to work with the ESP32Output exampleAll it does is connect to an NTP server, retrieve the current timestamp and display the UTC time.  This is basically a 30-minute project to produce a working demostration of an ESP32 using hard-wired Ethernet.

The configuration uses a static IP and network setup (router/gateway, netmask and DNS), as the original ESP8266 project seemed to have problems with DHCP (and quite honestly, I just haven’t gotten around to trying it with the ESP32 version, yet …let me know how it goes if you do).  All of the configuration options are in the “local_config.h” file.

The original library example code uses a single NTP server, “”, which seemed a little anti-social to me, so I’ve added several of the more popular geographical pools into the config file and updated the default target to be the main “”.   You should choose the one closest to you (unless you’d like to see how unreliable bare UDP really is, in which case you might like to try “”  —  apologies if you’re reading this from McMurdo Station 🙂 ).



Recent Updates (March 1st, 2019)

Otto Winter has been continuing his updates to esphome with improvements to the set-up wizard and the addition of min/max settings for rotary encoders (esphome enables you to add an ESP8266 or ESP32 to Home Assistant without writing any code).

Theo Arends has been working on reducing stack space usage in Sonoff-TASMOTA to fix some intermittent crashes.  If you’re having issues, please upgrade to version or greater (see this post for more details).

Phil Bowles has been updating the API documentation and examples for his esparto rapid development framework for the ESP8266 (available as an Arduino IDE library; write concise, working code with no setup() or loop() functions).

Xose Pérez has made lots of changes to his espurna replacement firmware for ESP8266 devices over the past few weeks, with support for more than twenty new products added and the incorporation of many fixes (both from Xose himself and submitted by an ever-growing community of users).

Rich Heslip has published an ESP32 project, “Motivation Radio BLEMIDI”, to add WiFi and Bluetooth functionality to Eurorack based modular synthesizers.  The hardware for this module is also open source and available from a separate repository, courtesy of Jim Matheson.


TASMOTA exceptions and watchdog resets

Just a quick note on recent TASMOTA changes.  Theo has been pushing out some updates over the past couple of days to fix an intermittent stack overflow problem which has cropped up with some combinations of hardware and TASMOTA firmware.  The issue seems to manifest itself with TASMOTA versions and and some devices which do load current monitoring (eg:- the NX-SP201 series, double-outlet smart switches).  Initial indications are that executing a “status 0” command at exactly the same time as the current monitor is updating can run the device out of stack space.

Bottom line… update to release of (or greater) if you’re seeing these symptoms.

Recent Updates (Feb 14th 2019)

I’ve added Mike Rankin’s Twitter feed to the ESP32 links section (RH column).  Mike has several ESP8266 and ESP32 projects in his Github repository and usually has some interesting commentary on his Twitter feed (ongoing status, problems, fixes, etc).  His latest project, a rechargeable-coin-cell based ESP32 mini board, is definitely worth a look, as are his previous ESP8266 creations.

Theo and his merry band of helpers have been hard at work pushing out more updates to Sonoff-TASMOTA.  Along with some code refactoring at the end of January to change “boolean” types to “bool” and “byte” to “uint8_t”, some other interesting updates have just slipped out in the last couple of recent releases:-

  • Templates.  This is a great new feature which allows people to  add new device GPIO definitions via JSON templatesA repository for user-submitted templates has already been created.
  • Support for multiple ADS1115 devices on the i2c bus.  If you’ve been limited by the single AtoD pin on the ESP8266, you can now add up to four, four-channel ADS1115 devices (on unique addresses) to the i2c bus and have them automatically recognized.
  • Numeric operators “==”,  “!=” ,  “>=”  and  “<=”  added to rules (the previously existing  “=”  string comparator frequently produced unexpected results when used in a numeric context).
  • HASS discovery and status for sensors.

Martin Ger has just updated his esp_wifi_repeater package to handle MQTT QOS (in version 2.2.5).

Adding Alexa control.  Phil Bowles has released a tiny Wemo emulator library, “weenymo.  It’s about 60 lines of code and adds Alexa on/off functionality to your ESP8266 projects (and don’t forget to check out his “esparto” rapid development library while you’re visiting his GitHub repository).

Otto Winter has integrated the esphomeyaml and esphomelib projects under the umbrella name of “esphome.  If you haven’t come across either (any) of these before, the basic idea is that a user can write a short configuration file and have code automatically generated for an ESP8266 or ESP32.  With esphome, you can have an application up and running on your ESP in a few minutes without writing a single line of code yourself.

ENC28J60 Gateway (Was:- Not-So-Recent Changes)

While answering a question in another thread, I realized that I’d missed an exciting change which, from the number of hits related pages get, is sure to be of interest to readers of this blog.

Back in the March/April time frame, Martin Ger updated his ESP WiFi Repeater to support an SPI-connected ENC28J60 ethernet module.  The work was quite well hidden, way down the page in a very long README (which catalogues the tremendous amount of work that Martin has put into this project).  Martin credits Andrew Kroll “…for his great work on getting [this] right”, so kudos to both of them for a very useful addition.

ENC28J60 hardware

You’ll need to run your ESP at 160MHz and have a decent power-supply to have this mod work effectively, but as Martin points out, once you have the ENC28J60 hardware configured with his ESP WiFi Repeater package, you’ve got yourself a super-cheap, DIY access-point.

Recent Updates (20th Oct 2018)

esp-go  –  Pete Scargill’s re-badged “Hackitt & Bodgitt” code for a universal i2c Nano peripheral extender for the ESP8266.

Pete has mainly been updating the documentation for his code over the past couple of weeks.  In the latest release, the name has changed to “esp-go.doc” to reflect the re-branding.


badgy  –  SQFMI’s “Swiss Army” e-Ink badge,based on the ESP-12F.

SQFMI has updated the code to work with the latest version (3.0) of the GxEPD library.


mobile-rr  –  idolpx’s ESP8266 Mobile Rick-Roll Captive Portal.

idolpx has added some images to the documentation to help novice ESP8266 users get a better grasp of what they’re doing, as well as updating the code to add DNS overrides and improve the WiFi scan filtering.


Sonoff-Tasmota  –  Theo Arends’ all-purpose replacement for Sonoff firmware.

Theo has been steadily updating and improving the 6.2.1 version of his firmware with (in no particular order):-

  • A change to a non-blocking MQTT library as the default.
  • Add support for the DS3231 RTC.
  • Add TasmotaModbus library.
  • Add support for the HX711 load cell.
  • Add support for Pzem energy monitors.

…as well as various fixes.


IRremoteESP8266  –  A library to enable IR send and receive on the ESP8266.

Mark has updated the package to support Disney’s “Made With Magic” protocol.