Shelly Dimmer via MQTT

Does anyone already control Shelly DImmer via Mqtt ?? I turn on and nothing else.

Type switch : shellydimmerlampaTV “shellydimmerlampaTV” [stateTopic=“shellies/shellydimmer-lampaTV/light/0”, on=“on”, off=“off”, commandTopic=“shellies/shellydimmer-lampaTV/light/0/command”, on=“on”, off=“off”]

Again a wrong text configuration for an MQTT thing channel.
Why don’t you use the PaperUI…

The on and off are duplicated, any reason for that?
Remove them, and then restart if you are on 2.4

On paperUI config you wouldn’t have to restart… But that has been fixed on 2.5 anyway

If it still doesn’t work then your topics are incorrect or check your MQTT traffic

But it works. On / Off works fine. I have problem with dimmer and JSONPath.

There is not such thing as a shelly dimmer (Yet…) They are on pre-order on the website

And I can’t find any information on their website about the MQTT topics to use for the dimming
But you could try a percentage channel or a number channel and then link it to a Dimmer item

shellies/shellydimmer-<deviceid>/light/0/set for brightness, accepts a json payload:
“turn”: “on”,
“brightness”: 100

Use a javascript transformation for the out going payload
You can’t do that with openHAB 2.4, you will need 2.5:

I do this with some zigbee2mqtt bulbs:

The tranformation:

(function(brightness) {
    if (brightness > 0) {
        var shellyobj = { "turn":"on", "brightness":brightness};
    } else {
        var shellyobj = { "turn":"off", "brightness":0 };
    var data = JSON.stringify(shellyobj);
    return data;
1 Like

I try this:
Type dimmer : shellydimmerlampaTVDimmer “shellydimmerlampaTVDimmer [%d %%]” [stateTopic=“shellies/shellydimmer-lampaTV/light/0”, transformationPattern=“JSONPATH:$.brightness”, commandTopic=“shellies/shellydimmer-lampaTV/light/0/set”, transformationPatternOut=“JSONPATH:$.brightness”]

But in mqtt.fx I see sent value - 100
I need send
“brightness”: 100

You can’t just make syntax up. That would look at your output string as if was JSON, find a field called brightness and extract a value. You want the exact opposite - take a value and add JSON structure around it.

Before binding 2.5 that was usually done with rules, but now you could use a javascript transformation. Or maybe just add fixed text with formatBeforePublish

1 Like

You must use a JS transformation as @rossko57 said the JSONPATH transform only works to extract information. It can’t create a json string.

I have detailed the way to use a JS transformation above

Form me work a JSONPATH transformation in Input, to extract the Brigthness value. Ant the JS transformation in output as follow:

(function(brightness) {
    if (brightness > 100) {
        brightness = 100;
    } else if (brightness < 1) {
        brightness = 1;
    var shellyobj = { "turn":"on", "brightness":brightness};
    var data = JSON.stringify(shellyobj);
    return data;

For Shelly dimmer, the brightness value are 1…100, and I use a switch to set dimmer On or Off.

Why not simply use the Shelly Binding instead of MQTT.
Makes things a lot easier, even devices are discovered automatically…

I tried to use Shelly bindind first.
Yes, true, is simple and the devices is discovered, but I found that when the device state is changed out of openhub, e.g. using the local button, the update of status in openhub is slow.
I suppose that Shelly Binding use REST API (the configuration required to set http user and password), and the “polling interval”.
Using MQTT instead the status is updated when the MQTT topic is received from the broker like as “event driven”.

This might be an old expierience. The Binding uses CoIoT (CoAP) to receive changes immediately.
No delays.

My last info was that using the official shelly binding doesn’t support actions like “long push”.
Is it possible now? Thats the whole reason why I’m using MQTT.

AFAK yes, please check the Shelly Binding thread.

I’m also still using MQTT instead of the Shelly binding.

There are advantages of it I think:

  • Less binding installed, less binding related problem
  • All of my switches using MQTT, so it is much more straightforward to use it here also.
  • And: you don’t have to wait for the maintainer to update the database/add new devices and fix bugs in the binding. As far as I know, right now even the latest openHAB release is not working with the latest Shelly fw because the CoIoT protocol changed…

Yes, I am also using MQTT partly for these reasons. Additionally with MQTT I defined all things via text files and after a fresh new install of OH I do not have to wait fot auto-discovery of things etc, it justs works immediately. I Have a couple of Shelly Dimmers and they work fine with MQTT.

1 Like

You can define the Shelly Things via config file and skip discovery.

That is true. However my complete setup for the Shelly devices at the moment is via MQTT and it is working perfectly flawless. Is there any advantage if I use the Shelly binding?

Can‘t really tell, it is some kind of personal flavour. One thing i would mention, you don‘t have to break your head about incoming or outgoing transformation.