Migration MQTT to 2.4

Any message means ON or literally any number means ON and non-numbers mean OFF? Ignored?

Any message means ON

OK, then I think this will work.

Assuming you are running OH 2.5 M1 (which you should because of many bug fixes in MQTT 2 binding immediately after 2.4 released there is a new default value in the Map transform. So if you create a .map file containing

=ON

and apply that transform to the incoming Channel any message should get transformed to ON.

Works!
Thank you @rlkoshak
One more thing, can you explain this rule from here: https://www.openhab.org/addons/bindings/mqtt.generic/

rule "Publish all"
when 
      Channel "mqtt:broker:myUnsecureBroker:myTriggerChannel" triggered
then
   //this is variable where all incoming messages is stored separated by # 
   val parts = receivedEvent.split("#")
   //but i do not understand this line 
   sendCommand(parts.get(0), parts.get(1)
end

This is to replace part of the replacement for the EventBus capability. The Rule get’s triggered for all messages published to the myTriggerChannel. The receivedEvent implicit variable carries the event as a String. The format of the String is <topic>#<value>.

So when events are received on the topic we can command the Item of the same name with the value. Thus you can sort of federate OH instances over MQTT by having them publish all events and using a Rule like this to synchronize them.

Since i install new MQTT binding (2 days ago), i have 2 mqtt_v_1 stops. This was never happen before. And strange, mqtt v1 cannot reconnect to broker, only OH restart helps (i try to restart mosquitto service - doesnt help). I use same name “zbox” on mqtt1 and “zbox” in bridge mqtt2 - is this possible fail reason?
OH 25M1 Xubuntu x86

Most likely. Each needs to have it’s own client ID. Only one client with a given client ID can be connected to the broker at a time. When a client tries to connect with the same ID as a client already connected, the broker will kill the connection to the already connected client and use new connection instead.

Hi Mate, do you have a corresponding item file for these lamps ?
Cheers

Hi, after several months I have now decided to migrate to MQTT 2.4.
Most of items are simple ON/OFF item with On=1", Off=0", but I also have some LEDS with a fadein/out and strange on/off message.
With MQTT1 the item was:

Switch	LED_Cucina	    {mqtt=">[localbroker:/N17_LEDCucina/cmd:command:ON:pwm,12,1023,2000],           >[localbroker:/N17_LEDCucina/cmd:command:OFF:pwm,12,0,2000],             <[localbroker:/N17_LEDCucina/LED_Cucina/OUT:state:OFF:0],          <[localbroker:/N17_LEDCucina/LED_Cucina/OUT:state:ON:255],",        autoupdate="false"}`

How can I create an equivalent thing/item in MQTT2.4 ?
Thanks for your help
Lorenzo

As described above and in many of the links in the thread above, assuming you have the binding set up and a Broker Thing created and it shows as online.

  1. Create a Generic MQTT Thing
  2. Set the outgoing topic to “/N17_LEDCucina/cmd”
  3. Set the incoming topic to “/N17_LEDCucina/LED_Cucina/OUT”
  4. Configure custom ON and OFF values (1 and 0 respectively)
  5. Link the new Channel to your Item, keep autoupdate=“false”

Thanks RIch,
This is clear to me but I need to send :
as ON command “pwm,12,1023,2000”, as OFF command “pwm,12,0,2000”
while for the state the binding receive “255” as ON and “0” as OFF

How can I solve this issue with the 2.4 binding?

Thanks
Lorenzo

If they are fixed values, use the custom ON/OFF value fields. If not, use a transform.

Thanks Rich… solved but I have created 4 map files … probably due to my poor knowledge :laughing:

I am now in the process of migrating from MQTT 1.x binding to 2.4.
Currently running OH 2.4.0 stable.

I have difficulties connecting the channel to an item. The channel updates, but the item does not.
PaperUI shows the broker to be online and the channel seems to be defined and linked to the item:

The log shows the channel receiving updates:

2019-12-06 13:50:47.894 [vent.ChannelTriggeredEvent] - mqtt:broker:fbeab725:Solna_E_T triggered 21.9

But the linked item does not update. This is the item definition:

Number	Solna_Entrance_Temp		"Temperatur entré [%.1f °C]"	<temperature>	(gFlat ,gVardag, gTemp)		{channel="mqtt:broker:fbeab725:Solna_E_T"}

The item is defined in an .items file. If I try to create the item using PaperUI the item does not show up when trying to link the channel. In fact, no item shows up in the Link box for the channel.

EDIT:
My bad!
I forgot also to define the Generic MQTT Thing and from there define the channels. Now it works!

1 Like

Since I have some time due to the pandemic, I have migrated my entire system to MQTT 2.4, except for my ESP32 led controllers, For the life of me I cannot seem to get the State topics or the Transform values correct for the following.

String OTTOMAN_LED “OTTOMAN LED String” {mqtt=">[mosquitto:home/OTTOMAN_LED/set:state:*:default]"}

Switch OTTOMAN_LED_Power “OTTOMAN LED Power” [ “Switchable” ]
{mqtt=">[mosquitto:home/OTTOMAN_LED/set:command:*:MAP(LEDStripEffectJSON.map)]"}

Number OTTOMAN_LED_FX “OTTOMAN LED Fx”
{mqtt=">[mosquitto:home/OTTOMAN_LED/set:command:*:MAP(LEDStripEffectJSON.map)]"}

I have figured out the following:
Color OTTOMAN_LED_Color “Color” [ “Switchable” ]

Number OTTOMAN_LED_Speed “Speed [%.0f]”

Number OTTOMAN_LED_Intensity “Intensity [%d]”

I have tried many different ways, Read a lot of threads and I am struggling. Mind you I am a mechanic by trade not a programmer, I didn’t even know what a Raspberry pi was. I have had Openhab2 running on a Raspbery Pi for a couple of years now and just found out they will be turning off MQTT 1. I currently have MQTT1 and MQTT 2 running together and everything is working but I just wanted to convert my ESP32 Led controller over to MQTT2.

I have learned a lot from this forum, but this MQTT2.4 is kicking my butt.

Thanks in advance, Mike

The channel equivalent would be a commandTopic (for outbound), not a state topic.

Thanks Rossko57, I’ll give that a try. Thanks

I’m getting confused as where to put what text into the Paper UI Config Channel for example: The OTTOMAN_LED_POWER, Do I put
``` home/OTTOMAN_LED/set`` into the MQTT Command Topic?

And
```command:*:MAP(LEDStripEffectJSON.map`` into the Outgoing Value Transformation?

This is my current Items file for this LED controller.

//ledstrip 

//MQTT 1 
String OTTOMAN_LED "OTTOMAN LED String" {mqtt=">[mosquitto:home/OTTOMAN_LED/set:state:*:default]"}
Switch OTTOMAN_LED_Power "OTTOMAN LED  Power"  [ "Switchable" ] 
{mqtt=">[mosquitto:home/OTTOMAN_LED/set:command:*:MAP(LEDStripEffectJSON.map)]"}
Number OTTOMAN_LED_FX "OTTOMAN LED Fx" 
{mqtt=">[mosquitto:home/OTTOMAN_LED/set:command:*:MAP(LEDStripEffectJSON.map)]"} 
// Color OTTOMAN_LED_Color "Color"	 <rgb>  [ "Switchable" ]
// Number OTTOMAN_LED_Speed "Speed [%.0f]"
// Number OTTOMAN_LED_Intensity "Intensity [%d]"
    
//MQTT 2.4    
//String OTTOMAN_LED "OTTOMAN LED String"{channel="mqtt:topic:OTTOMANLED:String"}  
//Switch OTTOMAN_LED_Power "OTTOMAN LED  Power"  [ "Switchable" ] {channel="mqtt:topic:OTTOMANLED:Power"} 
//Number OTTOMAN_LED_FX "OTTOMAN LED Fx"{channel="mqtt:topic:OTTOMANLED:Fx"}    
Color OTTOMAN_LED_Color "Color"	 <rgb>  [ "Switchable" ]{channel="mqtt:topic:OTTOMANLED:Color"}    
Number OTTOMAN_LED_Speed "Speed [%.0f]"{channel="mqtt:topic:OTTOMANLED:Speed"}   
Number OTTOMAN_LED_Intensity "Intensity [%d]"{channel="mqtt:topic:OTTOMANLED:Intensity"} '''

``
I have it broken into two sections due to the MQTT migration MQTT1 and MQTT2.4. If I uncomment all of MQTT1 the LED controller works, I have commented the Color and Numbers because I have them working with MQTT2.4.

Confusion at it finest.

Thanks, Mike

Yes, if that is where you want to publish your Item commands.

Nearly. Whatever was sent to your Item as command will get passed (as a string) to your transformation.
The (string) result of your transform ends up as topic payload.
So there is no syntax to specify “command”, you have no other choice.
Just
MAP:LEDStripEffectJSON.map
the syntax is a bit different, no brackets.

Rossko57 you are the man, After you set me straight, I was able to see the commands being sent to my broker and go from there. for some reason I had to change the FX command to string not number It did not like it. But thank you so much for sharing your knowledge and time. I have been putting in some days into this and I was really getting frustrated so once again thank you. Now I have to do this like 6 more times. What does the link button do? I’ll do some research into that "I just found it " Hopefully I can just link my other LED Controllers to these channels.

Thank you, Mike