# Trouble configuring MQTT on openhab 2.5

**URL:** <https://community.openhab.org/t/trouble-configuring-mqtt-on-openhab-2-5/112663>\
**Category:** Other\
**Tags:** mqtt, binding\
**Created:** [January 3, 2021, 8:43am UTC](https://community.openhab.org/t/trouble-configuring-mqtt-on-openhab-2-5/112663 "2021-01-03T08:43:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![StefaanV](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@StefaanV](https://community.openhab.org/u/StefaanV)\
**Post date:** [January 3, 2021, 8:43am UTC](https://community.openhab.org/t/trouble-configuring-mqtt-on-openhab-2-5/112663/1 "2021-01-03T08:43:36Z")

</div>

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

```auto
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)

```auto
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" }

```

---

<div class="post-metadata">

**Author:** ![hafniumzinc](https://community.openhab.org/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@hafniumzinc](https://community.openhab.org/u/hafniumzinc)\
**Post date:** [January 3, 2021, 8:49am UTC](https://community.openhab.org/t/trouble-configuring-mqtt-on-openhab-2-5/112663/2 "2021-01-03T08:49:01Z")

</div>

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:

```auto
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…

---

<div class="post-metadata">

**Author:** ![StefaanV](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@StefaanV](https://community.openhab.org/u/StefaanV)\
**Post date:** [January 3, 2021, 9:14am UTC](https://community.openhab.org/t/trouble-configuring-mqtt-on-openhab-2-5/112663/3 "2021-01-03T09:14:32Z")

</div>

@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 😃

---

<div class="post-metadata">

**Author:** ![StefaanV](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@StefaanV](https://community.openhab.org/u/StefaanV)\
**Post date:** [January 3, 2021, 9:33am UTC](https://community.openhab.org/t/trouble-configuring-mqtt-on-openhab-2-5/112663/4 "2021-01-03T09:33:52Z")

</div>

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

```auto
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

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

```

---

<div class="post-metadata">

**Author:** ![hafniumzinc](https://community.openhab.org/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@hafniumzinc](https://community.openhab.org/u/hafniumzinc)\
**Post date:** [January 3, 2021, 9:36am UTC](https://community.openhab.org/t/trouble-configuring-mqtt-on-openhab-2-5/112663/5 "2021-01-03T09:36:07Z")

</div>

Try a restart of openHAB.

---

<div class="post-metadata">

**Author:** ![StefaanV](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@StefaanV](https://community.openhab.org/u/StefaanV)\
**Post date:** [January 3, 2021, 9:37am UTC](https://community.openhab.org/t/trouble-configuring-mqtt-on-openhab-2-5/112663/6 "2021-01-03T09:37:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hafniumzinc](https://community.openhab.org/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@hafniumzinc](https://community.openhab.org/u/hafniumzinc)\
**Post date:** [January 3, 2021, 9:54am UTC](https://community.openhab.org/t/trouble-configuring-mqtt-on-openhab-2-5/112663/7 "2021-01-03T09:54:50Z")

</div>

> [@StefaanV](#):
>
> Strange

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.](https://community.openhab.org/t/oh2-mqtt-standalone-server-with-text-file-config/110330/4)

> [@StefaanV](#):
>
> Any suggestion for the actuator side of things ?

Is that the same question as this?

> [@StefaanV](#):
>
> Is there a way to push all the items states to MQTT with one configuration ? That would make my day

If so, I don’t know I’m afraid. Maybe using one half of an [MQTT Event Bus](https://community.openhab.org/t/mqtt-2-5-event-bus/76938), but not sure if it’s relevant?

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

---

<div class="post-metadata">

**Author:** ![StefaanV](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@StefaanV](https://community.openhab.org/u/StefaanV)\
**Post date:** [January 3, 2021, 10:15am UTC](https://community.openhab.org/t/trouble-configuring-mqtt-on-openhab-2-5/112663/8 "2021-01-03T10:15:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hafniumzinc](https://community.openhab.org/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@hafniumzinc](https://community.openhab.org/u/hafniumzinc)\
**Post date:** [January 3, 2021, 10:34am UTC](https://community.openhab.org/t/trouble-configuring-mqtt-on-openhab-2-5/112663/9 "2021-01-03T10:34:35Z")

</div>

> [@StefaanV](#):
>
> because it is a v1 binding

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

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [January 3, 2021, 4:00pm UTC](https://community.openhab.org/t/trouble-configuring-mqtt-on-openhab-2-5/112663/10 "2021-01-03T16:00:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![StefaanV](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@StefaanV](https://community.openhab.org/u/StefaanV)\
**Post date:** [January 9, 2021, 9:05am UTC](https://community.openhab.org/t/trouble-configuring-mqtt-on-openhab-2-5/112663/11 "2021-01-09T09:05:53Z")

</div>

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

```auto
  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`

```auto
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.
