Can't get OpenHAB2 to see my MQTT messages



  • So, I thought I finally had everything setup properly, but alas something is still not working.

    Overview

    • MySensors.org 2.0 (downloaded about 3 days ago)
    • OpenHAB 2 (installed yesterday)
    • Raspberry Pi (Rasbian 1.9, updated)
    • Mosquitto (whatever the current version is)

    Devices

    • Sensor with a temperature and humidity sensor
    • I'm using the GatewayW5100MQTTClient on an Arduino Uno with a W5100 shield
    • Raspberry Pi 2 B, which is handling the MQTT broker and OpenHAB

    Status

    • Uno+Sensors+Radio is working properly
    • Gateway+Radio+Ethernet is working properly
    • Mosquitto is working properly
    • openHAB 2 is setup, but it doesn't display the sensor results

    As you can see my Arduino side of things is working properly, here is a sample of the messages I receive on my Raspberry Pi when I type mosquitto_sub -v -t 'mygateway1-out/#'

    mygateway1-out/2/1/1/0/0 19.8
    mygateway1-out/2/0/1/0/1 21.2
    

    I'm hoping someone can help me troubleshoot the following code snippets to figure out what's wrong, I'm pretty sure the issue in between OpenHAB 2 and Mosquitto.

    So here goes.

    OpenHAB: Sitemap

    sitemap belmont label="Main Menu"{
    	Frame {
    		Group item=gSF label="Attic" icon="secondfloor"
    		Group item=gFF label="First Floor" icon="firstfloor"
    		Group item=gGF label="Ground Floor" icon="groundfloor"
    		Group item=gC label="Basement" icon="cellar"	
    		Group item=Garden icon="garden" 
    	}
    	Frame label="Basement Monitor" {
    		Text item=BasementMonitor_Temp01
    		Text item=BasementMonitor_Hum01
        }
    }
    

    OpenHAB: Items

    Group All
    
    // Sensor Types
    Group gTemperature (All) // Contains all temperature sensors
    Group gHumidity (All) // Contains all humidity sensors
    
    // Floor Mappings
    Group gSF           "Attic"   		<secondfloor>
    Group gFF           "First Floor"   <firstfloor>
    Group gGF           "Ground Floor"  <groundfloor>
    Group gC            "Basement"      <cellar>
    Group Garden        "Garden"        <garden>
    
    // Room Mappings
    Group SF_Play       "Play Room"     <corridor>      (gSF)
    Group SF_Office		"Office"   		<office>     	(gSF)
    
    Group GF_Living     "Living Room"   <video>     	(gGF)
    Group GF_Dining     "Dining Room"   <video>     	(gGF)
    Group GF_Kitchen    "Kitchen"       <kitchen>   	(gGF)
    Group GF_Corridor   "Corridor"      <corridor>  	(gGF)
    
    Group FF_Bath       "Bathroom"      <bath>      	(gFF)
    Group FF_Kate       "Kate's Room"   <girl1>    		(gFF)
    Group FF_Jake       "Jake's Room"   <boy1>      	(gFF)
    Group FF_Bed        "Master Bedroom"   	<bedroom>   (gFF)
    Group FF_Corridor   "Corridor"      <corridor>  	(gFF)
    
    Group gC_Furnace    "Furnace Room"  <corridor>     	(gC)
    
    Number  BasementMonitor_Temp01  "Temperature [%.1f °C]"  		<temperature>   (gC_Furnace, gTemperature)   {mqtt="<[MyMQTT-2:mygateway1-out/2/1/1/0/0:state:default]"}
    Number  BasementMonitor_Hum01   "Humidity [%.1f %%]"     		<temperature>   (gC_Furnace, gHumidity)      {mqtt="<[MyMQTT-2:mygateway1-out/2/0/1/0/1:state:default]"}
    

    OpenHAB: mqtt.cfg

    openhab.url=tcp://localhost:1883
    openhab.clientId=MyMQTT-2
    

    OpenHAB: mqtt-persistance.cfg

    broker=openhab
    

    OpenHAB: mqtt-eventbus.cfg

    broker=openhab
    stateSubscribeTopic=MyMQTT-2/stateUpdates/${item}/state
    commandSubscribeTopic=MyMQTT-2/commandUpdates/${item}/command
    

    Help

    What am I doing wrong?



  • VICTORY!!!!

    Apparently I just needed to bang my head against the keyboard and randomly try combinations until it worked.

    So to hopefully help other people I'll post how I got it to work.

    OpenHAB: Items

    Number  BasementMonitor_Temp01  "Temperature [%.1f °C]"  		<temperature>   (gC_Furnace, gTemperature)   {mqtt="<[mysensors:mygateway1-out/2/1/1/0/0:state:default]"}
    Number  BasementMonitor_Hum01   "Humidity [%.1f %%]"     		<temperature>   (gC_Furnace, gHumidity)      {mqtt="<[mysensors:mygateway1-out/2/0/1/0/1:state:default]"}
    

    OpenHAB: mqtt.cfg

    mysensors.url=tcp://localhost:1883
    mysensors.clientId=openHAB
    

    OpenHAB: mqtt-persistance.cfg

    broker=mysensors
    

    OpenHAB: mqtt-eventbus.cfg

    broker=mysensors
    stateSubscribeTopic=MyMQTT/stateUpdates/${item}/state
    commandSubscribeTopic=MyMQTT/commandUpdates/${item}/command
    

    Arduino: GatewayW5100MQTTClient

    #define MY_MQTT_CLIENT_ID "mysensors-1"
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
    

    So to summarize here are the key parts (I think):

    • Broker = mysensors
    • clientId = openHAB
    • pattern for items = {mqtt="<[mysensors:mygateway1-out/2/0/1/0/1:state:default]"}

    I'm still not sure if the second and third line in the mqtt-eventbus.cfg is correct. I don't have MyMQTT anywhere else, so I think I may try different combinations to see what works.



  • Hi! Can you post your arduino sketches as well??

    Thanks!



  • This helped me out a lot, thanks!



  • @micah said in Can't get OpenHAB2 to see my MQTT messages:

    I'm still not sure if the second and third line in the mqtt-eventbus.cfg is correct. I don't have MyMQTT anywhere else, so I think I may try different combinations to see what works.

    MyMQTT should be replaced with brokername (mysensors in this example). openhab will then publish the event to the mqtt broker on its topics (useful if you use f.eks. node-red for openhab rules)



Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.6k
Posts