I’m new to openHAB and MQTT. To learn how to use both together I have them set up as follows:
I use the docker image of openHAB 3.2.0 and eclipse mosquitto 2.0.14
Ubuntu 20.04.4 is running with VMWare on an intel® Core™ i7-8550U Windows PC
So far I managed to configure switches by creating a topic with MQTT.fx, using a local MQTT broker and creating a MQTT thing with a channel set to said topic and an switch item. It works without trouble and status and changes are observable on my MQTT Explorer as I use the switch on the openHAB GUI.
here is the yaml of the MQTT Thing channel:
UID: mqtt:topic:d49d2ed101:96e2c089e0
label: Test Switch
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:d49d2ed101
location: Labor Raum 2
channels:
id: TestSwitch
channelTypeUID: mqtt:switch
label: Test Switch
description: “”
configuration:
commandTopic: labor/raum2/testswitch
stateTopic: labor/raum2/testswitch
off: OFF
on: ON
Now I want to send my used memory value from the systeminfo binding to the MQTT topic. But no values reach the topic. I can only publish values with MQTT.fx which are shown in openHAB.
This yaml shows how I set up the channel in a way, that I can send values with MQTT.fx to openHAB and they stay in MQTT Explorer but will be overwritten in openHAB only by the systeminfo item.
UID: mqtt:topic:d49d2ed101:SysteminfoRAM
label: Systeminfo RAM
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:d49d2ed101
location: Labor Raum 1
channels:
Indentation is critical in YAML. Please pose using code fences.
```
code goes here
```
From a quick look, you’ve only defined a stateTopic. If you want to publish something on a command to an Item, you need to define a commandTopic. Then when the Item linked to that Channel receives a command, the command will be published as an MQTT message. If you only have a stateTopic, the Channel is read only and OH will not ever publish to them.
You’re not sending any commands to your Item though, are you?
The general openHAB process to communicate to the outside world is to send a command to an Item.
The counterpart process, where the world tells us something, arrives at Items as a state update.
Two deliberately different processes, as they must be if we don’t want to go round and round in loops.
It sounds like your Item is getting state updates from here?
The MQTT binding won’t act on those, not commands.
There is a tool to work around this and bend the usual architecture.
Apply a follow profile to the link between your Item and the MQTT binding. This will change the usual action, so that an Item update gets presented to MQTT binding as though it were a command instead.
And don’t have any stateTopic at all on your MQTT channel - there you are building a loop.