Shelly Dimmer default FW + MQTT control

A quick summary of Shelly Dimmer integration into OpenHAB using default firmware and control over MQTT.

Device description can be found here


    // Shelly dimmer
Thing mqtt:topic:shelly_dimmer1 "Light" @ "Buro" {
    Type switch : power             "Power"         [ stateTopic="shellies/shellydimmer-XXXXXX/light/0/status", transformationPattern="JS:shelly_dimmer-status.js", commandTopic="shellies/shellydimmer-XXXXXX/light/0/command", on="on", off="off" ]
    Type dimmer : dimmer            "Dimmer"        [ stateTopic="shellies/shellydimmer-XXXXXX/light/0/status", transformationPattern="JSONPATH:$.brightness", commandTopic="shellies/shellydimmer-XXXXXX/light/0/set", transformationPatternOut="JS:shelly_dimmer-brightness.js"]
    Type number : temperature       "Temperature"   [ stateTopic="shellies/shellydimmer-XXXXXX/temperature"]
    Type number : energy            "Energy"        [ stateTopic="shellies/shellydimmer-XXXXXX/light/0/power"]


Switch Shelly_dimmer1_Power      "Dimmer1 Light []"                     <light>                 (gPers_Change_Hour)                     {channel="mqtt:topic:shelly_dimmer1:power"}
Dimmer Shelly_dimmer1_Dimmer     "Dimmer1 [%d %%]"                      <light>                 (gPers_Change_Hour)                     {channel="mqtt:topic:shelly_dimmer1:dimmer"}
Number Shelly_dimmer1_Temp       "Temperature [%.1f°C]"                 <temp>                  (gPers_Change_Hour, gTempSocket)        {channel="mqtt:topic:shelly_dimmer1:temperature"}
Number Shelly_dimmer1_Energy     "Power [%.1f W]"                       <energy>                (gPers_Change_Hour)                     {channel="mqtt:topic:shelly_dimmer1:energy"}


(function(jsonString) {
    var data = JSON.parse(jsonString);
    var isonState = data.ison;
    if (isonState === null) isonState = UNDEF;
    if (isonState == true) isonState = 'ON';
    if (isonState == false) isonState = 'OFF';
    return isonState;


(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;

An alternative to the JS Transform would be to chain the JSONPATH transformation with a MAP transformation. I’m not saying that would be better, just mentioning it as an alternative. Thanks for posting!

oh interesting, thanks for the hint.

No working. I have:

> Type dimmer : shellydimmerlampaTVDimmer " shellydimmerlampaTV Dimmer"        [ stateTopic="shellies/shellydimmer-lampaTV/light/0/status", transformationPattern="JSONPATH:$.brightness", commandTopic="shellies/shellydimmer-lampaTV/light/0/set", transformationPatternOut="JS:shelly_dimmer-brightness.js"]

File shelly_dimmer-brightness.js with your code and in MQTT.fx I see send only number not string.
shellies/shellydimmer-lampaTV/light/0/set with value 58.
Must be text {
“brightness”: 100

You will need both Javascript transformation service installed, and a 2.5 version of MQTT binding that supports transformationPatternOut

1 Like

Excellent overview, thank you very much!

I was wondering if the Shelly Dimmer also supports reporting of total enery consumption as all other newer Shelly Devices do. It is not mentioned in the API documentation, but it does. I just looked at the MQTT data sent and it reports this as …/energy… :slightly_smiling_face: (like all other Shelly devices).

So we can complete the things channel definition

Type number : totalenergy "Total Energy"   [ stateTopic="shellies/shellydimmer-XXXXXX/light/0/energy", transformationPattern="JS:divideby60000.js" ]

The JS transformation is needed to obtain a value in the unit kWh as all Shelly devices report in Watt minutes.
So the divideby60000.js tranformation looks like this

(function(i) {
    return Number((parseFloat(i) / 60000).toFixed(3)); 
1 Like