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?

have you solved the question raised above?
I have integrated WLED to my HomeAssistant.
However, all other PINs at my NodeMCU are available, so I am planning to utilize them via usermods. But for correct working, I need to receive the mqtt messages and work with them

Actually if you look at you can see that usermod is using MQTT. You can start from this code if you want add some functionality.

That code only send mqtt messages but not listen to/read them (it is necessary for two way communication between mqtt server and wled)

That is correct. And you want status message too. In this case you have to talk to dev channel if you need help otherwise if you figured how it can be done do a PR to WLED.