Mqtt 2.5

This is the pull request. And as you can see, I did not have time to continue to work on that :confused:

Cheers, David

I updated to OpenHAB 2.5.0-snapshot to fix some annoying bugs but I still noticed a big one in the MQTT binding or maybe in OpenHAB itself?
My mqtt payload is {"battery":100,"voltage":3032,"linkquality":60,"click":"single"} and I’m using the transformationPattern to get the click value.

Type string : click "Click"                    [ stateTopic="zigbee2mqtt/<DEVICE_ID>", transformationPattern="JSONPATH:$.click" ]

When I press the button twice, the first time it will set the value to single but the second time it will not change the item again because the value stays the same. I’m listening on item changes with node red. Right now it’s not possible to turn a device on and off with a single click.

A stateful channel will only pass a value to an item if the value actually changed, that is correct.
You want the “trigger” channel of the mqtt broker thing instead. If fires every time when a value is received.

The issue is, that you cannot apply a transformation before the condition (fixed string) is evaluated. You probably need a rule in this case.

Cheers, David

Hi,

any update on when the MQTT outgoing transformations will be implemented? I still have both the old MQTT and the new MQTT binding “working” side by side, but yesterday, for the second time, somehow the old binding stopped working. I’m not sure what I did last time to get it working again, but it would be great if we were able to migrate everything to the new binding.

Thanks for a heads.

It is implemented since two months or so :slight_smile: Just remember that openHAB has no “stable” / “unstable” branches that gets any backports of later changes (we just call it “stable”). You must be on openHAB snapshots to get those changes.

The timing is just really bad at the moment, because openHAB is in the process of changing the build system. The snapshots sporadically do not work since that process started end of January and is finished by maybe end of the month.

Cheers, David

