MQTT issue after migration to OpenHAB 2

Hi all

Just decided to move to OpenHAB 2 from an earlier version and have faced some slight issues with MQTT.

Previous version - all working fine.
OpenHAB 2 - only analogue sensor values are read. No digital values read nor messages sent.

Now running a Raspberry Pi with OpenHABianPi installed. Setup was fairly easy. MQTT binding installed, actions etc and then copied my items file across into the \OPENHABIANPI\openHAB-conf\items directory via the Samba service (using Windows to setup). I also moved my sitemap across into the relevant folder.

Surprised that I cannot edit MQTT settings within the PaperUI, I’ve edited the mqtt.cfg file and mqtt-eventbus.cfg files which were automatically created upon binding install. I’ve literally copied settings from the openhab.cfg file on the previous version.

I want to keep my Mosquitto MQTT broker on a separate Pi - in fact its my original that still has the previous version of OpenHAB running simultaneously until OpenHAB is working, so rather than localhost in the config files I’ve included the IP address and port. The two Pi’s are on my local network, with firewall exceptions for port 1883 etc. Using mqttlens I can see messages flying to/from devices/broker as normal.

mqtt.cfg file:

#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
localbroker.url=tcp://172.16.1.230:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
localbroker.clientId=OpenHAB

# Optional. User id to authenticate with the broker.
#<broker>.user=<user>

# Optional. Password to authenticate with the broker.
#<broker>.pwd=<password>

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
localbroker.qos=1

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
localbroker.retain=true

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
localbroker.async=true

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>

mqtt-eventbus.cfg

# Name of the broker as it is defined in the openhab.cfg. If this property is not available, no event bus MQTT binding will be created.
broker=localbroker

# When available, all status updates which occur on the openHAB event bus are published to the provided topic. The message content will 
# be the status. The variable ${item} will be replaced during publishing with the item name for which the state was received.
statePublishTopic=openHAB/stateUpdates/${item}/state

# When available, all commands which occur on the openHAB event bus are published to the provided topic. The message content will be the 
# command. The variable ${item} will be replaced during publishing with the item name for which the command was received.
commandPublishTopic=openHAB/commandUpdates/${item}/command

# When available, all status updates received on this topic will be posted to the openHAB event bus. The message content is assumed to be 
# a string representation of the status. The topic should include the variable ${item} to indicate which part of the topic contains the 
# item name which can be used for posting the received value to the event bus.
stateSubscribeTopic=Ourplace/${item}/state

# When available, all commands received on this topic will be posted to the openHAB event bus. The message content is assumed to be a 
# string representation of the command. The topic should include the variable ${item} to indicate which part of the topic contains the 
# item name which can be used for posting the received value to the event bus.
commandSubscribeTopic=Ourplace/${item}/command

Here are one of my digital and analog items:

Switch Light_GF_Dining_Stand		"Stand Lamp" 					(GF_Dining, Lights_GF)		{mqtt=">[localbroker:Ourplace/Kitchen/RF/=02:command:ON:default],>[localbroker:Ourplace/Kitchen/RF/=02:command:OFF:default]"}
Number Temperature_GF_Kitchen 	"Temperature [%.1f °C]"	<temperature>	(Temperature, GF_Kitchen, FTS1)		{mqtt="<[localbroker:Ourplace/Kitchen/DHT22-1/T:state:default]"}

My analog sensor values such as temperature, humidity from devices are passing through my broker and being presented on the OpenHAB 2 GUI perfectly. I can edit the mqtt.cfg topics and intentionally make them invalid, proving loss of comms etc.

When I change state of an item on OpenHAB 1.x, I see the broker receive the message and I would expect the state of that item to then change in OpenHAB 2 GUI (as its reading the broker). This does not happen.

When I change the state of an item in OpenHAB 2 I would expect to see a message be presented at the broker. Instead, nothing appears.

I suspect there if the issue was just publishing, this may be easier to solve. The fact that OpenHAB 2 is not reading digital values but does read analog values causes me some concern.

Assistance resolving this would be fantastic.

Thank you.

Are you missing your tmp directory /var/lib/openhab2/tmp? I think the MQTT transport needs this temp directory, and a recent issue with a distro caused it to be removed. Might be related.

Also, were you using the MQTT Event Bus binding in your previous setup, or have you now added that as a difference from your previous setup?

Hi John

Thanks for getting in touch.

