This is a follow up question to my initial question you can find -> here
I am now migrating to the mqtt 2.5 binding and therefore I need to switch to the things and channel business.
Reading values works fine- yet again it is the question how I can write a specific value to the MQTT topic:
in MQTT1 my item looked like this:
Number Temperature_Setpoint "Zieltemperatur [%.1f °C]" <temperature> {mqtt="<[mosquitto:hometop/ht/hc1_Tdesired:state:default],>[mosquitto:set/hometop/ht/hc1_Tdesired:command:*:${command},heizen]"}
Thing topic Temperature_Setpoint "Zieltemperatur" {
Channels:
Type number : temperature "Temperature" [stateTopic="hometop/ht/hc1_Tdesired",commandTopic="set/hometop/ht/hc1_Tdesired" ,"${command},heizen"]
}
Which obviously does not work. (using the same sitemap entry)
The tricky bit is, that I need to grab the numeric value and add “heizen” and send it to the topic.
Type number : temperature "Temperature" [stateTopic="hometop/ht/hc1_Tdesired",commandTopic="set/hometop/ht/hc1_Tdesired" , formatBeforePublish="%s,heizen"
I’m not quite sure what formatting you need in your specific case - are they comma separated? Either way, it’s formatBeforePublish you want! The %s will get filled in by your command.
Thank you very much for you suggestion.
formatBeforePublish might be the thing actually - Yet I need to figure out the right syntax and/or escaping. So far it does break my thing configuration.
This helps a bit - the .things file is still working correctly. Yet nothing is sent to the topic - I had an oder fiddle to try and work out the right syntax - but so far without any luck.
I have left the problem for a while - but now as I upgraded to OH3 is is pressing again.
The previously suggested hints have led to nowhere unfortunately. The mqtt explorer shows nothing - and I still have not figured the correct way to form the message via a thing file.
There are actually two commands I would like to realise: the first might be a bit easier:
currently my thing looks like this and I tried to hardcode the value “heizen”:
Thing topic HeizungMQTTModus "Heizmodus" {
Channels:
Type number : temperature "Heizmodus" [stateTopic="hometop/ht/hc1_Tniveau", commandTopic="set/hometop/ht/hc1_Tniveau",formatBeforePublish="-m \"heizen\""]
}
but this does not work at all. Any help would be much appreciated.
Go back a step. Have no formatting or transformation at all in your channel, so it just publishes the basic number.
After editing Things file, restart the binding or reboot.
Command the linked Number Item with a number - what do you get in your MQTT Explorer or mosquitto_sub ?
After fiddeling with this for far too long - I went for the cheap solution. Now I just use the exec binding to send the working mosquitto_sub command to my broker.
I don’t really like it - but it works and there are only so many hours in a day…