Ok. I thought there was something still missing in the binding (either incoming or outgoing transformations (I need both).

What would be your advice? Wait till that build system change process is over?

Hi, i updated to Snapshot version but i couldnt find description of how to use outgoing transformations for mqtt, do you have a readme or link to examples? Thank you!

Look at the examples for incoming transformations, outgoing are working the same. It’s self explanatory in Paper UI so I don’t really get your question.

Outgoing transformations are available in OH 2.5 Milestone 1 which was released prior to the changes David described.

I am on openHAB 2.5.0 Build #1491. If I wanted to go to that 2.5 M1 milestone, what would be correct way to get there? Just switching to “testing” in openhabian-config seems to not work:

Aktualisierung für 59 Pakete verfügbar. Führen Sie »apt list --upgradable« aus, um sie anzuzeigen.

$ apt-get -y install openhab2=2.5.0~M1-1
Paketlisten werden gelesen... Fertig
Abhängigkeitsbaum wird aufgebaut.
Statusinformationen werden eingelesen.... Fertig
Die folgenden Pakete werden durch eine ÄLTERE VERSION ERSETZT (Downgrade):
  openhab2
0 aktualisiert, 0 neu installiert, 1 durch eine ältere Version ersetzt, 0 zu entfernen und 59 nicht aktualisiert.
E: Packages were downgraded and -y was used without --allow-downgrades.
FAILED (apt)

Based on the message, Build #1491 came out after 2.5 M1 so moving to 2.5 M1 is a downgrade. So, as the error from apt says, you need to apply the --allow-downgrades flag or not use -y and let it ask you if you want to downgrade.

I do have a vague memory that apt, for some reason, treats all of the milestone releases as if they were ahead of the snapshots. If that is the case, the solution is still the same.

So if my build came out after 2.5 M1, should my build have the MQTT outgoing transformation functionality included (I wouldn’t have to downgrade then)? I tried and it didn’t seem to work. Might have done something wrong though…

The easiest way to check is through PaperUI.

Thanks, I just “downgraded” to M5, and now it seems that the outgoing transformations work. Thanks again.

Thank you very much for your answer, outgoing transformation is clear but still i’m getting mad with this rollershutter items! :exploding_head:
So, the thing is a Shelly2, which is running very good in my OH 2.3 with following item:

Rollershutter Studio_Rollershutter "Studio Rollershutter [%d]"  (Studio) {mqtt=">[syn:shellies/shellyswitch-xxxxxx/roller/0/command:command:*:MAP(shelly.map)], <[syn:shellies/shellyswitch-xxxxxx/roller/0/pos:state:default]"}

And shelly.map file is:

UP=open
DOWN=close
STOP=stop

because open close and stop are the payloads of Shelly2 rollershutter.
In my sitemap i can manage a rollershutter item to command up and down, and get the percentage back.

Now i am running openHAB 2.5.0 Build #1549 and i want to replicate the same command.
I have no problem to run it as a dimmer using another mqtt payload, but still i would like to use a rollershutter item.
I inclued transformationPatternOut and here is my thing file:
MAP file is same as previous

Thing mqtt:topic:shelly2studio (mqtt:broker:synBroker) {
    Channels:
       Type rollershutter : studioshutter "Studio Shutter Command" [ stateTopic="shellies/shellyswitch-xxxxxx/roller/0/pos", commandTopic="shellies/shellyswitch-xxxxxx/roller/0/command",transformationPatternOut="MAP:shelly.map"]

And here the item:

Rollershutter   Studio_Shutter_Com           "Studio Shutter Com [%d]"   <rollershutter>             (Studio, gShutter)              { channel="mqtt:topic:shelly2studio:studioshutter" }


But when i try to send up or down the item, here is the log:

2019-03-09 15:56:21.950 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.handleCommand()' on 'org.openhab.binding.mqtt.generic.internal.handler.GenericThingHandler@57efe67c': Cannot call update() with custom stop/move/up/down
java.lang.IllegalStateException: Cannot call update() with custom stop/move/up/down

I am getting crazy please help!
Thank you :grinning:

1 Like

Rollershutter support is not complete on the MQTT binding side. The binding just doesn’t know what to do when it gets a “STOP” command etc.

so the only thing is to wait i guess… correct?

Until someone implements it, correct. That is how open source projects work ^^.

Rick i got my shelly’s rollershutters working with following config:
.thing file:

Thing topic Shelly25_xxxxxx "Shelly2.5 Rolluik Achterdeur" @ "Keuken" {
    Channels:
        Type rollershutter : Rolluik    "Rolluik achterdeur"     [ stateTopic="shellies/shellyswitch25-xxxxxx/roller/0/pos", transformationPattern="JS:ShellyRS.js"]
        Type number : Rolluikpos        "Positie achterdeur"     [ commandTopic="shellies/shellyswitch25-xxxxxx/roller/0/command/pos"]
        Type string : Rolluikcmd        "Command achterdeur"     [ commandTopic="shellies/shellyswitch25-xxxxxx/roller/0/command"]
}

the shellyRS.js file:

(function(i) {
    return (100-i);
}) (input)

this gives the right symbol for the shutter on the sitemap shelly open = 100% vs openHAB open = 0%

.item file:

Rollershutter Rolluik_achterdeur    "Rolluik achterdeur"        <blinds>    { channel="mqtt:topic:mosquitto:Shelly25_xxxxxx:Rolluik", autoupdate="false" }
Number Rolluik_achterdeurpos        "Rolluik achterdeur"                    { channel="mqtt:topic:mosquitto:Shelly25_xxxxxx:Rolluikpos" }
String Rolluik_achterdeurcmd        "Rolluik achterdeur"                    { channel="mqtt:topic:mosquitto:Shelly25_xxxxxx:Rolluikcmd" } 

.sitemap:

Default item=Rolluik_achterdeur

and a . rules file:

rule "Shellie2.5 Achterdeur command"
when
    Item Rolluik_achterdeur received command
then 
    switch (receivedCommand) {
        case UP : 
            Rolluik_achterdeurcmd.sendCommand("open")
        case STOP : 
            Rolluik_achterdeurcmd.sendCommand("stop")
        case DOWN : 
            Rolluik_achterdeurcmd.sendCommand("close")
    }
end

Hope this helps.
Jan

Anyone have a working example with a chain of transformations with both JSONPATH and JS.
Need to divide the JSON value by 10. Or is there any other way to not having two items and run through a rule?

I am running Openhab 2.5M4 and MQTT 2 binding.

See seperate post on same subject: