Erverthing started after I have bought a brand new Shelly Plus RGBW PM for my frontdoor lights.
Very fast I figured out that the current Shelly-Binding is not properly working with newer Shelly devices. But than I remembered that in the beginning we all connected Shelly devices via MQTT. So I decided to give it a try as I really urgently need this functionality in OpenHAB. Again very fast I figured out that the MQTT communication with newer Shelly devices also changed. I guess it is a more modern way to use the MQTT Qeue and I started searching for a solution. I finally made it running but was a little frustrated as I had to collect the information over many Support threads. I found a lot of âalmost knowing and copying from other threads solutionsâ but I never had the feeling that the author really did understand what he/she had to configre or why you had to configure it like that. So at the end I thought my self that a more complete Tutorial could be a good thing to all the people who need currently a solution.
This tutorial will start after you have setted up and configured a mqtt bridge in OpenHAB
I will start with the very specific configuration of my Shelly Plus RGBW PM and will at the end be more generic. Thatâs at least the plan.
- Configure Your Shelly Device
- enable MQTT
- use your own MQTT prefix or use the default one you only have to know it!!
2. Add a generic MQTT thing to OpenHAB
- Choose your bridge
- Create the thing
3. Configure your MQTT thing
- Open the MQTT thing and open the code page
The header should look similar to the one here (some other ids)
UID: mqtt:topic:4ce2582d:shellyplusrgbw
label: Shelly Plus RGBW
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:4ce2582d
The channels need configuration. Please keep in mind, that #shellymqtttopic
needs to be replaced with whatever you have choosen in your Shelly MQTT configuration above as MQTT prefix
channels:
- id: LEDSwitch
channelTypeUID: mqtt:switch
label: LED Schalter
configuration:
commandTopic: #shellymqtttopic/rpc
formatBeforePublish: '{"id":1,"src":"#shellyresponse","method":"Light.Set","params":{"id":1,"on":%s}}'
stateTopic: #shellymqtttopic/events/rpc
transformationPattern:
- JSONPATH:$.params.light:1.output
off: "false"
on: "true"
Find explainations to the MQTT settings here OpenHAB Generic MQTT Thing
Letâ explain the configuration:
of the channels.
configuration | value | description |
---|---|---|
commandTopic: |
#shellymqtttopic/rpc | This is the MQTT queue where the request is sended if you want to change any item off the thing |
formatBeforePublish: |
â{âidâ:1,âsrcâ:âshellyresponseâ,âmethodâ:âLight.Setâ,âparamsâ:{âidâ:1,âonâ:%s}}â | This is single quoted as the mqtt answer needs double quotes |
stateTopic: |
#shellymqtttopic/events/rpc | This is the MQTT queue where you get the information of the thing from |
transformationPattern: |
- JSONPATH: $.params.light:1.output |
The answer of the shelly thing is a json and to separate values from the anwer json you have JSONPATH to be installed |
off: |
âfalseâ | as this is a switch there is on and off which is true and false on the shelly |
on: |
âfalseâ |
Letâs understand the formatBeforePublish:
and JSONPATH:
formatBeforePublish:
- id : you can choose a numeric value here. It is only for identification
- src : this is the MQTT prefix (src/rpc) where you will get the answer back when you send a message to your shelly device. Thatâs why you can choose your own name. For us this only has a function if you want to debug why the shelly is not doing what you have told it. This is in our case normaly not used
- method : This parameter took me the most time to understand. I found a lot of examples where this value was set to âSwitch.Setâ and I never got any reaction on the Shelly. The trick is, this value depends on the device and furthermore on the devicemode!! This is decribed on the Shelly documentation (Shelly Light) but not very clearly to me.
- params : This is the json you will send to your shelly device. Which parameter you can set depends again on the device or the devicemode. There is simple trick to get easily what your shelly is supporting. It also helps you to figure out which method you have to use. In your browser type in
ip-address_of_your_shelly_device/rpc/Light.GetStatus?id=0
. If it is a switch use Switch.GetStatus?id=0, an RGBW uses RGBW.GetStatus?id=0 etc. If you use the wrong method you will get as answer
.
If you do it right you get the status of your device
JSONPATH:
- As an answer you get a json String
{"src":"shellyplusrgbwpm-08a6f7732ae8","dst":"shellyplusrgbwhaustuer/events","method":"NotifyStatus","params":{"ts":1739093012.22,"light:0":{"id":0,"brightness":69,"output":true,"source":"WS_in"}}}
.
We are only interested on the part âparamâ. If you want retrieve theoutput
value with JSONPATH we have to start with$.params
an. Under params you find the next node light:1 which we add with a dot$.params.light:1
. output is then the next node under light:1 which we also add via dot for the final result$.params.light:1.output
- As an answer you get a json String
"params": {
"light:0": {
"brightness": 3,
"id": 0,
"output": true,
"source": "WS_in"
},
"ts": 1739092905.97
}
3.1 Configure the brightness channel
- id: LEDBrightness
channelTypeUID: mqtt:dimmer
label: LEDs Helligkeit
configuration:
min: 0
formatBeforePublish: '{"id":1,"src":"shellyresponse","method":"Light.Set","params":{"id":1,"brightness":%s}}'
max: 100
commandTopic: #shellymqtttopic/rpc
step: 1
stateTopic: #shellymqtttopic/events/rpc
transformationPattern:
- JSONPATH:$.params.light:1.brightness
5. Additional Remark
I do have a Shelly Plus RGBW PM and this one can either be driven in RGBW mode or 4LED switch mode. The method:
you need in the output channel is different depending on the mode:
Please if you think, that this tutorial is still a bad description for the configuration write your questions in the comments below so that we can improve this tutorial.