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]”
}
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
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;
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…
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?
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.