The tmp directory you’ve mentioned is in place. I’ve browsed to the directory and can see entries for localbroker and mosquitto - two broker names I tried.

In the previous version all of the bindings were in the main config file as you probably know, and part of that was the event bus element. I’ve taken the details relating to even bus from the original single config file and put them into the specific event-bus binding file in OH2.

Thank you.

OK, so you have both instances of openHAB (1.x and 2) referring to the same broker, both running identical configs? Every clientId has to be unique to the broker, so that’s an issue right there. I think there would be other problems for the MQTT Event Bus binding as well. Would the MQTT Item binding be more appropriate to your purpose?

Hi John

I knew that both versions should have unique clientId but thought that if I set them the same for now it may eliminate any problem with the clientId…eg it works for one so why not the other…but it could clash I suppose. Have changed it now and unfortunately no clear benefit yet.

MQTT Item binding probably is more appropriate, yes; particularly as I’m defining MQTT topics for every item! I shall delve into this in a little while.

Thank you

John

With every item already having an assigned MQTT binding topic against it, I have now commented out the subscribe and publish topics in the mqtt-eventbus binding file.

Is this correct?

Aaron

I believe so. If you just want to have individual items listen to or publish on specific topics (by far the most common setup), then you just need the plain MQTT item binding and mqtt="..." in your .Items file.

Ok John

I have the following files:

Note I’ve hashed the name of the eventbus file so to prevent it being found and used.

MQTT item:

Switch Light_GF_Kitchen_NetCtrl		"Network Control On/Off"									{mqtt=">[localbroker:Ourplace/Kitchen/Out/=46:command:ON:default],>[localbroker:Ourplace/Kitchen/Out/=46:command:OFF:default]"}

This does not seem to be working, nor are the analog MQTT values I was reading on the GUI before.

Aaron

At the openhab> prompt, type

config:delete org.openhab.mqtt-eventbus

to make sure the MQTT Event Bus binding configuration is gone. (Just renaming the .cfg file won’t purge the configuration from the OSGi ConfigurationAdminManager).

Likewise, I recommend you also disable MQTT Persistence service, at least until the basic MQTT item binding is working and you also know you need the MQTT Persistence service. To do that, make sure all keys in the mqtt-persistence.cfg are commented out with a # at the beginning of the line, and then at the openhab> prompt type:

config:delete org.openhab.mqtt-persistence

Try help config to look around other configuration information to make sure it looks correct.

Hi John

Using SSH these are invalid commands!?

Hi, @watou says about OH2 karaf console, please try ssh openhab@localhost -p 8101 with password habopen

Thank you. Have done this and unfortunately no change.

My only remaining idea is to put mosquitto on the same Pi as OH2 and run it
to see if this works? Maybe there is a problem with openhabianpi
connecting to network mosquitto brokers?

Update:

I have installed mosquitto on the same hardware as OH2, and have modified the mqtt.cfg file to look at broker address localhost:1883. This was to rule out any network problems.

I have changed the IP address of my OH2 hardware to that of the old OH/Mosquitto hardware which is now disconnected. Using MQTTlens I am connected to mosquitto and can see message flowing from my devices - so I know this is working.

On the OH2 interface, items are still not showing device values or able to send MQTT output.

This would suggest the problem is local with config?

Once again, my config is below.
My items file is stored in: \OPENHABIANPI\openHAB-conf\items
My mqtt.conf file is stored in: \OPENHABIANPI\openHAB-conf\services

One of my analog input items:

Number Temperature_GF_Living 	"Temperature [%.1f °C]"	<temperature>	(Temperature, GF_Living, FTS1)		{mqtt="<[localbroker:Ourplace/Living/DHT22-1/T:state:default]"}

One of my digital output items:

Switch Light_GF_Dining_Stand		"Stand Lamp" 					(GF_Dining, Lights_GF)		{mqtt=">[localbroker:Ourplace/Kitchen/RF/=02:command:ON:default],>[localbroker:Ourplace/Kitchen/RF/=02:command:OFF:default]"}

MQTT.conf

#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
localbroker.url=tcp://localhost:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
localbroker.clientId=OpenHAB

# Optional. User id to authenticate with the broker.
#<broker>.user=<user>

# Optional. Password to authenticate with the broker.
#<broker>.pwd=<password>

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
localbroker.qos=1

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
localbroker.retain=true

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
localbroker.async=true

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>