Mqtt-binding - diferent retain bit

Tags: #<Tag:0x00007fd311be1a90>

(Dimitar Dragoev) #1

I need to set different retain bit based on item when OH2 publish a message.

For example if I turn off Item_1
Switch Item_1 {mqtt=">[broker:/def/relay1:command:OFF:1]"} - to have Retained but
For example if I turn off Item_2
Switch Item_2 {mqtt=">[broker:/def/relay2:command:OFF:1]"} - not to have retain bit

Now as I can see this is set globally when configure the broker


(Rich Koshak) #2

File a feature request Issue on the openhab1-addons repo. Though given that most of the effort is focused on the MQTT 2 binding you should look in the openhab2-addons repo for the WIP issue on MQTT 2 and chime in there as well.

(Nadir Syed) #3

I also wish to have a way of selecting when to retain or not retain messages.

(Magcode) #4


would also appreciate this feature

(Rich Koshak) #5

On a different thread it occurred to me that you can set the retain bit in the broker config in mqtt.cfg. So if you need some Items to have the retain bit enabled, just define two brokers, one with the retain bit and one without. Then:

Switch Item_1 {mqtt=">[retain-broker:/def/relay1:command:OFF:1]"}
Switch Item_2 {mqtt=">[broker:/def/relay2:command:OFF:1]"}

The same would go for QOS settings.

(Magcode) #6

OH! That is brilliant!
Problem solved. Thanks @rlkoshak

(Dimitar Dragoev) #7

Thanks @rlkoshak for the hint !