[SOLVED] MQTT 2.4 Concat item states

Hi,

I’m planning to migrate from MQTT v1 to v2 in the next days and hopefully improve my setup a bit.
For my irrigation setup I’m using a diy solution which needs e.g. ON:15 as the MQTT input. 15 in this case is the time in minutes to open the valve.
Therefore I’m using two items (Switch and Number ) at the moment and a rule to combine both information and send it via the MQTT action. The device will respond with ON directly after the valve opened and after 15 minutes with OFF.
Is there any way to combine the Switch and Number Item without the rule?

Hello,
You could use a text value channel in a generic mqtt thing in the mqtt2 binding linked to a string item combined with an outgoing value format to add the “ON:” part. This way you would only have one String item which you can send Numbers as commands that get published to your command topic which than changes to the ON and OFF values published to the state topic.
Best regards Johannes

Hi Johannes,
thanks for your response. Maybe I did not get your idea fully right.
How would this be connected with a switch to trigger the On or Off command?

Maybe I understood you wrong. Do you ever send an OFF command to your device? The way I understood it you only send commands in the format: “ON:numberofminutes” and than it turns off automatically. Does you device accept an OFF command too? Than the format before publish wouldn’t work but you could still just send the full String from a rule to the item or use a map on your Sitemap to have it turn on for 15 minutes button without a rule or even make a selection type where you can choose the number of minutes.
What is the topic structure of your device? Do you have separate state and command topics or is it all one topic?

There is no way to combine the two separate Items without a Rule. But there is an Action on the MQTT 2 binding so you can pretty much continue to do it the way you do now. You just need to import and use the new Action instead of the MQTT 1 publish Action. See https://www.openhab.org/addons/bindings/mqtt.generic/#rule-actions.

1 Like

Yes, I should have mentioned that before - sorry.

Yes I have separate topics for commands and states.

Ok, I see - do you know if this is a general OH limitation or a binding limitation?

No there is no real way to combine two different types. The way I was proposing was a kind of work around where you would have had a String item. But this would have not given you a true switch item or a true number item. Just a string item which could have an on and off state of kinds but as a string.
So @rlkoshak is right using the publish action Is probably still the way to go

1 Like

It’s a general OH limitation. If you want to combine two Items into one, you must create a third Item to store the combined state and use a Rule to populate that third Item when one of the other two change.