# Shellyplus1 (gen2) Nodered to MQTT

**URL:** <https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522>\
**Category:** General\
**Created:** [12 January 2022 12:24 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522 "2022-01-12T12:24:21Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Japie.G](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@Japie.G](https://discourse.nodered.org/u/Japie.G)\
**Post date:** [12 January 2022 12:24 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522/1 "2022-01-12T12:24:21Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 January 2022 12:47 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522/2 "2022-01-12T12:47:32Z")

</div>

You offer no info to help you.

You can find the topics and info here

> **[RPC Channels | Shelly Technical Documentation](https://shelly-api-docs.shelly.cloud/gen2/Overview/RPCChannels/)**
>
> Shellies support communication through multiple RPC channels. The number of simultaneous non-persistent RPC channels that can be opened on a Shelly is limited to 6.

and overview of rpc

> **[RPC Protocol | Shelly Technical Documentation](https://shelly-api-docs.shelly.cloud/gen2/Overview/RPCProtocol/)**
>
> RPCs (Remote Procedure Calls) are used to send commands to devices and receive notifications and replies from these devices.

---

<div class="post-metadata">

**Author:** ![Japie.G](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@Japie.G](https://discourse.nodered.org/u/Japie.G)\
**Post date:** [12 January 2022 13:37 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522/3 "2022-01-12T13:37:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 January 2022 13:57 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522/4 "2022-01-12T13:57:07Z")

</div>

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

```auto
{"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**

---

<div class="post-metadata">

**Author:** ![deputynl](https://avatars.discourse-cdn.com/v4/letter/d/49beb7/32.png) [@deputynl](https://discourse.nodered.org/u/deputynl)\
**Post date:** [12 January 2022 13:59 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522/5 "2022-01-12T13:59:52Z")

</div>

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.

```auto
[{"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":""}]

```

---

<div class="post-metadata">

**Author:** ![Japie.G](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@Japie.G](https://discourse.nodered.org/u/Japie.G)\
**Post date:** [12 January 2022 14:33 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522/6 "2022-01-12T14:33:06Z")

</div>

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:

```auto
[{"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 🙂

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

 ![Schermafbeelding 2022-01-12 om 15.39.47](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/95d35cb7e319e43ecd24e9838978e0fb8017d44b.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 January 2022 14:47 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522/7 "2022-01-12T14:47:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Japie.G](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@Japie.G](https://discourse.nodered.org/u/Japie.G)\
**Post date:** [12 January 2022 14:50 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522/8 "2022-01-12T14:50:13Z")

</div>

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

no succes

 ![Schermafbeelding 2022-01-12 om 15.48.43](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5ec23a12c5016a3aaacda7c3608a79647c5b9e8d.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 January 2022 14:53 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522/9 "2022-01-12T14:53:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Japie.G](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@Japie.G](https://discourse.nodered.org/u/Japie.G)\
**Post date:** [12 January 2022 15:00 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522/10 "2022-01-12T15:00:10Z")

</div>

I found the solution!

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

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 January 2022 15:00 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522/11 "2022-01-12T15:00:51Z")

</div>

you mean the solution i gave you in post 4.

---

<div class="post-metadata">

**Author:** ![Japie.G](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@Japie.G](https://discourse.nodered.org/u/Japie.G)\
**Post date:** [12 January 2022 15:01 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522/12 "2022-01-12T15:01:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 January 2022 15:02 UTC](https://discourse.nodered.org/t/shellyplus1-gen2-nodered-to-mqtt/56522/13 "2022-01-26T15:02:43Z")

</div>

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