MQTT 2.4 Migration Help

Hi all,

A bit of background information, I’m using a Raspberry Pi 3 with the latest openHAB v2.4.0. I have also upgraded to MQTT v2.4.

For the main part I’ve managed to migrated successfully. However, I am now facing one issue which i cannot seem to figure out.

It’s important to mention, all my configs have been done in a text file.

So essentially, I have a Sonoff SV running Tasmota firmware; it is being used on a Garage Door and also utilising GPIO14 for a contact sensor.

I know that GPIO14 sends a ON/OFF topic as per below:

cmnd/rearGarageDoorSensor/POWER2 = OFF

So, in MQTT v1.x I created a .map file for the .items as shown below:

OFF=CLOSED
ON=OPEN

Now, in v2.4 I’ve set up sensor topic as a Switch because of the ON/OFF, is this correct?

Then in my .items as a Contact switch which uses the .map file to transform it. However, this does not seem to work.

Please see below:

.things

Bridge mqtt:broker:oh [ host=“localhost”, secure=false ] {
Thing mqtt:topic:rearGarageDoor “Rear Garage Door” {
Channels:
Type switch : power “Power” [ stateTopic=“stat/rearGarageDoor/POWER”, commandTopic=“cmnd/rearGarageDoor/POWER” ]
Type switch : contact “Contact” [ commandTopic=“cmnd/rearGarageDoorSensor/POWER2” ]
}
}

.items:

Contact Rear_Garage_Door_Sensor “Garage Door Sensor [MAP(onoff.map):%s]” (House, Rear_Garage) { channel=“mqtt:topic:rearGarageDoor:contact” }

Can anyone shed any light on what I’m doing wrong please?

Many thanks in advanced,

Jeevs

1 Like
Bridge mqtt:broker:oh [ host=“localhost”, secure=false ] {
Thing mqtt:topic:rearGarageDoor “Rear Garage Door” {
Channels:
Type switch : power “Power” [ stateTopic=“stat/rearGarageDoor/POWER”, commandTopic=“cmnd/rearGarageDoor/POWER” ]
Type switch : contact “Contact” [ commandTopic=“cmnd/rearGarageDoorSensor/POWER2”, ON=“OPEN”, OFF=“CLOSED” ]
}
}

I asked a similar question a couple of weeks ago - I believe you can do the transformation in the channel definition like this. Then you don’t need the .map file reference in your .items if I understand correctly.

Try it out and let me know - otherwise I’m sure someone else will be around to correct us!

Edit - here is my question from a few weeks ago - in case you notice something else useful:

Edit 2:
Just saw that your transform is opposite of what I put. I am now thinking you may need to change the second channel to a “contact” instead of a “switch” and do the opposite transformation - perhaps this is close:

Type contact : contact “Contact” [ commandTopic=“cmnd/rearGarageDoorSensor/POWER2”, OPEN=“ON”, CLOSED=“OFF” ]

Then I believe your .items file can be:

Contact Rear_Garage_Door_Sensor “Garage Door Sensor [%s]” (House, Rear_Garage) { channel=“mqtt:topic:rearGarageDoor:contact” }

Please be aware that all the quotes are of wrong type, because the first posting used quoting instead of code fences. The thing definition should be without colons.
The channel is wrong either, the bridge is missing (mqtt:topic:oh:rearGarageDoor:contact instead of mqtt:topic:rearGarageDoor:contact)

Bridge mqtt:broker:oh [ 
    host="localhost", 
    secure=false 
  ] {
    Thing mqtt topic rearGarageDoor "Rear Garage Door" {
        Channels:
            Type switch : power   "Power"   [ stateTopic="stat/rearGarageDoor/POWER", commandTopic="cmnd/rearGarageDoor/POWER" ]
            Type switch : contact "Contact" [ stateTopic="stat/rearGarageDoorSensor/POWER2", on="ON", off="OFF" ]
    }
 }

and the items:

Contact Rear_Garage_Door_Sensor "Garage Door Sensor [%s]" (House, Rear_Garage) { channel="mqtt:topic:oh:rearGarageDoor:contact" }

