Unable to get OpenHAB to subscribe to MTTQ

Hi,

I am new to OpenHAB and MQTT and have been struggling to get MTTQ to update the status of a field in OpenHAB for a few days.

Mosquitto seems to be working correctly, I am able publish and subscribe from the command line

System / Config info

Windows 7
Mosquitto 1.4.3
OpenHAB 1.7.1

ddykeman.items file

Number itm_garage_dist “Garage Dist [%.1f Inch]” (ALL) {mqtt="<[mymosquitto:4032:state:default]"}
Contact itm_my_gar_door “Garage Door Status [MAP(en.map):%s]” (ALL)

ddykeman.sitemap

sitemap demo label=“Dykeman Home”
{
Frame label=“Garage”
{
Text item=itm_my_gar_door label=“Garage Door Status [%s]”
}

OpenHAB.cfg

mqtt:mymosquitto.url=tcp://localhost:1883
mqtt:mymosquitto.qos=0
mqtt:mymosquitto.retain=true
mqtt:mymosquitto.async=true

When I use “mosquitto_pub -t 4032 -m 17 -q 1” i can see the command line subscription window get updated but not OpenHAB app

Thanks for any help you can provide… Dave

You are displaying itm_my_gar_door in your sitemap, but the MQTT item binding is on itm_garage_dist. Unless you have a rule somewhere linking the two, there is nothing that is updating the item you are showing your sitemap.

Thanks for the quick response. good catch. I should have included the ddykeman.rules file (See below)

I should have mentioned before that I also do not see any activity in the openhab command window.(i.e. Start.bat) when publishing from mosquitto. However when first executing start.bat I can see MQTT starting

Launching the openHAB runtime…
osgi> 2015-09-16 04:09:20.046 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been started (v1.7.1).
2015-09-16 04:09:20.810 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started
2015-09-16 04:09:21.340 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed.
2015-09-16 04:09:21.340 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2015-09-16 04:09:21.340 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection ‘mymosquitto’
2015-09-16 04:09:22.573 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest

ddykeman.rules file

rule “Convert Door”
when

Item itm_garage_dist received update

then

if(itm_garage_dist.state < 19)

{
itm_my_gar_door.state = OPEN
}
else
{
itm_my_gar_door.state = CLOSED
}

end

Ok - if you are not seeing events on the openHAB event bus then there is obviously something wrong with your MQTT config, but that aside your rule is incorrect also. To update the state of an item you need to do;

itm_my_gar_door.postUpdate(OPEN)

See if that helps.

Thanks Ben

Where do I run this command? Does this go in the .rules file? if so… do I replace “itm_my_gar_door.state = OPEN” with “itm_my_gar_door.postUpdate(OPEN)” and the same for CLOSED or keep both commands…

Sorry i’m a noob…

Thanks Again… Dave

After reading your response again I think I know what you meant… Blame it on lack of sleep Since I’m not seeing the subscription updates in OpenHAB I’m not sure if this new command is working. Is there someway to just execute your command?

I am still unable to receive MQTT subscription updates in OpenHAB. Can someone tell me if my OpenHAB.cfg file entries are correct? am I missing anything?

Thanks Dave

Have you definitely got the MQTT binding jar in your /addons directory (as well as the io.transport.mqtt bundle)?

Thanks Ben, adding the binding jar seems to have fixed the issue. Much Appreciated!! Dave

Hello, we suffer almost the same issue here:

on MQTT (mosquitto) I am listening on any eventual message in the queue:

mosquitto_sub -h 10.10.10.103 -t /#

then I have the following switch:

Switch item=PiLED label=“Pi LED”

that should be issuing the command:

Switch PiLED “Pi LED” (GF_Study) {mqtt=">[mosquitto:home/study/PiLED:command:on:ON],>[mosquitto:home/study/PiLED:command:off:OFF],<[mosquitto:home/study/PiLED/state:state:default]"}

When I switch the slider from the UI a messages appear on the log:

2016-01-12 01:34:58.754 [INFO ] [runtime.busevents ] - PiLED received command ON

But on mosquitto I get no message. I am sure mosquitto by itself is working properly (I am able to read/write on topics independently): what am I missing ?

I would commend looking at your log when you start openhab. I had issues connecting to MQTT at first. But I saw that it wasn’t connecting to the broker in the log. Check that first… Search for MQTT or broker, and post results. Good place to start.

I think the command out-bindings are incorrect, Instead of on:ON and off:OFF you should have ON:on and OFF:off, as in

Switch PiLED "Pi LED"  (GF_Study) {mqtt=">[mosquitto:home/study/PiLED:command:ON:on],>[mosquitto:home/study/PiLED:command:OFF:off],<[mosquitto:home/study/PiLED/state:state:default]"}

The wiki says:

Item itemName {mqtt="<direction>[<broker>:<topic>:<type>:<trigger>:<transformation>]" }

Having this same problem…can someone help please