MQTT thing-Definition with inverse ON/OFF and seperated commandTopic

Hi all,

I try to change my robonect to MQTT-Binding.

I allready defined a thing with a lot of channels working in readonly fine.

But I got problems with commandTopic. Here the relevant thing (reduced to relevant channels):


Thing mqtt:topic:mosquitto:R2D2 "_R2D2" (mqtt:broker:mosquitto) {
    Channels:
         Type switch : StartStop "_R2D2 StartStop"      [ stateTopic="R2D2/mower/stopped",
            transformationPattern="REGEX:(*)",
            on="false",
            off="true",
            commandTopic="control", on="start", off="stop"
        ]
}

Two problems I have got:
a) the stateTopic mower/stopped has value true (if stopped) and false (when mower running). I tried to inverse this, so switch should be ON when state publishes false and OFF when state publishes true
b) In documentation of robonect I found, the control receives start, mower will start, with stop will stop. (https://forum.robonect.de/viewtopic.php?t=3930

But with the defined channel, I cannot see any MQTT control (checked with MQTTAnalyzer App)

Anyone more familiar with mqtt has got an idea? Or already got Robonect working mqtt only?

Have you tried to manually publish the relevant mqtt message e.g. via the mqtt analyzer app or any other 3rd party tool, to verify if the issue is with openhab or with the device itself?

Not yet. Do you have an example syntax for mosquito-client?

There is only one on and off parameter for a Channel which does the translation for both the stateTopic and the commandTopic. Given that each topic uses different values for ON/OFF you’ll have to use a rule or separate Items for this.

You might be able to set up two Channels, one for the state and another one for the command and link both to the same Item.

Note, for the commandTopic wouldn’t you really want R2D2/mower/control?

Documentation says TOPIC/control, so I believe this should be right.

I‘ll search for an example for an item with two channels, one for state and one for command and will try. Thank you

I got it. Thanks for your hint with two channels! That worked.

Could inverted stop true in a channel and using another for command.

Correct mqtt was R2D2/control

1 Like

Originial problem was solved, but maybe one additional question:

Is it possible to give a selection-list directly with the channel? So that a string item directly shows the options like manually done in sitemaps with selection and mappings?

Only if you are the binding author. That’s not going to happen with deliberately generic MQTT binding channel.

Maybe you meant about setting options on your Item? Set the Items metadaya

I thought about the channel definition in things-file, not generally in the binding :wink: I know my limit and very glad and thankful for all the work you all spend in developing openHAB. :+1:

In some bindings I just need to define item as string with a binding channel behind and got a choice like done in Sitemaps with mapping.

Thought there could be an option in channel definition in things file too.

Thanks for your patience with me

Yes, bindings like zwave or weather can “know” exactly what a channel represents, and suggest options for Item. It’s like force-feeding metadata to the linked Item.
Generic MQTT could reprsent anything.

It’s not user-adjustable at the channel point, because you should be doing your “presentation” settings in the Item metadata.

Could you tell me the reason why you changed to MQTT?
I struggled a little at the beginning with my robonect cause the channels are a bit weird but with two rules (still DSL) handling the status and start/stop-channels I’m now quite happy with the functionality.

rule "Bewaesserung Command" 
when
  Member of BewaesserungG received command
then
  if ( receivedCommand == ON )
    sendCommand(triggeringItemName + "_start", "ON")
  else if ( receivedCommand == OFF )
    sendCommand(triggeringItemName + "_stop", "ON")
end

rule "Bewaesserung Change" 
when
  Member of BewaesserungG changed
then
  if ( newState == "CLOSED" )
    postUpdate(triggeringItemName.replace("_status",""), "OFF")
end

Hi Larsen,

until yet I didn’t changed, but testing with MQTT.

Well, because the robonect binding sometimes not really work well in my case (with rain, the wlan connection is at the limit), I have got a mix of http things via API for commands and some status informations, robonect-Binding, a self written API the mower sends new status to and so on.

Especially status changes via robonect sometimes needs some minutes before openHAB shows via binding.

To simplify I now test with mqtt, furthermore mqtt gives some more interesting informations, like substatus, blades etc. my hope is to use mqtt and http for commands so much less code and complexity

yes, you might get some additional status information via mqtt (but that doesn’t solve the wifi-problem. You considered a repeater…?). I have good wifi in my garden, so status change is really accurate.
I would be interested if you are able to grab something useful via mqtt, so maybe you could report in this thread?

Well, interesting is, that robonect binding failed sometimes, but mower is always able to send via Wi-Fi to server. So pull mower doesn t work well, put Push from mower always fine.