MQTT button state topic and specific added setting

Hi there,

I’ve added a publication of button click state (short, long, double) over mqtt in button.cpp in /btn topic of 3 constant define in const.h.
My wled project is my bedside lamp included in my domotic to gently wake me up, and I need to send the button click to my domo system to manage my alarm clock.

As an exercice, I’m trying to add a custom setting in the sync page.
No pb with html in setting.h :

Send Button State over MQTT : \<input type="checkbox" name="BTM"><br>

i’ve added a variable in wled.h :
WLED_GLOBAL bool buttonMQTTEnabled _INIT(false);

in xml.cpp :

in set.cpp
buttonMQTTEnabled= request->hasArg(F("BTM"));

and in wled_eeprom.cpp
EEPROM.write(2600, buttonMQTTEnabled);
just before the commit();

and buttonMQTTEnabled =;
just below the reading for mqttEnabled.

In the web interface, there is now a brand new checkbox setting, I’m able to save it with the “save” button and the sketch in my modified “button.cpp” is able to handle it.

But when I reboot the esp, I’m back to the initialisation of that var.

I know some of that shouldn’t be of good practice, and i’m pretty sure i do not understand all i’ve added here, it’s just an exercise

but How to save this setting more consistently and permanently ?

My device : wemos D1 mini 4M, RGBW adressable led strip.

You should consider creating a WLED usermod. WLED usermods can add custom UI elements.
I think that would be easier and faster.

Once you get the usermod working, if you want to create your own fork of wled and customize it internally, you are of course welcome to do that. Then you can review how to modify the UI in the WLED wiki.

I am only suggesting usermod so you can get it working more quickly / easily. If you want the additional challenge, I cannot help more than suggest using the wiki and reviewing the sound reactive fork of WLED with UI modifications.

If you are new to github, you can search on how to find project branches, but I bet you find the sound reactive branch of WLED faster than it took you to read this far. :wink:

Can you add UI elements just in the usermod? I’ve been editing many files as shown above for mine.

Makes me think WLED is configured to have custom usermod UI tab.

See any docs? :wink:

1 Like

Thanks for the advices huggy,

I’ve start first with a usermod, I was able to send button click over mqtt.
I’m pretty sure I would have been able to trigger macros from that, but i’d want to keep the flexibility of the UI to affect macro to button clicks.

and it’s pretty easy to implement that directly in “button.cpp” (and that part works great btw), and my home automation works fine with that!

In the wiki, I’haven’t found more information about webUI mods except the part that concern nodeJs/npm to generate html_*.h files.

Does it generate conf save script also?

And yes, i’m github newbee do you mean the atuline wled fork ?

Ok, I’ve rewied Adding a Sound Settings page to the UI, I do not add a setting page, but that’s the step I went through.
Note that here he do not describe the implentation of EEPROM write/read.

Well, I failed in selecting the right adress to write in eeprom…

with an address directly joined/consecutive from the previous one :
EEPROM.write(2550, buttonMQTTEnabled);

It works fine…

1 Like