This will provide a Manual button and an Auto button which will set the Item to either “manual” or “auto”. Assuming the Item is linked to the Channel, anytime the Item is changed it will send that string via the %s in formatBeforePublish.
i better check configuration option for list-item component and it’s possible to define a list of values with format value=description, so i changed the page UI yaml file as follow:
For this scope the formatBeforePublish was not necessary, so I removed it from .thing file.
The UI doesn’t change, is the same as previous picture with option list with simple description: schedule, manual, boost and so on
Maybe formatBeforePublish will be useful for switch item or for numeric item, I’m just doing some tests
for numeric item there is not actionOptions in yaml/UI configuration so i try with publishBeforePublish in thing file and,first, it’s doesn’t work I expect, I received the wrong string AUTO instead of right string {“auto_lock”:“AUTO”}
I try changing the string in the channel configuration to
adding the " + %s + ", this generate an error in mqtt bridge that forced the unload, I suppose, of mqtt bridge, so in the log i saw a lot of error message stating “…changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)”
after restoring the thing file deleting the string " + %s + " the bridge reload and the formatBeforePublish starts to work correctly.
so I made a second test without force the error but simply stopping the mqtt from things UI page but this didn’t give the expected result, the formatBeforePublish didn’t work.
I generate again the error and restore again the thing file and it works…
So I ask, what do I have to stop/restart for make it work correctly without generate error in thing file?
Ah, this is an absolute classic: openHAB has a bug, which it has had for a long time, where it doesn’t always properly load a Things file after it has been saved.
Restart your openHAB for a quick fix, or do this. To be honest, deliberately generating the error in the Things file is the fastest and easiest method as it forces openHAB to unload all the Things in that file. Repairing the Things file then forces openHAB to load all the Things back up.
You can also use a simple switch to get you auto manual to work.
Try using the main UI to create a generic thing its easy and has a simple form to fill in. Once you get it setup you can add channels in the code section.
So for your example with outgoing format using auto manual in the code tab enter