Configuration Mysensors MQTT push button

Openhab 4.0.2
hardware: RPi

Hi,
I already have some Mysensors based temperature sensors and relays, what I am going to extend with a doorbell. Every relay and sensors work well, but I can’t make this push button work.

The sensor communicates with the MQTT broker well, but I can’t connect it properly to an Item. Do you have any idea why I can’t represent the MQTT messages as an Item?

MQTT messages on the broker
The sensor communicates with the broker well, but I can’t connect it to an Item. This is an example of messages sent/recieved by the MQTT broker.

// MQTT communication on the broker. example
//presentation of the sensor on the network
mysensors-gateway-out/102/255/0/0/17 2.3.1 
mysensors-gateway-out/102/255/3/0/6 0
mysensors-gateway-out/102/255/3/0/11 Zone Controller Relay //name of the sensor
mysensors-gateway-out/102/255/3/0/12 0.33 // version of the sensor sketch
mysensors-gateway-out/102/1/0/0/3 (null) //Relay 1
mysensors-gateway-out/102/2/0/0/3 (null) // Relay 2
mysensors-gateway-out/102/3/0/0/0 (null) // Push button
mysensors-gateway-in/102/1/1/0/2 0 // relay 1 turned off
mysensors-gateway-in/102/1/1/0/2 1 //relay 1 turned on
mysensors-gateway-out/102/3/1/0/16 0 //push button pushed
mysensors-gateway-out/102/3/1/0/16 1 //push button released
//etc.

Thing file
This is a sensor which handle two relays and the doorbell push button

Thing mqtt:topic:GardenRelay "Garden relay kapcsoló ID 102" (mqtt:broker:MySensorsMqttBroker){
	Channels:
		Type switch : lamp "Lamp1" [ 
			commandTopic="mysensors-gateway-in/102/1/1/0/2", 
			on=1, 
			off=0
		]
		Type switch : gardengate "Garden door" [ 
			commandTopic="mysensors-gateway-in/102/2/1/0/2",
			on=1, 
			off=0
		]
		Type switch : gardendoorbell "Doorbell" [
			commandTopic="mysensors-gateway-out/102/3/1/0/16",
			on=0,
			off=1
		]
}

Related Items file

Switch os_garden_lamps   "Lamp"   (Outside, Lamps, Outside_lamps, Outside_walk_lamps)     { channel="mqtt:topic:GardenRelay:lamp"}
Switch os_garden_door    "Garden door"   (Outside)  { channel="mqtt:topic:GardenRelay:gardengate"}
Switch os_garden_doorbell   "Garden doorbell"  (Outside) { channel="mqtt:topic:GardenRelay:gardendoorbell"}

Thank you

Use strings…

Thing mqtt:topic:GardenRelay "Garden relay kapcsoló ID 102" (mqtt:broker:MySensorsMqttBroker){
	Channels:
		Type switch : lamp "Lamp1" [ 
			commandTopic="mysensors-gateway-in/102/1/1/0/2", 
			on="1", 
			off="0"
		]
		Type switch : gardengate "Garden door" [ 
			commandTopic="mysensors-gateway-in/102/2/1/0/2",
			on="1", 
			off="0"
		]
		Type switch : gardendoorbell "Doorbell" [
			commandTopic="mysensors-gateway-out/102/3/1/0/16",
			on="0",
			off="1"
		]
}

No, sorry it didn’t solve the issue. Please don’t forget that the two other switches already work like a charm, despite states defined as numeric values. the only diff (what I can see) between relays and the button is the MQTT topic. I guess it shouldn’t have effect on it. :thinking:
Can I debug it somehow, what do you think?

A command topic is the topic that OH publishes to when the Item receives a command. The state topic is the topic that OH receives messages from.

You’ve only configured command topics so OH can only publish and will never receive any messages and therefore the Items will never change.

Sensors will usually only have a state topic and actuators will usually have both a state topic and a command topic, and usually they are not the same topic.

1 Like

Didn’t catch this part.

First, with a deeper look at your definition :slight_smile: although working, it’s wrong.
As you built the connection between Bridge and Thing manually, you chose the wrong UID for the Thing.
Second (and that’s the point why the doorbell input doesn’t work as expected: You have to use stateTopic for incomming messages.

So the correct Thing should be:

Thing mqtt:topic:MySensorsMqttBroker:GardenRelay "Garden relay kapcsoló ID 102" (mqtt:broker:MySensorsMqttBroker) {
    Channels: 
    Type switch : lamp "Lamp1" [
        commandTopic="mysensors-gateway-in/102/1/1/0/2", on="1", off="0"
    ]
    Type switch : gardengate "Garden door" [
        commandTopic="mysensors-gateway-in/102/2/1/0/2", on="1", off="0"
    ]
    Type switch : gardendoorbell "Doorbell" [
        stateTopic="mysensors-gateway-out/102/3/1/0/16", on="0", off="1"
    ]
}

Be aware that also the links are changed.

Switch os_garden_lamps    "Lamp" (Outside, Lamps, Outside_lamps, Outside_walk_lamps) { channel="mqtt:topic:MySensorsMqttBroker:GardenRelay:lamp"}
Switch os_garden_door     "Garden door"     (Outside)                                { channel="mqtt:topic:MySensorsMqttBroker:GardenRelay:gardengate"}
Switch os_garden_doorbell "Garden doorbell" (Outside)                                { channel="mqtt:topic:MySensorsMqttBroker:GardenRelay:gardendoorbell"}

If you’re creating a mqtt things channel through UI, the broker UID will always be part of the UIDs. Although this is not strictly necessary, it’s best practice to set the UIDs the same way

Please keep in mind, that on and off parameters are strings, not numbers (strange thing, that openHAB doesn’t complain about missing quotes).

Yes, this was the mistake. I should use stateTopic.
Thank you for the hint!

Thank you for these additional improvement suggestions!

Hi Udo,
just to inform you I also updated all my MQTT items, as you suggested. I extended the channel definition with the Broker UID, but all my items stopped working. I got following error for all.

"No ThingHandlerFactory found for thing mqtt:topic:TempSensorBathroom (thing-type is mqtt:topic). Deferring initialization."

I returned to the previous solution. I just wanted to let you know. :wink:

Obviously, you have to change the channel UID on both places :wink: not only on the channel side.