Trouble configuring MQTT on openhab 2.5

Hi guys,

I’m having trouble configuring MQTT on my openHAB 2.5 configuration.
I’m trying to merge different community examples into my setup but it seems I’m missing something.
I want to have item states external to openHAB to be able to write automation scripts in typescript as I’m having a really hard time wrapping my head around the built-in script language and libraries.
My configuration is in files as I’ve had some unfortunate events where the PaperUI config went missing after a wrong maneuver in the Karaf interface.
Here’s what I have so far

  • openHAB 2.5 setup on openhabian (rPi3)
  • Mosquitto broker (default openhabian setup)
  • Mqtt spy on my PC
  • Bindings: MySensors, modbus, tado, hue, rfxcom

Basically, with the below setup, openHAB isn’t posting the state to the mosquitto broker. Changing the state of the dc_test item does work.

mqtt.things file

Bridge mqtt:broker:automat "MQTT automat Broker" @ "MQTT" [ 
  host="localhost",
  secure=false,
  port=1883,
  qos=0,
  retainMessages=false,
  clientID="openhab",
  keep_alive_time=30000,
  reconnect_time=60000,
  username="",
  password=""
]
{
Thing topic dcs {
	Channels:
		Type contact : dc_test "dc_test" [
			stateTopic = "home/automat/dc_test/state",
			commandTopic = "home/automat/dc_test/set"
		]
	}
}

aqara.items file (extract)

Contact                 dc_test                     "Contact [%s]"                    <door>          { channel="deconz:openclosesensor:homeserver:dc_test:open" , channel="mqtt:topic:automat:dcs:dc_test"}
Number                  dc_test_bat                 "Batterij [%.1f %%]"              <battery>       { channel="deconz:openclosesensor:homeserver:dc_test:battery_level" }
DateTime                dc_test_laatste             "Laatste update [%1$ta %1$tR]"    <time>          { channel="deconz:openclosesensor:homeserver:dc_test:last_updated" }

Are you trying to get your MQTT Channel to follow your Deconz Channel? At the moment you don’t have it setup correctly for that - you will need to use the follow profile.

Try:

Contact dc_test "Contact [%s]" <door> { channel="deconz:openclosesensor:homeserver:dc_test:open" , channel="mqtt:topic:automat:dcs:dc_test"[profile="follow"]}

But that will only follow. Your commandTopic won’t be pushed to your Deconz Channel…

@hafniumzinc thanks for helping out.
For the doorcontact sensor, I only want to export the state to MQTT.
After that, I’ll need to be able to command actuators (lights and shades mostly) from MQTT.
I’ll give your suggestion a go.

Is there a way to push all the items states to MQTT with one configuration ? That would make my day :smiley:

Now this is really bizarre, I changed the config to the below
now the sensor data is published to MQTT topic home/automat/light/badkamer/set ! How does that work ?

mqtt things setup

Bridge mqtt:broker:local "MQTT local Broker"  [ ... ]
{
  Thing topic dcs {
    Channels:
      Type contact : dc_test "dc_test" [  
        commandTopic = "home/automat/sensor/dc_test"
      ]
    }
  Thing topic lights {
    Channels:
      Type switch : licht_badkamer "licht badkamer" [
        stateTopic = "home/automat/light/badkamer/state",
        commandTopic = "home/automat/light/badkamer/set"
      ]
    }
}

Item setup unchanged

Contact   dc_test   "Contact [%s]"    { channel="deconz:openclosesensor:homeserver:dc_test:open" , channel="mqtt:topic:local:dcs:dc_test"[profile="follow"]}

Try a restart of openHAB.

OK, restarting openhab solved this issue. Strange.
Any suggestion for the actuator side of things ?

There’s a long standing bug when saving a Things file - openHAB doesn’t always load it up correctly. A restart usually fixes it, or you can do this.

Is that the same question as this?

If so, I don’t know I’m afraid. Maybe using one half of an MQTT Event Bus, but not sure if it’s relevant?

I think it’ll be far less effort to get actual rules working…

OK, I’ll give the eventbus a try.
I thought it had been discontinued because it is a v1 binding

It’s not a binding itself - just s particular setup and configuration using the MQTT Binding.

Comment; You cannot send commands to a Contact type Item, whch in turns means you cannot have a functional commandTopic on its MQTT channel.

Yes, I know that. Strangely, with the mqtt.things configuration

  Thing topic dcs {
    Channels:
      Type contact : dc_test "dc_test" [  
        stateTopic = "home/automat/sensor/dc_test/state",
        commandTopic = "home/automat/sensor/dc_test"
      ]
    }

and the aqara.items

Contact dc_test { channel="deconz:openclosesensor:homeserver:dc_test:open" , channel="mqtt:topic:local:dcs:dc_test"[profile="follow"]}

The state gets pushed to the commandTopic (home/automat/sensor/dc_test), not to the stateTopic as one might expect.