MQTT 2.x binding, can send, can't receive

open habian 2.4 release, mqtt binding 2.x

I thought I’d successfully moved from mqtt binding 1.x to 2.x…but, I was wrong.

At this point I can publish mqtt, but I don’t receive.

.thing file:

Bridge mqtt:broker:redpi_mqtt_broker [ host="192.168.53.105", secure="AUTO", username="***", password="****" ]
{
    Thing topic drivesensor "Driveway Motion Detector" {
    Channels:
        Type number : DrvMotNum     "Drive Motion Num Channel"   [ stateTopic="driveway/motion"]
        Type string : DrvMotStr     "Drive Motion Str Channel"   [ stateTopic="driveway/stringtest"]
    }
    Thing topic thermostat1 "Thermostat 1" {
    Channels:
        Type string : temperature1  "Temperature One"   [ stateTopic="tstat1/temperature"]
        Type string : setpoint  "Set point"   [ commandTopic="tstat1/setpoint"]
        Type string : humidity1  "Humidity One"   [ stateTopic="tstat1/humidity"]
        Type string : request "tstat request"   [ stateTopic="tstat1/request"]
    }
}

.items file:

Number mqtt_drive_motion "Motion sense in driveway! [%.1f]"  {channel="mqtt:topic:redpi_mqtt_broker:drivesensor:DrvMotNum"}
String mqtt_test "Mqtt test [%s]"  {channel="mqtt:topic:redpi_mqtt_broker:drivesensor:DrvMotStr"}
String mqtt_tstat1_temp     "[%s]"  {channel="mqtt:topic:redpi_mqtt_broker:thermostat1:temperature1"}
String mqtt_tstat1_humidity "[%s]"  {channel="mqtt:topic:redpi_mqtt_broker:thermostat1:humidity1"}
String mqtt_tstat1_setpoint "[%s]"  {channel="mqtt:topic:redpi_mqtt_broker:thermostat1:setpoint"}
String mqtt_tstat1_request  "[%s]"  {channel="mqtt:topic:redpi_mqtt_broker:thermostat1:request"}

This rule triggers on the White_Puck and mqtt__tstat1_setpoint (these are widgets in habpanel for example). But, when I publish “tstat1/request” with a topic of setpoint, it doesn’t

rule "update tstat1"
    when
        Item White_Puck_10 changed from "NULL" to "ON" or
        Item White_Puck_10 changed from "OFF" to "ON" or
        Item mqtt_tstat1_setpoint changed or
        Item mqtt_tstat1_request changed to "setpoint"
        //Time cron "0 * * ? * * *"
    then
        val actions = getActions("mqtt","mqtt:broker:redpi_mqtt_broker")
        logInfo("tstat1", mqtt_tstat1_setpoint.state.toString)
        actions.publishMQTT("tstat1/setpoint", mqtt_tstat1_setpoint.state.toString)
end

Same with the inbound drive sensor publish for DrvMotStr…

Please provide a cutout of events.log and openhab.log when publishing the topic.

That would great, but when the mqtt clients publish, nothing shows in the oh logs. :slightly_frowning_face:
There is no indication it is receiving the topics.

But, when I trigger oh to publish tstat1/setpoint topic the client sees it.

Why are you using the action, You have a channel set-up…

rule "update tstat1"
    when
        Item White_Puck_10 changed from "NULL" to "ON" or
        Item White_Puck_10 changed from "OFF" to "ON" or
        Item mqtt_tstat1_setpoint changed or
        Item mqtt_tstat1_request changed to "setpoint"
        //Time cron "0 * * ? * * *"
    then
        logInfo("tstat1", mqtt_tstat1_setpoint.state.toString)
        mqtt_tstat1_setpoint.sendCommand(mqtt_tstat1_setpoint.state.toString)
end

Basically I haven’t had the “aha!” moment yet. :thinking:

So, correct me if I’m wrong:
This channel definition defines a channel called setpoint that sends the topic “tstat1/setpoint”

Type string : setpoint  "Set point"   [ commandTopic="tstat1/setpoint"]

This item definition defines an item mqtt_tstat1_setpoint linked to the channel defined above:

String mqtt_tstat1_setpoint "[%s]"  {channel="mqtt:topic:redpi_mqtt_broker:thermostat1:setpoint"}

And, this line in your code triggers the channel to publish with the topic “tstat1/setpoint” with mesage <current string in item mqtt_tstat1_setpoint.

mqtt_tstat1_setpoint.sendCommand(mqtt_tstat1_setpoint.state.toString)

Side note, it appears, that after restarting OH, things are working. (And, it appears, every time I save changes to the .things file containing the bridge, I need to restart OH. Is this normal? Or am I not seeing what I think I’m seeing? :roll_eyes: very possible )

Correct
Correct
Correct
Correct
Side note: correct, this is a bug. Corrected in the snapshots.

Ok. So, what’s the use case for the two ways? (Action vs sendCommand)

The action is useful when the item name is generated in the rule.
If the item is known then use the command

Hmm…am now running snapshot 2.5.0~S1507-1 (Build #1507) , still have to restart OH after changing the Bridge in .things file.

By the way, you might want to hide you username and password from your first post

And that’s one of the advantages of using the paperUI to define things and channels

Thanks, I usually catch stuff like that…, my firewall is pretty good…but, no sense pushing my luck. :face_with_raised_eyebrow:

Well, in addition to feeling like files let me understand what I’ve got better (and that could just be me… :sunglasses: ), when I started using OH, I got tired of “oh, that works better in BasicUI”, and “this works better in PaperUI”, and “that doesn’t work in that UI at all”. :exploding_head:

And, are you saying it was corrected in snapshot for in the UI, but not for file updates? :thinking:

No I am saying it is safer and simpler to use the paperUI to create things and channels

And how would @drmacro have shared his configuration with us, asking for advice? Screenshots? :grinning:

1 Like

For the moment, yes. I have seen that a lot actually.

I have the same issues as @drmacro

Channels do not seem to work, I am with the official binding.
I rely on config files, because they make it much easier to rebuild my environment in case of failure. I can just copy/paste the .items .thing file and I am done.

But also for me I get inconsistent error messages and the channel mapping does not seem to work. Maybe it is because I am using 2.x and 1.x of MQTT at the same time.
I think I’ll just give up for now and “never change a running system”

By snapshot - do you meen the.jar of the MQTT binding or the latest openhab snapshot release?

That’s a separate bug then. Do you have any error messages in the log that could help fix that issue?

The snapshot that is available via the repositories. No jars. It’s just that snapshots are bit broken because of the merge of Eclipse Smarthome with openHAB that is currently going on.

When I save the .thing file there is nothing out of the ordinary. It reports the update, no errors. But, then no subscribed publish from elsewhere triggers any of my rules.

If I stop/start OH (this 2.5 snapshot on a Pi) then all mqtt in and out work fine. Another note is, the mqtt broker is not running in OH or on the OH Pi. The broker is a mosquito broker on separate PI.

(probably not related, but I did see a block of eclipse related errors the first time I started OH after update to the snapshot.)

Could you please open a bug report? I will investigate that tomorrow with your configuration posted above.

Done: #4731

Yes, screen shots. Nothing wrong with that