Hello Forum,
I am a new user here although I have been lurking these forums for a while and have been trying to learn how to use openHAB in order to implement it in my now-under-construction house.
Today I faced a strange issue where an MQTT message causes multiple updates items on that topic. I would like to confirm if this is an expected behavior or is it a bug.
The issue appears when configuring a Generic MQTT thing with multiple channels, if 1 channel is defined using wildcard (#) and others using full topic name, then any message to that topic results in updating all the linked items twice, if the message is sent to a different topic then the item with wildcard updates only once. Changing the channel from wildcard to full topic causes all the items to update only once as expected.
This behavior is confirmed using MQTT.fx and KARAF console. (see below)
- Platform information:
- Hardware: RPI 3 B
- OS: openHABian v1.5
- Java Runtime Environment: java -version (openjdk version “1.8.0_222”)
- openHAB version: openHAB 2.5.4-1 (Release Build)
- Issue of the topic: single MQTT message causes multiple updates of items if one of the items is subscribed using wildcard and other items are subscribed to the same topic.
- Please post configurations (if applicable):
*Things
Broker
Bridge mqtt:broker:mosquitto "MQTT Broker: Mosquitto" [ host="localhost", port=1883, secure=false, clientID="openHAB2" ]
*Generic MQTT Thing
Thing mqtt:topic:mqttTest "mqtt topic test" (mqtt:broker:mosquitto){
Channels:
Type string : channel1 "channel 1 test" [ stateTopic="topic/#", transformationPattern="JSONPATH:$.data1" ]
Type string : channel2 "channel 2 test" [ stateTopic="topic/1", transformationPattern="JSONPATH:$.data2" ]
Type string : channel3 "channel 3 test" [ stateTopic="topic/1", transformationPattern="JSONPATH:$.data3" ]
Type string : channel4 "channel 4 test" [ stateTopic="topic/2", transformationPattern="JSONPATH:$.data2" ]
Type string : channel5 "channel 5 test" [ stateTopic="topic/2", transformationPattern="JSONPATH:$.data3" ]
}
*Items
String channel1Test "item for channel 1 test" <string> { channel = "mqtt:topic:mqttTest:channel1"}
String channel2Test "item for channel 2 test" <string> { channel = "mqtt:topic:mqttTest:channel2"}
String channel3Test "item for channel 3 test" <string> { channel = "mqtt:topic:mqttTest:channel3"}
String channel4Test "item for channel 4 test" <string> { channel = "mqtt:topic:mqttTest:channel4"}
String channel5Test "item for channel 5 test" <string> { channel = "mqtt:topic:mqttTest:channel5"}
on KARAF Console
log:set INFO smarthome.event.ItemStateEvent
log:tail smarthome.event.ItemStateEvent
publishing the below JSON using MQTT.fx and monitoring on KARAF console
{"data1":"chan1test", "data2":"chan2test", "data3":"chan3test"}
- publishing on topic/1
16:52:54.823 [INFO ] [smarthome.event.ItemStateEvent ] - channel3Test updated to cahn3test
16:52:54.837 [INFO ] [smarthome.event.ItemStateEvent ] - channel2Test updated to cahn2test
16:52:54.846 [INFO ] [smarthome.event.ItemStateEvent ] - channel3Test updated to cahn3test
16:52:54.853 [INFO ] [smarthome.event.ItemStateEvent ] - channel2Test updated to cahn2test
16:52:54.861 [INFO ] [smarthome.event.ItemStateEvent ] - channel1Test updated to chan1test
16:52:54.868 [INFO ] [smarthome.event.ItemStateEvent ] - channel1Test updated to chan1test
- publishing same JSON on topic/2
16:54:08.586 [INFO ] [smarthome.event.ItemStateEvent ] - channel5Test updated to cahn3test
16:54:08.601 [INFO ] [smarthome.event.ItemStateEvent ] - channel5Test updated to cahn3test
16:54:08.610 [INFO ] [smarthome.event.ItemStateEvent ] - channel4Test updated to cahn2test
16:54:08.620 [INFO ] [smarthome.event.ItemStateEvent ] - channel4Test updated to cahn2test
16:54:08.629 [INFO ] [smarthome.event.ItemStateEvent ] - channel1Test updated to chan1test
16:54:08.638 [INFO ] [smarthome.event.ItemStateEvent ] - channel1Test updated to chan1test
- publishing same JSON on topic/3
16:55:19.696 [INFO ] [smarthome.event.ItemStateEvent ] - channel1Test updated to chan1test
As you can see, MQTT is working expected and items are receiving correct values, except that it updates each items twice (except when publishing to a topic with no other channels defined).
If I change the topic for channel1 from topic/# to topic/1 then all the item update happens only once.
The real world usage (and how I noticed it) was by testing Rhasspy voice assistant with openHAB where Rhasspy publishes the information on hermes/intent/INTENTNAME
, so I would need to monitor hermes/intent/#
with item IntentName to catch all the intents and a rule executing different commands based on the state of IntentName.
I would be happy to share the full real use case if needed.