[SOLVED] MQTT 2.4 - Item retains it state


I am using MQTT 2.4, and I have strange behaviour and probably I am missing something.

I have an item which is connected to an MQTT topic. All works fine. When the topic change, the item is updated.
The strange is that when I send the item a command (via Karaf console), the item is changed but then goes back to the value it was before. The only thing that can explain it, is that the MQTT binding somehow “retain” the item value.
BTW, when I remove the link to the MQTT channel (item is not connected to any channel), the item works as expected, that means, when I send the command from Karaf, it keep the value (this was just to check that the item is not changed from other source).

Here is log example when it happens (I don’t understand why Motion_Entrance change back from OFF to ON):

2019-01-20 10:50:17.357 [ome.event.ItemCommandEvent] - Item 'Motion_Entrance' received command OFF
2019-01-20 10:50:17.371 [nt.ItemStatePredictedEvent] - Motion_Entrance predicted to become OFF
2019-01-20 10:50:17.400 [vent.ItemStateChangedEvent] - Motion_Entrance changed from ON to OFF
2019-01-20 10:50:17.404 [GroupItemStateChangedEvent] - Motion changed from ON to OFF through Motion_Entrance
2019-01-20 10:50:17.408 [vent.ItemStateChangedEvent] - Motion_Entrance changed from OFF to ON
2019-01-20 10:50:17.412 [GroupItemStateChangedEvent] - Motion changed from OFF to ON through Motion_Entrance

m I missing something here?


Can you post the channel config, please?

Type switch : Motion          [ stateTopic="tele/device/PICB47EBED/MOTION", transformationPattern="JSONPATH:$.motion" ]

Switch Motion_Entrance "Motion [MAP(motion.map):%s]" <motion_sensor> (Motion) { channel="mqtt:topic:mosquitto:PICB47EBED:Motion" }

There is no commandTopic…

Why do I need command topic? Is it a must?

The channel get state update from the MQTT, I thought that in this case I don’t need command topic …

Why would you send a command manually to a motion sensor ?
This does not make sense, even that the device will not accept such a command.


I sent it only for debug purpose and then I saw the issue.

Yes, but the MQTT topic did not change, therefore it had to flip back. If you want to debug, you should publish to the topic, not sending comand to the item.


If I understand you correctly, the binding makes sure that the item value will match the last topic state. Is this the case? (this is what I am seeing but I must say that it is strange behaviour)

Not sure why you think this is strange? Sending OPEN to most doors, they’ll stay shut in reality and I would expect their OH status to stay shut as well.

The ‘predicted’ part in your log comes about from autoupdate guessing what might happen after a command. Autoupdate is not smart enough to understand that there won’t be an affect here.


The strange thing is that using Karaf, I’ve sent a command to the item, not to the binding. That means that the mqtt binding monitors the state of the item all the time and makes sure that the state of the item will match the state the binding have.

“Someone” has decided to return the state of the item to ON (in the above snapshot). The end device didn’t send it, so the only one that can do it is the binding and this is strange.

Okay, so you would prefer the MQTT binding to only update your Item when there is an external event. I think what you want is a stateless channel, inbound, i.e. an event channel. I don’t think MQTT supports that? though it easy to simulate with a proxy Item.


Actually, I just want to know the behaviour. If the binding stores the last state he got from the device and it always sync this state ti the item, that is fine, for me it was a surprise. I just want a confirmation that this is how it works so I know it is not an issue with my system.

It might be the binding’s response to a command sent to what you have defined as a read-only channel. Seems reasonable.

You can verify that by issuing a postUpdate to the Item instead.

I have used smarthome:update and now it seems to work as expected. Not sure that I fully understand the logic here …

Thx for the help!

I don’t even know what that means, but so far as I see the generalized openHAB logic:

It’s down to a debate about whether sending a command to a read-only channel should cause a binding to do nothing at all, or to instead give the reasonable response of affirming that the ‘target’ device state will remain unchanged.

This is the console. You can send from there command or update to an item.

If I understand correctly your response, you also think that the item shouldn’t be change, right?

Maaaaybe. Bear in mind it would be legitimate to send a REFRESH command to a read-only channel, for example, and to get an update in response. “Do nothing” definitely not a blanket expectation.
The binding is the real arbiter of what is a sensible response or not, this might depend on the underlying technology.
We’re second-guessing what the binding developer had in mind now.

Is your problem that it changed at all? See autoupdate.

The Mqtt binding keeps its channel in sync with their state topics. Linked items are therefore set to the bindings cached state and will reset to that state if the framework sends a “command”.

The binding will not be informed if the user overwrites an item state via “update”.


Thx, that explain what I see.