Converting to new MQTT binding - one Thing is not updating

  • Platform information:
    • Hardware: i3-3220/8gb RAM/500Gb HDD
    • OS: Ubuntu 18.04.2 LTS
    • Java Runtime Environment: Java SE Runtime 1.8.0.121-b13
    • openHAB version: openHAB 2.4.0 Release Build
  • Issue of the topic:
    Cannot get MQTT status information from one particular sensor.
    I have many items that I have converted from the old binding to the new binding, however this is one that I can’t seem to do in the new binding. I am not sure why this one just won’t work.

I have a simple MQTT weatherstation updating to Weather Underground, and it also publishes data to the topic ‘weatherstation’.

The data is presented in the following json:

{"TempC":"23.37","DewPoint":"15.74","Humidity":"62.20","Pressure":"1016.00","Battery":"3.14"}

In the old MQTT binding, I would read this into OpenHAB using the following item configuration:

String WUSensor					"[%s]" {mqtt="<[mc:weatherstation:state:default]"}
DateTime WUSensor_LastUpdate	"WU Tx Update [%1$ta %1$tR]"		<clock>
Number WUBattery_Status			"WUnderground Tx: [%.2f V]"	(wusensor)	{mqtt="<[mc:weatherstation:state:JSONPATH($.Battery)]"}
Number WUHumidity				"Humidity: [%.2f%%]"					(wusensor)	{mqtt="<[mc:weatherstation:state:JSONPATH($.Humidity)]"}
Number WUPressure				"Pressure: [%.2f]"						(wusensor)	{mqtt="<[mc:weatherstation:state:JSONPATH($.Pressure)]"}
Number WUTemperature			"Temperature: [%.2f°C]"					(wusensor)	[ "CurrentTemperature" ] {mqtt="<[mc:weatherstation:state:JSONPATH($.TempC)]"}

I’ve since tried to convert it to the newer MQTT binding, and it does not seem to be reading/updating the values in OpenHAB.

mqtt.fx shows the data is coming in, and I have this written to a separate database using Node-Red for logging/troubleshooting retrospectively.

There are no logs in the events.log or openhab.log to show that this is actually receiving the data which is weird.

I’ve posted below the information of the configuration - open to any help as I have spent a week trying to get this working and it just is baffling me why this doesn’t.

  • Items configuration related to the issue
String WUSensor					 {channel="mqtt:topic:mc:WUndergroundSensor:rawdata"}
Number WUBattery_Status			"WUnderground Tx: [%.2f V]"	            (wusensor)	{channel="mqtt:topic:mc:WUndergroundSensor:batteryvoltage"}
Number WUHumidity				"Humidity: [%.2f%%]"					(wusensor)	{channel="mqtt:topic:mc:WUndergroundSensor:humidity"}
Number WUPressure				"Pressure: [%.2f]"						(wusensor)	{channel="mqtt:topic:mc:WUndergroundSensor:pressure"}
Number WUTemperature			"Temperature: [%.2f°C]"					(wusensor)	[ "CurrentTemperature" ] {channel="mqtt:topic:mc:WUndergroundSensor:temp_c"}
  • Sitemap configuration related to the issue
		Text item=WUBattery_Status valuecolor=[WUSensor_LastUpdate>10="green",WUSensor_LastUpdate>15="orange", WUSensor_LastUpdate>20="red"]
			Text item=WUSensor_LastUpdate
Text item=WUSensor
  • Rules code related to the issue
// Creates an item that stores the last update time of this item
rule "Records last Wunderground Battery update time"
when
  Item WUTemperature received update
then
  postUpdate(WUSensor_LastUpdate, now.toString())
end

  • Services configuration related to the issue
Bridge mqtt:broker:mc "Mosquitto" @ "MQTT"[ host="localhost", port="1883", secure=false , username="myusername", password="mypassword" ] {

Thing topic PIRHall "Hallway PIR" @ "MQTT" {
    Channels:
        Type contact : hall "Hallway PIR" [ stateTopic="stat/sensor/hall_pir" ]
        }

Thing topic WUndergroundSensor "Weather Underground Sensor" @ "MQTT" {
        Channels:
        Type string : rawdata           "Raw Data"               [ statetopic="weatherstation"]
        Type number : batteryvoltage    "Battery Voltage"        [ statetopic="weatherstation", transformationPattern="JSONPATH:$.Battery"]
        Type number : humidity          "Humidity"               [ statetopic="weatherstation", transformationPattern="JSONPATH:$.Humidity"]             
        Type number : pressure          "Air Pressure"           [ statetopic="weatherstation", transformationPattern="JSONPATH:$.Pressure"]
        Type number : temp_c            "Temperature_C"          [ statetopic="weatherstation", transformationPattern="JSONPATH:$.TempC"]
        Type number : dewpoint          "Dew Point"              [ statetopic="weatherstation", transformationPattern="JSONPATH:$.DewPoint"]
     }
}

Hello,

Maybe an idea, your json presents values as strings. Should it be as float instead ? And if you can’t change this you should handle a conversion.

Have you checked what PaperUI shows for the MQT things? Are the broker and the generic things online?
Are you using the correct channel syntax? The correct one is shown under each channel.
Does the log show any related messages after startup?

[Edit]
What topic are you subscribing to with mqttfx? Only “weatherstation”?

The json is presented as strings currently. I’m not too fussed about that at this stage.

This is how it is shown in mqtt.fx:

I’ve tried to go back to basics and just bring in the string that is returned by the sensor into MQTT:

String WUSensor					 {channel="mqtt:topic:mc:WUndergroundSensor:rawdata"}

This should in theory mean that I can see this in the sitemap text item. This works in the old MQTT binding, but in the new one, it doesn’t update this.

Currently in PaperUI it shows the last update done when it was on the old MQTT binding (as I have a rule that retrieves the last written item to the persistence database and populate this back in case of power outage or restarting OpenHAB), and if I disable the persistence it does not update at all, despite seeing this update in MQTT.fx

Initially I thought it might not like the fact the topic was a single word, so I have duplicated the payload into the topic “tele/weatherstation”, however this is also not seen by OpenHAB when changing the statetopic in the mqtt.things file. (I’ve made sure I restart after updating the file, as I have seen other posts about this being an issue with the new binding).

I’ve tried to shift around the things in the mqtt.things file, in case there was some sort of interference from another item - however it does not make a difference to where this is located in the things file, this particular thing is not updating, but every other thing in the file is working fine.

I’ve tried to create this in the PaperUI directly as well and it exhibits the same behavior.

The broker and generic thing is online. And all other MQTT subscriptions seem to be working for the rest of the house (lights, other sensors).

Is there any extra logging I can enable for this? I have looked in the events.log and openhab.log files, but there is nothing referencing the weatherstation topic item.

I

Sorry for asking twice, but please confirm you are using only the topic “weatherstation” in mqtt.fx? (I’m not familiar with picture you posted, I’m using mqtt spy).

EDIT:
If you changed something about the MQTT Things in the file setup, version 2.4 is known to have an issue that the broker isn’t reallly connected anymore. A restart of openHAB would solve that.

Did setup my TestRaspi with openHAB 2.4 and MQTT. Setting all up via PaperUi, I had to restart OpenHAB to get the Generic Thing ONLINE (yours is online!). I’m using the same stateTopic as used/subscribed on Mqtt.spy (“tele/sonoff_TH/SENSOR”) and I’m getting the expected JSON string.

Yes, this is only the topic “weatherstation”.

If I get some time, I might spin up a new vm and see if I can get this to work on my ‘non-live’ setup