Outgoing MQTT from item in OH3 via files, not UI

Hello all and merry christmas.
I’m at my wits end and have been searching/trying different stuff to try to get mqtt working in OH3.
Background:
I have OH2.5 working via text files and is planning to migrate to OH3 using text files as well.
But trying to migrate so It uses correct OH3 semantics etc and not just copy the whole thing over :slight_smile:

But I struggle with MQTT.
In OH2.5 a normal number item would look like this:

Number      Melcloud_1_roomTemperature     { channel="melcloud:acdevice:XXXX:XXXX:roomTemperature", mqtt=">[broker1:home/openhab/temperature/melcloud1roomtemperature/state:state:*:${state}]" }

Meaning if I change the switch, it will also send this via MQTT outgoing.

I installed a new and clean OH3.2 openhabian to migrate. Installed the MQTT binding and set it via a .things file according to the new format (and this helpful guide openhab-addons/xtend_examples.md at main · openhab/openhab-addons · GitHub):

Bridge mqtt:broker:myAuthentificatedBroker "mqttbroker" [ host="192.168.x.xx", secure=false, username="user", password="password", clientID="openhab3"]
{
    Thing topic melcloudMQTT "melcloudMQTT"
    {
        Channels:
            Type number : Melcloud_1_powerMQTT "Melcloud_1_powerMQTT" [ stateTopic = "cloudway/melcloud/temperature/state" ]
    }
}

It connects and says online.

The items file use this:

Number      Melcloud_1_roomTemperature     { channel="melcloud:acdevice:xxxx:xxxxx:roomTemperature", channel="mqtt:topic:myAuthentificatedBroker:melcloudMQTT:Melcloud_1_roomTemperature" }

But no values are ever sent out (or in for that matter)
I read somewhere that I could just use normal .items that I used in OH2.5 in OH3.2, but that does not seem to work either.

The reason why I want to do it this way is so I can have power over the mqtt path.
Maybe the only solution is to make rules for every item and path?

Could someone help me troubleshoot (well, maybe not right now since its christmas eve haha) ?
Cheers!

Your Thing melcloudMQTT has a Channel Melcloud_1_powerMQTT which has a single property stateTopic. This means that this Channel, and any Items linked to this Channel, will only receive MQTT messages into openHAB.

In order to send/publish MQTT messages you also need a commandTopic property in your Channel. Any linked Items that you command will then cause an outgoing message to your MQTT broker.

In terms of your Item: you have this linked to a KNX Channel, and your MQTT channel. NOTE: if the Item state is changed via your KNX Channel, this will not be forwarded on to your MQTT Channel because state changes from bindings come in as updates, not commands.

I would have a search around for the follow profile feature in these forums (on phone so tricky to link at the moment) - that may do what you want.

Check the fundamentals first: is openHAB correctly connected to your MQTT broker? Is your MQTT broker running? You could use MQTT Explorer to check the activity at your MQTT broker.

Well, that’s the answer right there. Then I guess I’ll have to use rules.
Cheers and thanks!

To repeat: you don’t have to use rules. You can use the follow profile. But if you’re comfortable with rules then go for it.

And don’t forget to change your Thing Channel to include a commandTopic.

I looked into the “follow” profile and it solved my issue perfectly!
Big thanks to you @hafniumzinc for pointing me in the right direction.

For guidance if someone finds this post:
things for broker:

Bridge mqtt:broker:broker1 "mqttbroker1" [ host="192.168.xx.xx", secure=false, username="user", password="password"]
{
    Thing topic melcloudMQTT "melcloudMQTT"
    {
        Channels:
            Type number : room "Melcloud_1_roomTemperature" [ stateTopic = "cloudway/melcloud/temperature/state", commandTopic = "cloudway/melcloud/temperature/set" ]
            Type switch : power "Melcloud_1_power" [ stateTopic = "cloudway/melcloud/power/state", commandTopic = "cloudway/melcloud/power/set" ]
    }
}

Items:

Number      Melcloud_1_roomTemperature     { channel="melcloud:acdevice:xxxxx:xxxxx:roomTemperature", channel="mqtt:topic:broker1:melcloudMQTT:room" [profile = "follow"] }
Switch      Melcloud_1_power               { channel="melcloud:acdevice:xxxxx:xxxxx:power", channel="mqtt:topic:broker1:melcloudMQTT:power" [profile = "follow"] }

Now, whenever the channel gets an update via a binding, it sends out the info on respective MQTT path I have selected.

Cheers!

Thank you! This solved my problems with my RGB LEDs. I worked all day to find a solution.