[SOLVED] MQTT (v2) format output

Dear all,

I want to extend my bunch of Shellys via a Shelly Dimmer. I know Openhab 2.5 supports Shellies natively but - of the topic - MQTT is dramatically faster on my raspberry 4.

Regarding the topic itself:
I try to format the mqtt properly but it is not working. On top I do not see my command in MQTT.fx (even the working ones) and also openhab log just shows me the changed value of the item - so it is hard (for me) to debug.

The thing looks like this:

Thing mqtt:topic:Shelly_Kinderzimmer "Shelly Kinderzimmer" (mqtt:broker:Mosquitto) @ "MQTT"  {

  Channels:

    Type switch : Power "Power" [ stateTopic="shellies/shellydimmer-xxxxxx/light/0", on="on", off="off", commandTopic="shellies/shellydimmer-xxxxxx/light/0/command", on="on", off="off" ]


    Type dimmer : Dimmer2 "Dimmer2"   [ stateTopic="shellies/shellydimmer-xxxxxx/light/0/status",transformationPattern="JSONPATH:$.brightness",commandTopic="shellies/shellydimmer-xxxxxx/light/0/set",transformationPatternOut="{turn: on, brightness: %s}"]

    Type number : Number2 "Number2"   [ stateTopic="shellies/shellydimmer-xxxxxx/light/0/status",transformationPattern="JSONPATH:$.brightness",commandTopic="shellies/shellydimmer-xxxxxx/light/0/set",transformationPatternOut="{\"turn\": on, \"brightness\": %s }"]
}

Items look as follows

Switch   Shelly_Kinderzimmer_Dimmer2  "Kinderzimmer Dimmer" {channel="mqtt:topic:Shelly_Kinderzimmer:Dimmer2", autoupdate="false"}
Number   Shelly_Kinderzimmer_Number2  "Kinderzimmer Number" {channel="mqtt:topic:Shelly_Kinderzimmer:Number2", autoupdate="false"}

When I change the name from “Dimmer2” to “Dimmer” I get the following error. Does anybody know the reason?

019-12-28 16:43:44.482 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'shelly.things' has errors, therefore ignoring it: [32,19]: missing RULE_ID at 'Dimmer'

[32,26]: mismatched input '"Dimmer2"' expecting ':'

[32,40]: missing '}' at 'stateTopic'

[32,97]: no viable alternative at input 'transformationPattern'

[32,143]: no viable alternative at input 'commandTopic'

[32,199]: no viable alternative at input 'transformationPatternOut'

[33,27]: mismatched input '"Number2"' expecting ':'

[34,1]: missing EOF at '}'

For me it feels I am doing some basics wrong.
The Shelly Dimmer MQTT docu is here: https://shelly-api-docs.shelly.cloud/#shelly-dimmer-sl-mqtt

M questions:

  • Any idea why I can not call it “Dimmer” but “Dimmer2”?
  • Any idea how to get it correctly working?
  • Any idea how to debug MQTT properly (incl. outgoing messages)?

System:
Openhab 2.5 stable on raspberry 4.

Thanks and best
Matthias

What is it, the items or the thing?
Why don’t you use the PaperUI to set-up your things?

Set the binding on DEBUG

Because “Dimmer” is a reserved word.

With a quick glance, you’ve linked the Dimmer2 Channel to a Switch, not a Dimmer Item.

Also, I don’t use nor recommend .things files (exactly because of postings like this) so I can’t be sure but it looks like you are using an outgoing format config string in an outgoing transformation. They are two separate fields which is obvious and all but impossible to get wrong when using the UI.

Dear all,

thank yo for the answers.
After some vacations I solved the issue. The hint “formatBeforePublish” was the solution and quite obvious ;-).

My working solution for others to use the Shelly Dimmer via MQTT on Openhab 2.5.

thing file:

Thing mqtt:topic:Shelly_Kinderzimmer "Shelly Kinderzimmer" (mqtt:broker:Mosquitto) @ "MQTT"  {
  Channels:
    Type switch : Power "Power" [ stateTopic="shellies/shellydimmer-xxxxxx/light/0", on="on", off="off", commandTopic="shellies/shellydimmer-xxxxxx/light/0/command", on="on", off="off" ]
    Type number : Helligkeit "Helligkeit"   [ stateTopic="shellies/shellydimmer-xxxxxx/light/0/status",transformationPattern="JSONPATH:$.brightness",commandTopic="shellies/shellydimmer-xxxxxx/light/0/set",formatBeforePublish="{\"ison\":true,\"mode\":\"white\",\"brightness\":%s}"]
}

items file:

Switch   Shelly_Kinderzimmer  "Kinderzimmer Deckenlampe" ["Lighting"] {channel="mqtt:topic:Shelly_Kinderzimmer:Power", autoupdate="false"}
Number   Shelly_Kinderzimmer_Helligkeit  "Kinderzimmer Number" {channel="mqtt:topic:Shelly_Kinderzimmer:Helligkeit", autoupdate="false"}

Nevertheless (and off topic) I am still wondering why MQTT is so dramatically faster than the native shelly integration supported since Openhab 2.5. MQTT is not noticeable (hence below 100 ms) while the native binding can take several (!) seconds on the same system (raspberry 4, 4 GB RAM version), tried with shelly 1 and 2.5 as well as dimmer.

Best
Matthias