OH3 - mqtt common channel for state and command

since upgrading to OH3 from 2, I’ve encountered following problem;

Thing topic myTopic "My Topic" {
            Type number : myNum "mynum name" [stateTopic="smth/smth/one", commandTopic="smth/smth/one"]

and Item

Number myNum "mynum name" (Group) {channel="mqtt:topic:broker:myTopic:myNum"}

This combination unfortunately does not work anymore, I have to manually create two channels and connect them both to my only item. I want to read and command the same topic through one item.

I wonder why this does not work in OH3 anymore? Why do I have to create two channels? I got it into a working state, but it’s rather unfortunate and too much repetitive code to create two channels when one is enough, especially when I need to handle like 100 or more items like this.

Maybe there is just a change in the syntax, but I didn’t find any info about that.

Thanks for any reply.

Why not? What happens? Can you show a log extract?

(Note that it is considered unusual to use the same topic for state and command messages in MQTT)

There is nothing in the log. No error, it just does not work. I noticed it takes the first topic, either state or command, that works just fine, but the other one gets ignored. So when i have

stateTopic=“smth/smth/one”, commandTopic=“smth/smth/one”

I can succesfully read from the topic, but cannot change the value on broker via this item.

This is bonkers. You do understand it risks creating a loop?

How exactly are you attempting to do that? How are looking at what the broker receives? Is it just openHAB using this topic for now, no other device yet?


You have given an XY problem that is a little silly for home automation.

What is happening is you are sending a command to the topic then openHAB is reading that state and sending it into a loop.

The way to stop this from happening is having 2 topics.

Lets say the number is the set temperature of your HVAC device.

You have a stateTopic and a commandTopic.

Lets say topics are bedroom/aircon/state and bedroom/aircon/command

You have 3 devices connected to MQTT that want to change the temp they would do this by sending the number to the bedroom/aircon/command topic then the HVAC would receive the command and only the HVAC will publish to the bedroom/aircon/state topic.