Thanks for the corrections! I got pretty close…

One question, in the thing definition should the type be switch, contact, or can either work? His commands coming from the sonoff are ON and OFF, I would have thought that the contact “thing” would be:

Type contact : contact "Contact" [ commandTopic="cmnd/rearGarageDoorSensor/POWER2", OPEN="ON", CLOSED="ON" ]

Edit again - Do you need to have the contact be a stateTopic instead of a commandTopic channel? ( clearly I might not be the best helper here, hopefully I can learn something as well and not get others too confused. )

Haha… yes, that’s right. contact is receiving a state, not sending, so it should be a stateTopic…

Doing the correction above…

1 Like

@Jeevs - Did any of this work? What’s the “winning configuration”?

Hi @crxporter & @Udo_Hartmann,

Thank you so much for your input so far, you have been a great help. Apologies, I’ve not got around to responding earlier (may be time difference, I’m in the UK).

However, I’ve now had chance to play around with configutrations and the below actually results in a error in the log.

Bridge mqtt:broker:oh [ host="localhost", secure=false  ] {
    Thing topic rearGarageDoor "Rear Garage Door" {
    Channels:
        Type switch : power "Power" [ stateTopic="stat/rearGarageDoor/POWER", commandTopic="cmnd/rearGarageDoor/POWER" ]
        Type contact : contact "Contact" [ stateTopic="cmnd/rearGarageDoorSensor/POWER2", ON="OPEN", OFF="CLOSED" ]
    }
}

Contact Rear_Garage_Door_Sensor “Garage Door Sensor [%s]” (House, Rear_Garage) { channel=“mqtt:topic:oh:rearGarageDoor:contact” }

The error that I get is:

2019-01-04 18:33:19.016 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘ON’ not supported by type ‘OpenCloseValue’: No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.ON

2019-01-04 18:33:27.981 [WARN ] [eneric.internal.generic.ChannelState] - Command ‘OFF’ not supported by type ‘OpenCloseValue’: No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.OFF

Any ideas what I could try next?

Thanks,

Jeevs :slight_smile:

It looks like an error sending “ON” and “OFF” to a “contact” item. I would try this next - note switching ON<->OPEN and OFF<->CLOSED

Bridge mqtt:broker:oh [ host="localhost", secure=false  ] {
    Thing topic rearGarageDoor "Rear Garage Door" {
    Channels:
        Type switch : power "Power" [ stateTopic="stat/rearGarageDoor/POWER", commandTopic="cmnd/rearGarageDoor/POWER" ]
        Type contact : contact "Contact" [ stateTopic="cmnd/rearGarageDoorSensor/POWER2", OPEN="ON", CLOSED="OFF" ]
    }
}

Thank you, with the above I get no error and nothing happens on the ui :frowning:

Give me a few minutes, I’m going to try it on my 2.4 setup real quick!

Your door is sending the following, correct?

cmnd/rearGarageDoorSensor/POWER2 = OFF
cmnd/rearGarageDoorSensor/POWER2 = ON

That is absolutley correct! :slight_smile: - Thank you!

Alright mr/ms @Jeevs -

I got it working. I was very stuck but then I realized I didn’t have the “Map Transformation” installed in the paper UI.

This works:

THINGS

Bridge mqtt:broker:mosquitto "Mosquitto" [ host="localhost", port=1883, secure=false, clientID="openHAB2" ]
{
    Thing topic Jeevs "Garage" @ "Door" {
    Channels:
        Type switch : switch     "RearDoor"                [ stateTopic="stat/rearGarageDoorSensorSW/POWER2", commandTopic="cmnd/rearGarageDoorSensorSW/POWER2" ]
        Type contact : contact     "RearDoorC"             [ stateTopic="cmnd/rearGarageDoorSensor/POWER2", transformationPattern="MAP:Jeevs.map" ]
    }
}

ITEMS

Contact Rear_Garage_Door_Sensor "Garage Door Sensor [%s]" (House, Rear_Garage) { channel="mqtt:topic:mosquitto:Jeevs:contact" }

MAP: (called Jeevs.map)

