Lifelong Learning Knowledge should be uncompromisingly sought after and freely given away.

8Mar/190

A simple dual MQTT button…

I seem to be on a roll lately with these ESP8266 based projects, but they are so fun and useful, it's not difficult to identify new uses. This project originated from another project I just completed, building my own solder fume extractor. I wanted an easy way to turn the fume extractor on and off as well as having a timer turn it off after a few hours (in case I forget to turn it off). I immediately thought of a USB-powered MQTT "button" that would toggle the fume extractor on and off. But hey, if I was going to have this feature for my fume extractor and bother with incorporating it into my HASS.IO server, why not add another button and allow it to toggle two switches. I could use the other for my soldering iron, which sadly does not have an automatic shutoff built-in. And if they are both accessible to my HASS.IO server, why not automate and coordinate them? But first...

As with all of my projects, I listed the problem(s) I was trying to solve and my requirements for a solution.

Problems I wanted to solve:

  1. Eliminate the need to plug in and unplug the fan power cord on the fume extractor every time I want to use it
  2. I often forget to turn on the fume extractor when soldering
  3. Shut off the extractor after a few hours (in case I forget) or when the soldering iron is turned off
  4. I have been known to forget to turn off my soldering iron

So, four primary problems to solve. What are my requirements?

  1. Switch or button within easy reach while sitting at my lab desk
  2. Leverage HASS.IO to control the Sonoff plug on the extractor and the Sonoff plug on the soldering iron
  3. Not take up any desk space
  4. Use up some of the numerous ESP-12S modules I already had on hand
  5. Have nice large buttons (I love arcade buttons)

Since I knew I wanted to leverage 28MM arcade buttons and I needed two, I started this project with the design of the enclosure. It's silly large because of the arcade buttons, but I planned to mount the whole enclosure under my desk anyhow, so size was less important than my desire to use ARCADE BUTTONS! I only challenge in the build for this enclosure was that I had decided I'd try my hand at mechanical retainers to hold the PCB in place, I ended up exporting the PCB design from EagleCAD into Fusion 360 and building the enclosure around it. The design allows the PCB to be slid into the slot from the back and a small tab holds the PCB in place once it's fully slid into position.

The next task was to design the actual PCB, which was super simple this time. I have already used all of these components andwas able to put this one together in about an hour. Although, in full transparency, I did send the first version off to OSHPark to fabricate only to realize I had put the USB connector on the board backward; speed and quality are always in conflict it seems. With that silly mistake resolved, I was good to go with this step.

The last step was writing the firmware for the ESP8266 and modifying my HASS.IO server settings to add the new button (switches) and automation to trigger the appropriate Sonoff switches when the buttons are pressed. The Arduino code is very straightforward. The modifications to my HASS.IO configuration was a bit tricker, I didn't really want to deal with having the MQTT button query the state of the switch and issues an "ON" or "OFF" command, I just wanted it to "TOGGLE" the switch, regardless of its current state. I ended up figuring out that I could trigger a toggle command on the Sonoff switch based on any published message to the MQTT button topic. What this means is that my automation will trigger anytime any message is published on the MQTT button topic, doah. Sometimes things are just easier than you'd expect. I just had to add a second automation for the second button and test things out.

Testing was great, the only bug I found was that I had swapped the button IO pins on the PCB in firmware. A quick reflash of the ESP8266 with the fixed firmware and it was all good. As soon as the button is pushed for the fume extractor, it comes on, super low latency. Same was true for the second button that controls my soldering station. It was working and working perfectly!

One last enhancement needed to be developed, however. I wanted to automatically turn on the fume extractor when the soldering iron was turned on as well as turn it off when the soldering iron was turned off. However, I wanted to allow independent control of each so I could easily override the automation of the two, thus the two buttons. Doing automation in Home Assistant (HASS.IO) is fairly straightforward, lots of great community articles on how to write them, so no need to poorly attempt to instruct anyone on that here.

Overall, I'm absolutely thrilled with this project, it was incredibly easy to execute on and the reward; it makes me smile each time I get to smash that arcade button and hear the soft whirl of the fume extractor!

As with all my projects, all the artifacts for this project can be found on my GitHub repo for the project here.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.