[CLOSED] MQTT binding version 2.4 (Pre-release !)

Update about this issue:
This only happens when receiving the string message from my device.
When I publish the same message with MQTTspy, all functions normally.
I also investigated the payload with MQTTspy, but I can’t find any difference.

Found the issue: It seems that my device is sending an illegal character within it's payload. This character isn't visible in MQTTspy neither in the log output of OpenHAB. I discovered this while saving the message as a binary file from MQTTspy. Now the only thing is to figure out why my device is sending this character along.

Could you please add this to your bug report. I haven’t considered the case that /config is null.

I can improve the log message, by adding the character count to the message. That might help to see at first glance if non-printable characters are involved. I bet on a new line or tab character.

Could you please open a bug report to ask for improved logging? I will forget this issue otherwise.

Hello, I managed to convert all my switches to the new MQTT 2.4 version.
But I’ve been struggling with the JSONPATH conversion for a week now and could’nt get things running with the new version.
in v1 my item looked like this :

Number SolarSV	 "Volt [%.0f V]"            <energy>
	{ mqtt="	<[mqttimo:tele/Solaranlage/SENSOR:state:JSONPATH($.ENERGY.Voltage)],
				<[mqttimo:stat/Solaranlage/STATUS8:state:JSONPATH($.StatusSNS.ENERGY.Voltage)]" }

EDIT: I asked for help with the JSONPATH transformation, but finally found the solution for my Sonoff POW myself:
In the channel configuration state has to be:
stat/Solaranlage/STATUS8
Incoming value transformation is:
JSONPATH:$.ENERGY.Voltage

and my item looks like this:

Number Voltage "SVoltage [%.0f V]"  {channel="mqtt:topic:IDVoltage:CIDVoltage"}

EDIT again:
This doesnt work. Item value is only updated once after ceration. Then the values stay the same.
No values after reboot.

You need two channels linked to the same item.

Hopefully the tasmota developer will get their shit together and fix this ridiculous topic structure. There are so many people struggling with this. It fills pages, literally.
(/Rant)

1 Like

Hi,

I really like the new binding but struggle to use it for the Owntracks configuration I had set up with the 1.x binding.
I know there is the GPSTracker binding which could help, but I want to stick with MQTT for this.
The old item configuration I had was:

Switch  PresenceM_PhoneMqttHome "M @ Home" (gLOG)          { mqttitude="mosquitto:owntracks/Matthias/iPhone/event:Home" }

What I understood so far is, that I can transform the incoming value from MQTT, which looks like this:

‘{“t”:“c”,“tst”:1546182339,“acc”:65,“_type”:“transition”,“event”:“leave”,“lon”:XXXXXX,“lat”:YYYYY,“wtst”:1487837532,“tid”:“AA”,“desc”:“BB”}’

with JSONPATH to get out the different values. But the problem is, that I need three values to be checked:

  • event
  • tid
  • desc

Only if these three match the target pattern, the switch should turn ON.
Is this solvable with JSONPATH?

Thanks
Matthias

No, you would use a script transformation instead. Afaik Jsonpath can retrieve multiple values, but you would need to map those three concatenated extracted values to On/Off and that is not possible.

Hi to all, this is my first post.
I’m not familiar with OpenHAB, but as a developer of a mqtt bridge of another system, I got questions from my users, how to get all OpenHAB data bridged to the MQTT broker.
I don’t know exactly the OH wording, but for example, there are a bunch of non-mqtt temperature sensors configured in OpenHAB, is there an example how to configure a generic OH2MQTT bridge? Would this be worth to add an example with the new-rule-engine to the wiki?

I’ve found the MQTT 1 event bus binding, but the Wiki says, “don’t use that”. Would be nice to have a (link to a) simple generic example for the new binding.

Thanks, Christian

See here:

1 Like

So you mean to capture the MQTT message in a string item and then run a rule to extract the values?

I would be interested in what folder and file the paperui stores the settings.

in the userdata folder:
/srv/openhab2-userdata/jsondb (for openHABian)
OR
/var/lib/openhab2/jsondb

1 Like

@matzR I’m using the following to “bridge” between my phone sending Owntracks data via MQTT and the new GPSTracker binding:

val String gpsLoggerUrl = 'http://127.0.0.1:8080/gpstracker/owntracks'
val String json = (Mobile_Owntracks.state as StringType).toString
sendHttpPostRequest(gpsLoggerUrl, "application/json", json)

The Mobile_Owntracks item is bound to my phone’s MQTT topic using the 2.4 binding.

yes there they are, thank you very much:grinning:

Did you found a solution?

No,
This is solvable with a JS transform

I’ve got the same error as this. I tried defining the actions above the rule and in the rule with the same result. I have my broker defined in a file and works fine receiving messages.

Bridge mqtt:broker:synology [ host="192.168.0.12",secure=false ]
{
    Thing mqtt:topic:alarm {
    Channels:
	    Type string : alarmstaterequest "Alarm State" [stateTopic="home/alarm/set", allowedStates="DISARM,ARM_HOME,ARM_AWAY"] 
    }
}

And this is my current rule:

import java.util.concurrent.locks.ReentrantLock

val ReentrantLock lock  = new ReentrantLock()
val actions = getActions("mqtt", "mqtt:broker:synology")

rule "Alarm Panel Action Received"
when
    Item alarmpanelRequest changed
then	
	lock.lock()
    try {
	
		switch(alarmpanelRequest.state.toString) {
			case "DISARM": {
				OhAlarmState.postUpdate("disarmed")
				actions.publishMQTT("home/alarm","disarmed")
				sendPushoverMessage(pushoverBuilder("Disarm").withTitle("Alarm Panel").withSound("falling"))
			}
			case "ARM_HOME": {
				OhAlarmState.postUpdate("home")				
				sendPushoverMessage(pushoverBuilder("Arm").withTitle("Alarm Panel").withSound("falling"))
				actions.publishMQTT("home/alarm","armed_home")
			}
			case "ARM_AWAY": {
				OhAlarmState.postUpdate("armed")
				actions.publishMQTT("home/alarm","armed_away")
				sendPushoverMessage(pushoverBuilder("Arm").withTitle("Alarm Panel").withSound("falling"))
			}
		}		
		
    } catch(Exception e) {
		logError("Error", "Alarm Panel Action Received: " + e.getMessage)
	} finally{
        lock.unlock()
    }
    
end

The actions.publishMQTT failes with
[ERROR] [eclipse.smarthome.model.script.Error] - Alarm Panel Action Received: Instance is not an MQTTActions class.

It works for this guy:

Why are you using a lock?