ON=OPEN
OFF=CLOSED

SITEMAP:

sitemap Jeevs label="Jeevs"
{
Default item= Rear_Garage_Door_Sensor label="Jeevs"
}

I’m a little sorry it took so long - I definitely learned a lot. I got a chance to read through like 50 more forum topics, read the documentation on MQTT again, read the blog post about MQTT 2.4 by @David_Graeff again, play with node red (for my dummy item)…

Whew, that was much more fun than doing nothing for the last 2 hours of my work day. Enjoy!

Thank you so much @crxporter! You are an absolute legend!

That worked like a treat - thank you so much, really happy right now :smiley:

Your solution will most definitley help others too!! :smiley:

p.s I’m a mr :wink:

I’m glad to help! Eventually I’ll need to figure this stuff out anyway for my house, it’s good for me to practice by tackling other people’s questions.

I just barely got it figured out, too… I had a whole post all put together about everything I’d tried that didn’t work - then I realized my pi didn’t have the Maps transformation service installed :expressionless:

I’m still not sure why the ON=“OPEN”, OFF=“CLOSED” didn’t work, does anyone know? Is that for outgoing transformations while the map is needed for incoming?

1 Like

Honestly, sincere thank you! You have been key in getting this sorted, so thank you :slight_smile:

I can understand your fustrations with the transformation service, easy mistake to make and obvious only once you realise lol

Agreed, not sure why the ON=“OPEN”, OFF=“CLOSED” didn’t work…would be great to hear thoughts from others…Could well be what you say, maps for incoming and the other for outgoing…

should be

on="OPEN", off="CLOSED"

mind the lower case…

1 Like

Thank you @Udo_Hartmann. I will give this a go and report back.

I am really confused, my binding seems to install, but I cannot get any commands to be received. My things looks like -
Thing mqtt topic Laundry Room “laundry” @ “light” {
Channels:
Type switch : switch “laundry_room_light” [
stateTopic=“laundry_room_light/STAT/”,
commandTopic=“laundry_room_light/cmnd/POWER/”,
//retained=false,
//postCommand="",
//transformationPattern=“JSONPATH:$.POWER”,
//formatBeforePublish="%s",
ON=“ON”,
OFF=“OFF”
]
where my item is -
Switch laundry_room_light “Laundry Room” (FF_LaundryRoom, gLight) { channel=“mqtt:topic:laundry_room_light:switch” }

Does this formatting look good? I am having troubles understanding where the “laundry” @ “light” is derived from. can someone point me in the right direction?

thanks,
cmo

Does this formatting look good?

No. :slight_smile:

Thing mqtt topic Laundry Room "laundry" @ "light" {
    Channels:
        Type switch : switch "laundry_room_light" [
            stateTopic="laundry_room_light/STAT/",
            commandTopic="laundry_room_light/cmnd/POWER/",
            //retained=false,
            //postCommand="",
            //transformationPattern="JSONPATH:$.POWER",
            //formatBeforePublish="%s",
            ON="ON",
            OFF="OFF"
        ]

Yet the first line is faulty :slight_smile:
You must not repeat the key word mqtt in the thing definition, beside that a Thing has a name, and the name must not contain spaces. So

Thing topic Laundry_Room "laundry" @ "light" {

would suffice.
In question of the channel definition, as you are using a switch, there is no need for parameters other than stateTopic and commandTopic. The whole thing would be:

Thing topic Laundry_Room "laundry" @ "light" {
    Channels:
        Type switch : switch "laundry room light" [
            stateTopic="laundry_room_light/STAT/",
            commandTopic="laundry_room_light/cmnd/POWER/"
        ]
}

But the bridge is missing, so please be aware that you have to configure a bridge for the Thing.

Are you sure the topics are correct? I’m using Tasmota, and the topics would be more like laundry_room_light/stat/POWER and laundry_room_light/cmnd/POWER (given, you defined full topic as %topic%/%prefix%/)

By the way: the “laundry” @ “light” part:

If the channel is linked to an item (you did not link the correct channel name either :wink: ), the Thing would appear in Paper UI control at the LIGHT tab and with the Name laundry