MQTT from a usermod

I’ve been working on using WLED as a base for a project. It’s an easy starting point, I’m sure I could do this without WLED… but WLED is so great, and having LED’s available on these projects is a huge plus…

I’ve got two user mods. One hooks up to my doorbell button and a single IO pin is watching for the doorbell button press. When it detects a debounced button press, it sends an MQTT message… and then another message when the button is release.

That mod didn’t require anything special to send the MQTT messages.

However on the other side of this hardware, I have another D1-Mini running WLED that is the chime part of the doorbell.

For this one it watches the color state of the first 3 LED’s… if they are anything other than off, it triggers a 15ms pulse to one of 3 IO pins, which are then using a MOSFET energizing the doorbell solenoids.
Each LEDs needs to be reset to off before it can trigger the solenoid again.

So you can play chimes via E1.31, or any of the built in ways of turning on and off LED’s

Everything works great!

Now for the part that required modification outside of the usermod file.

For the chime code, I wanted to listen for an MQTT message and respond with a programmed chime song. I had to edit wled17_mqtt.ino with a user subscribe and a user handlepayload



userHandleMQTTPayload(topic, payload);

both of those in the appropriate methods, and then of course I needed to define WLED_ENABLE_USER_MQTT in the wled00.ino file…

#define WLED_ENABLE_USER_MQTT //for user mods that need to listen to MQTT

I don’t like modifying code outside of the usermod file, but I didn’t see any other way around it.

Any other ideas for supporting MQTT processing and subscribing in a usermod?