Shellyplus 1 integration via MQTT

Hi,
has anyone here successfully integrated a shellyplus 1 relay into the openhab-environment via mqtt?
I just want to toggle the relay output.
I have managed to toggle it via the mqtt-explorer, but now i struggle with the transformations for the input/output…

The Syntax for turning the relay on is:

{
  "id": 123,
  "src":"shellyplus1",
  "method": "Switch.Set",
  "params":{
    "id":0,
    "on":true
  }
}

The response therefore is:
{"id": 0, "source": "MQTT", "output": false,"temperature":{"tC":55.3, "tF":131.5}}

Thanks in Advance!

Are you using the main UI or text config?

What do you put into mqtt explorer to get it to work ?

Looking at the doc (I don’t have any shelly stuff)

Shelly1 and Shelly1PM uses the following topics, where <model> is either shelly1 or shelly1pm:

  • shellies/<model>-<deviceid>/relay/0 to report status: on, off or overpower (the latter only for > > Shelly1PM)
  • shellies/<model>-<deviceid>/relay/0/command accepts on, off or toggle and applies accordingly
  • shellies/<model>-<deviceid>/input/0 reports the state of the SW terminal
  • shellies/<model>-<deviceid>/longpush/0 reports longpush state as 0 (shortpush) or 1 (longpush)
  • shellies/<model>-<deviceid>/input_event/0 reports input event and event counter, e.g.: {"event":"S","event_cnt":2} see /status for details

Your state topic is shellies/<model>-<deviceid>/relay/0
Your Command topic is shellies/<model>-<deviceid>/relay/0/command

You need to transform on=ON and off=OFF maybe

Hi,
I’m using the main UI.
The syntax for the second generation of shellys is completely different from the ones from the first generation. You can see it by the plus in the name :grinning:

I publish

{
  "id": 123,
  "src":"shellyplus1",
  "method": "Switch.Set",
  "params":{
    "id":0,
    "on":true
  }
}

to the topic <shellyplus_relayname> / rpc and then get the response to the topic named in the “src” parmeter of the published payload.

My problem is that i have no idea how to “build” my payload in the Channel of the thing.

Maybe something like this may help

JSONPATH:$.params.on

{ “id”: 123, “src”:“shellyplus1”, “method”: “Switch.Set”, “params”:{ “id”:0, “on”:%s } }

Oh if you have multiple devices on same topic you may need to filter

REGEX:(.*src\":\"shellyplus1.*)∩JSONPATH:$.params.on

HI,
thanks for your help. I can now turn the relay on, but somehow it does not turn off when toggling the item in OH to false.
It seems that the OH doesn’t publish to the topic, when i turn the item for the channel of, as i can’t see any payload in MQTT-Explorer.
I also swapped the transformations for the ON and OFF-Values. In this case, i can turn the relay off but not on…

I also tried to remove the state-topic in the channel-config, but this has no effect at all.
Do you have any idea what i could do?

my current config

How are you doing that, does your Item actually get a command? See your events.log

If i toggle my linked item “Test_Betrieb” via OH to true, i can see in the MQTT-Explorer that the message
{ "method": "Switch.Set", "params": { "id": 0, "on": true } } is published. If i turn the item off, no message is beeing published.
However, i cant see anything in the logger. (I’ve looked via :9001 , should be correct?)

I don’t know what that means. Isn’t your linked Item a Switch type, with ON/OFF commands and states?

Somethings wrong. If it works for ‘true’, then you should see commands in your events.log. Looking in wrong place, or logging not working (which makes it difficult to fix anything else)

I am prodding at this because the UI switch widget has a limitation, you can click ON for Items that have no OFF state, but clicking OFF doesn’t work unless the Item state is ON.
In other words, your state update settings might not be working.

You need to have a state topic filled in for it to work. What is your state topic?

Hi,
filling in the state topic didn’t change the problem, but i recogniced that the State of the Switch-Item stayed NULL. I’ve also seen in MC that the event.log-file didn’t change since 5th of Nov (almost a week). I restarted my OH and then re-installed the log-viewer via openhabian-config-tool.
After the next reboot it worked fine.

Thanks to the both of you for your help!

1 Like