Shellyplus1 (gen2) Nodered to MQTT

Hello!

I am trying to switch the relay of a shellyplus-1 on and off using an MQTT message from nodered. With Gen1 shelly devices this was easy. I don’t know what i am doing wrong now. Without posting what i already tried i want to ask if somebody has a working example for switching the relay of the gen2 shelly device using mqtt. I am very interested in what message you send to which topic.

Thanks in advance!

You offer no info to help you.

You can find the topics and info here

and overview of rpc

Thanks! Yes i am aware of that info but for some reason i can’t get it to work. Thats why i hoped somebody has a working example of how the info from the shelly documentation is used within nodered.

I do not have any gen2 devices. But what have you tried?
As far as i can make out you send

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

to topic shelly_id/rpc

  • id : number/string, identifier of this request, will be used to match the response frame. Required
  • src : string, name of the source of the request (you can choose whatever string you like to identify you as the source of the request). Required
  • method : string, name of the procedure to be called. Required
  • params : JSON object, parameters that the method takes (if any) Optional

Hi, I have integrated it with Domoticz. The below bit, received a device when it was updated and when it was a new shelly (magic done elsewhere in my flow). It takes that and creates a packet to be sent over MQTT. It depends on you setting the mqtt topic to a matching value as used in this bit of the flow of course. I hope this helps you get started.

[{"id":"13d61c25d6ee165f","type":"switch","z":"68000b40.442d94","name":"shelliesnew","property":"device.HardwareName","propertyType":"msg","rules":[{"t":"eq","v":"ShelliesNew","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":400,"wires":[["87b904e5bfba1bfd"]]},{"id":"0313839891922c8f","type":"switch","z":"68000b40.442d94","name":"on/off","property":"device.Status","propertyType":"msg","rules":[{"t":"eq","v":"On","vt":"str"},{"t":"eq","v":"Off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":890,"y":400,"wires":[["b4647653e2f6b2a8"],["16c0e772f4ab74e2"]],"outputLabels":["on","off"]},{"id":"b4647653e2f6b2a8","type":"change","z":"68000b40.442d94","name":"On","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"id\":123,\"src\":\"/shelliesplus/responses\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":true}}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":390,"wires":[["dcbf6a94c241e495"]]},{"id":"16c0e772f4ab74e2","type":"change","z":"68000b40.442d94","name":"Off","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"id\":123,\"src\":\"/shelliesplus/responses\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":false}}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":420,"wires":[["dcbf6a94c241e495"]]},{"id":"dcbf6a94c241e495","type":"mqtt out","z":"68000b40.442d94","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"6f3b55a4.3a524c","x":1190,"y":400,"wires":[]},{"id":"87b904e5bfba1bfd","type":"string","z":"68000b40.442d94","name":"topic","methods":[{"name":"append","params":[{"type":"str","value":"/shelliesplus/shellyplus1-"}]},{"name":"append","params":[{"type":"msg","value":"device.Name"}]},{"name":"append","params":[{"type":"str","value":"/rpc"}]}],"prop":"","propout":"topic","object":"str","objectout":"msg","x":770,"y":400,"wires":[["0313839891922c8f"]]},{"id":"6f3b55a4.3a524c","type":"mqtt-broker","name":"Mosquitto","broker":"mosquitto","port":"1883","clientid":"","usetls":false,"compatmode":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

Thanks so much for your effort. I think I overlook something.I think I do exactly what the API wants me to do. I watched the flow above and tried to alter some things but nothing changes.

I just made a simple inject node and I hook that up to a MQTT out node. My inject node looks like this:

[{"id":"f6ee0c7b.18c73","type":"inject","z":"d8a5ec23.77e018","name":"on","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"shellies/shellyplus1-441793a3acb0/rpc","payload":"{\"id\":123,\"src\":\"/shellyplus1-441793a3acb0/rpc\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":true}}","payloadType":"json","x":90,"y":80,"wires":[["bc861e3.ae07ae"]]}]

My shelly id name is shellyplus1-441793a3acb0

What am I doing wrong. I am a beginner, so it will be something stupid I think, but with the Gen1 there was no problem :slight_smile:

When I send the json via MQTT to the shelly I get it back as a plain response..

From the image your topic is ending rpc/, try removing the last /.

Already tried all combinations with slashes, no slashes, /rpc or events/rpc

no succes

Can we see the mqtt config page of the shelly 1?

also set an mqtt in node to topic #, and then manually switch the shelly, what topic and payload do you see?

Or install mqtt explorer

I found the solution!

I did not need to use shellies/ in front of the topic :crazy_face: :crazy_face: Now it all works as expected. Wow!

Thanks for your help, already thought it was something stupid..

1 Like

you mean the solution i gave you in post 4.

1 Like

Yes thank you so much. I overlooked it. Stupid me

Sometimes you get so blinded by a stupid mistake you just don't see it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.