[SOLVED] Infinite loop for a MQTT message OPENHAB2

i’m changing now from Openhab1 to Openhabe2, i have a lot of items which use MQTT message to control my home, i’ve tried to write them in the items file in the items folder, but it seem that something went wrong.
Here is an example i write it to to test if it works: items.items

Group test

Switch test "test sensor" (test) {mqtt=">[ideaal:test:state:*:Switch ${itemName}; zustand ${state}],>[ideaal:test:command:*:Switch ${itemName}; zustand ${command}]"}
Switch Switch1 "test Switch1" (test) {mqtt=">[ideaal:myhome/bedroom/switch1:command:ON:1:test1],>[ideaal:myhome/bedroom/switch1:command:OFF:0:test2],>[ideaal:myhome/bedroom/switch1:state:ON:1:test3],>[ideaal:myhome/bedroom/switch1:state:OFF:0:test4]"}
Switch Switch2 "test Switch2" (test) {mqtt=">[ideaal:myhome/bedroom/switch2:command:ON:1:test4],>[ideaal:myhome/bedroom/switch2:command:OFF:0:test5],>[ideaal:myhome/bedroom/switch2:state:ON:1:test6],>[ideaal:myhome/bedroom/switch2:state:OFF:0:test7]"}

here is my sitemap:

sitemap Test label="Test"{
  Frame label="test"{
    Switch item=test
    Switch item=Switch1
    Switch item=Switch2

when i subscribe the topic test : mosquitto_sub -h localhost -t test
i got an infinit loop from Mqtt messages,
but when i subscribe the other topics there is no message come: mosquitto_sub -h localhost -t myhome/#

so can you help me to solve the problem !

Why are you sending both command and state changes out to the switches? Did you mean to make the state changes inbound? Also double check the structure of your mqtt configurations, you seem to have an extra option in them. For outbound should be

{ mqtt="<direction>[<broker>:<topic>:<type>:<trigger>:<transformation>]" }

well because some sensors works as state and sometimes i use the rules by sending commands to do something, therefore i need to be sure that both of them works good,
for i deleted it from the second and third sensor to make them work,
but i still have the problem by the first sensor, when i comment the first sensor and start to subscribe, then i uncomment the sensor it will work perfectly,
but if i start my system and then try the sensor, infiniti loop will start to write in my subscriber.

Do you by chance have the mqtt action binding installed? It causes issues in the newer releases of OH?

I’m also not familiar with using the ${itemName} variables and if that might be causing your issues.

well i have installed the Mqtt action binding and then deinstall it, ${itemName} return the name of the sensor
${state} return the state of the sensor if it ON or OFF,
but i don’t think this is the problem, because i used ${itemName} inside the MQTT message of the second and third sensor, und they really doing well.

My last guess is in you rmqtt statement structure but you are beyond me on that one. I would try simplifying and rebuilding your item statement step by step to see if you can find what’s breaking it now that I understand you are changing the state to “Switch xxxx; zustand yyy” Maybe start with just:

Switch test "test sensor" (test) {mqtt=">[ideaal:test:state:*:Switch]"}

And then build from there

I’ve tried that also, but the same result , i’don’t know why!!

well it works when i changed it from state to command :smiley:

1 Like