MQTT 2 Binding receives Messages but doesn't send updates

Hi There,

I’m fighting with mqtt2 binding. It receives messages, but doesn’t sent new messages to mqtt.

For simplification I’ve created a simple setup:

Things

Bridge mqtt:broker:mosquitto [
host="192.168.178.100",
secure=false,
username="openhab",
password="secret",
clientID="openhabslaveeg"
] {
    Thing topic mqtttest {
      Channels:
        Type number : test "Test" [stateTopic="openhab/slave/test/state"]
    }
}

Items

Number  MQTTTest  "Test"  (gCounters)  { channel="mqtt:topic:mosquitto:mqtttest:test" } 

The configuration is identical on both openhab instances except the clientID.

When sending a message through mosquitto_pub

mosquitto_pub -u openhab -P secret -h 192.168.178.100 -t 'openhab/slave/test/state' -m '100'

It updates the state on both instances:

2019-08-13 20:40:35.694 [vent.ItemStateChangedEvent] - MQTTTest changed from 100 to 42

2019-08-13 20:40:35.694 [vent.ItemStateChangedEvent] - MQTTTest changed from 100 to 42

But when changing one item through karaf console, it only changes the local instance, not the remote instance. I’ve also subscribed ‘#’ through mosquitto_sub but nothing arrives.

I’m experiencing the same on 2.5m2. Have not had any time to look into it, more than seeing that openhab is silent.

Your channel has a stateTopic. This describes how the binding should use incoming MQTT messages to make OH Item state updates.

That’s it. You have no outbound messaging configured, so none happens. It is doing exactly what you asked for.

You would usually use commandTopic to describe how internal OH commands are to be sent ont to MQTT.

Are you trying to set up an event bus link? This needs to be done differently to an ordinary Item, please be clear about what you are doing.

Your Thing only defines a stateTopic.

My mqtt ver2 started working correctly once I cleaned cache and tmp and restarted.

Regards, S

I simply wanna sent every state of my item from one OH Instance to another (one way).
Changing from state to command (which nomenclature is misleading to me) solves it.

But as @Seaside said it only works after restarting OH

Reading this, I guess you are on openHAB 2.4. It is a known issue of this MQTT Version, after a change of the related things file a restart is needed. This is solved in the current milestone version!

commandTopic doesn’t do that either. It sends each command out on MQTT. It does not send states.
For example, if you command a Dimmer ON, it will send ON to MQTT.
The Dimmer will probably change to state 100%.
That state change will not be sent.

You need to decide what you actually want.

I have some measurements like the ones from my smartmeter that I wan’t to sent from one OH instance to another. It works for me with an old OH2 instance together with MQTT1 binding. Now I wan’t to do the same thing with MQTT2 binding but it doesn’t seem to work.

This is an item configuration:

Number:Energy  Energy_Consumption_External_Supply      "Fremdbezug [%.0f kWh]"   <powerplant>  (gCounters)  { channel="smartmeter:meter:evs:1-0_1-8-0", channel="mqtt:topic:mosquitto:energy:smart_meter_external_supply" }

But new measurements where not sent to mqtt. Do I really need to go back to mqtt1 binding to achieve this?

Thanks allot
Pascal

No, you just need to be clear about what “this” is,

I would guess that what you want to do is copy state updates of your energy meter Item to MQTT ??

Okay, so first thing you need is to define an MQTT channel that will put things out over MQTT.
You’ve done that part, using commandTopic

Now, that works in the normal openHAB way and only sends commands out over MQTT., never state changes.

We need a tool to convert state changes into commands, so that we can use that channel. That tool is the follow profile. We can link a channel to an Item and the follow profile will listen for Item state changes, then send them to the channel as though they were commands.

Number ....  { channel="usual:channel:for:updating:item", channel="mqtt:topic:mosquitto:energy:smart_meter_external_supply" [profile="follow"] }

I don’t know quite what happens with units involved though.

I agree with rossko57, the follow profile will be the closest to what you are used to. But there is another way if you have a lot of these Items. See Marketplace MQTT Event Bus. However, I’m not certain it works with 2.4, you may need to move to 2.5 M1 or M2.

Many thanks for your help!
I needed to disable the units - otherwise it throws an exeption.