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.

6Mar/180

Cheap Environment Sensing With ESP8266 & MQTT

Several years back, I got into the home automation game, sadly for me, at the time I was trying to automate "all the things", it was just too chaotic lacking any standardization, was severely limited in what you could do, and was crazy expensive. While trying to find a solution for the IOT cloud issues I was having with my last project, I stumbled upon Home Assistant, specifically HASS.IO. It's an open-source community driven solution for home automation, fully-embraced MQTT (which was what I needed), and was very actively being developed. It solved the need for the project I was finishing as it could ingest MQTT data, store it for a few weeks, and provide graphs, etc. But as I got running with it, I realized how powerful it was and how much more mature and accessible home automation had gotten. Fast-forward a few months, and I've completed my first take at a super inexpensive environment monitor for home automation (or any other need).

These sensors are super accurate, small, versatile, and best yet, they are super cheap! I designed this particular incarnation to sense the environmental elements, specifically the temperature, the humidity, and the barometric pressure. They are driven by the fantastically cheap ESP8266 and leverage MQTT as the mechanism to feed my HASS.IO instance with the data. For more flexibility and convenience, the boards are designed to support programming of the ESP8266 in-circuit which does drive up the costs but those components are only required if you wish to use this PCB for programming the ESP8266. I'll build the sensors I deploy without them which makes the total cost for a sensor (without the programming bits) $13.91 USD (with USB cable and wall-wart it's $16.14 USD). This makes this sensor far cheaper (and more rewarding) than anything else available on the market.

 

Sensor Data Populating My HA Instance

 

I've moved all schematics, code, and images of all my builds to my github.com account. You can find all the files related to this particular build here.