# Shelly 2nd generation devices & MQTT node

**URL:** <https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400>\
**Category:** General\
**Tags:** mqtt\
**Created:** [17 September 2023 12:58 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400 "2023-09-17T12:58:59Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jnn](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@jnn](https://discourse.nodered.org/u/jnn)\
**Post date:** [17 September 2023 12:58 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/1 "2023-09-17T12:58:59Z")

</div>

Hello,  
I'm a beginner when it comes to MQTT, and I'm trying to understand Shelly's API documentation for the 2nd generation devices.  
I have successfully subscribed to the following topics to work with MQTT in Node-RED:  
shellyplus1pm/events/rpc  
shellyplus1pm/online  
shellyplus1pm/status/switch:0

Now I am attempting to subscribe to the topic **Sys.GetConfig** I have tested using, for instance, **shellyplus1pm/MQTT.GetStatus** but I couldn't get it to work, got no response.  
https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Mqtt#mqttgetstatus-example

However, I believe I might be thinking in the wrong direction because if you look at the curl example, they are posting data instead:  
`curl -X POST -d '{"id":1,"method":"MQTT.GetStatus"}' http://${SHELLY}/rpc`

Here's an example for Mosquitto:  
`mos --port ${PORT} call MQTT.GetStatus`

I'm trying to understand how to "translate" the examples for Mosquitto in Shelly's documentation to MQTT nodes in Node-RED. I would appreciate some assistance. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [19 September 2023 09:56 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/2 "2023-09-19T09:56:06Z")

</div>

Try something like this -

```auto
topic shellyplus1pm/command
payload status_update

```

And to see the data -

```auto
topic shellyplus1pm/status

```

---

<div class="post-metadata">

**Author:** ![jnn](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@jnn](https://discourse.nodered.org/u/jnn)\
**Post date:** [19 September 2023 15:37 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/3 "2023-09-19T15:37:58Z")

</div>

Thanks. Can you please provide a simple example flow?

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [20 September 2023 01:27 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/4 "2023-09-20T01:27:09Z")

</div>

You will need to edit the MQTT nodes to add your broker

```auto
[{"id":"f679d31399ec44ed","type":"inject","z":"c8c7826a005c7f46","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"status_update","payloadType":"str","x":815,"y":1275,"wires":[["f117c29ea943dbeb"]]},{"id":"4cc106b5b2a206eb","type":"mqtt in","z":"c8c7826a005c7f46","name":"","topic":"shellyplus1pm/status","qos":"2","datatype":"auto-detect","broker":"","nl":false,"rap":true,"rh":0,"inputs":0,"x":810,"y":1320,"wires":[["d34bb2e2cfae8256"]]},{"id":"f117c29ea943dbeb","type":"mqtt out","z":"c8c7826a005c7f46","name":"","topic":"shellyplus1pm/command","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"","x":1040,"y":1275,"wires":[]},{"id":"d34bb2e2cfae8256","type":"debug","z":"c8c7826a005c7f46","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":975,"y":1320,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![jnn](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@jnn](https://discourse.nodered.org/u/jnn)\
**Post date:** [20 September 2023 15:53 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/5 "2023-09-20T15:53:04Z")

</div>

Thanks but please have a look on my flow.

```auto
[{"id":"a765589401bee4b4","type":"tab","label":"Shelly plus tests","disabled":false,"info":"","env":[]},{"id":"2fc172e9f6ab846e","type":"mqtt out","z":"a765589401bee4b4","name":"","topic":"shellyplus1pm/events/rpc","qos":"2","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"b288429d0f6eacbf","x":580,"y":560,"wires":[]},{"id":"dbf798fd9567a827","type":"mqtt in","z":"a765589401bee4b4","name":"","topic":"shellyplus1pm/status/switch:0","qos":"2","datatype":"auto-detect","broker":"b288429d0f6eacbf","nl":false,"rap":false,"inputs":0,"x":270,"y":140,"wires":[["eee493262658807b"]]},{"id":"1fb4cecb8a930829","type":"mqtt in","z":"a765589401bee4b4","name":"","topic":"shellyplus1pm/online","qos":"2","datatype":"auto-detect","broker":"b288429d0f6eacbf","nl":false,"rap":false,"inputs":0,"x":240,"y":260,"wires":[["eee493262658807b"]]},{"id":"4f0d9f3e660315cd","type":"mqtt in","z":"a765589401bee4b4","name":"","topic":"shellyplus1pm/events/rpc","qos":"2","datatype":"auto-detect","broker":"b288429d0f6eacbf","nl":false,"rap":false,"inputs":0,"x":260,"y":200,"wires":[["eee493262658807b"]]},{"id":"e52690129360bd8a","type":"mqtt in","z":"a765589401bee4b4","name":"","topic":"shellyplus1pm/rpc/Shelly.GetConfig","qos":"2","datatype":"auto-detect","broker":"b288429d0f6eacbf","nl":false,"rap":false,"inputs":0,"x":290,"y":500,"wires":[["588a356d8f0d8a25"]]},{"id":"36d781ec5f3783fa","type":"comment","z":"a765589401bee4b4","name":"The following works:","info":"","x":190,"y":80,"wires":[]},{"id":"03b1186a84cb7f39","type":"comment","z":"a765589401bee4b4","name":"I am unsure about the 'GetConfig' command. I have tested some different variants that don't work:","info":"","x":430,"y":400,"wires":[]},{"id":"39718c42cd246ff3","type":"inject","z":"a765589401bee4b4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Shelly.GetConfig","payloadType":"str","x":200,"y":560,"wires":[["2fc172e9f6ab846e"]]},{"id":"1681b442de8dcafa","type":"template","z":"a765589401bee4b4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"id\":1,\"method\":\"Shelly.GetConfig\"}","output":"json","x":320,"y":600,"wires":[["2fc172e9f6ab846e"]]},{"id":"2cb269372ac52fe9","type":"inject","z":"a765589401bee4b4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":600,"wires":[["1681b442de8dcafa"]]},{"id":"a4a70127efeb1b97","type":"comment","z":"a765589401bee4b4","name":"Tested with different topics, path and so on","info":"","x":260,"y":440,"wires":[]},{"id":"98bbc3ad4e4cbfc3","type":"comment","z":"a765589401bee4b4","name":"Shelly.GetConfig Mos Request according to the Shelly Gen 2 API docs: mos --port ${PORT} call Shelly.GetConfig","info":"","x":480,"y":680,"wires":[]},{"id":"588a356d8f0d8a25","type":"debug","z":"a765589401bee4b4","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":580,"y":500,"wires":[]},{"id":"eee493262658807b","type":"debug","z":"a765589401bee4b4","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":570,"y":180,"wires":[]},{"id":"b288429d0f6eacbf","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

```

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [20 September 2023 22:50 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/6 "2023-09-20T22:50:50Z")

</div>

What am I supposed to be looking at, the get config part of this flow is wrong ?

Did you try the flow I posted ?

---

<div class="post-metadata">

**Author:** ![jnn](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@jnn](https://discourse.nodered.org/u/jnn)\
**Post date:** [21 September 2023 04:58 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/7 "2023-09-21T04:58:15Z")

</div>

Your flow did not work. Yeah, the broker works fine, and getting data from the topics in the first section of my flow works fine. Sorry, I mixed up Sys.GetConfig and MQTT.GetStatus  
The sections below in my flow are where I attempted to make the "GetConfig" command work (tested various ways), but without any luck. So there, I need help.Thanks!

---

<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:** [21 September 2023 06:40 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/8 "2023-09-21T06:40:55Z")

</div>

You have to specify the topic in the payload using the src, this can be any string you wish. Then send to `shellyplus1pm- ************* /rpc`, where \*\*\*\*\*\*\*\* is the deviceid.  
e.g

```auto
{
    "id": 100000,
    "src": "shelly_config",
    "method": "Shelly.GetConfig"
}

```

Then in the mqtt in use the src to create the receiving topic.  
e.g.  
`shelly_config/rpc`

example flow

```auto
[{"id":"e52690129360bd8a","type":"mqtt in","z":"b9860b4b9de8c8da","name":"","topic":"shelly_config/rpc","qos":"2","datatype":"auto-detect","broker":"b288429d0f6eacbf","nl":false,"rap":false,"inputs":0,"x":180,"y":980,"wires":[["588a356d8f0d8a25"]]},{"id":"588a356d8f0d8a25","type":"debug","z":"b9860b4b9de8c8da","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":980,"wires":[]},{"id":"69cbdf6e61c4f96a","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":100000,\"src\":\"shelly_config\",\"method\":\"Shelly.GetConfig\"}","payloadType":"json","x":180,"y":1040,"wires":[["2fc172e9f6ab846e"]]},{"id":"2fc172e9f6ab846e","type":"mqtt out","z":"b9860b4b9de8c8da","name":"","topic":"shellyplus1pm/rpc","qos":"2","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"b288429d0f6eacbf","x":380,"y":1040,"wires":[]},{"id":"b288429d0f6eacbf","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

```

[edit] fixed topic in mqtt out node, should be something like `shellyplus1pm/rpc`. Your first section is missing the deviceid should be some thing like `shellyplus1pm-b578c99276721c1/rpc`. The deviceid is required to differentiate between devices.

---

<div class="post-metadata">

**Author:** ![jnn](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@jnn](https://discourse.nodered.org/u/jnn)\
**Post date:** [21 September 2023 07:02 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/9 "2023-09-21T07:02:54Z")

</div>

Thanks! I will have a look later on. Yeah I am aware of the device id, just masked it in my flow that I posted.

---

<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:** [21 September 2023 07:06 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/10 "2023-09-21T07:06:41Z")

</div>

I thought that maybe the case, but it creates confusion. Next time mask it like.  
`shellyplus1pm- ********** /rpc`, It will save confusion, specially for future readers of the topic.

---

<div class="post-metadata">

**Author:** ![jnn](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@jnn](https://discourse.nodered.org/u/jnn)\
**Post date:** [21 September 2023 16:55 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/12 "2023-09-21T16:55:40Z")

</div>

Yeah sorry for the confusion.  
No output in the debug window with your example either, I changed id to 1 in the inject code. Dunno what is wrong

---

<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:** [21 September 2023 17:20 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/13 "2023-09-21T17:20:07Z")

</div>

I do not know whats wrong either, as you give no example of what you used. As my example would of required editing with your device id in mqtt node. If you want more help please provide what you did.

works for me  
returns

```auto
{
    "id": 100000,
    "src": "shellyplus1pm- ****",
    "dst": "shelly_config",
    "result": {
        "ble": {
            "enable": false,
            "rpc": {
                "enable": true
            },
            "observer": {
                "enable": false
            }
        },
        "cloud": {
            "enable": true,
            "server": "s *****"
        },
        "input:0": {
            "id": 0,
            "name": null,
            "type": "switch",
            "invert": false,
            "factory_reset": true
        },
        "mqtt": {
            "enable": true,
            "server": "1 ****",
            "client_id": "shellyplus1pm- ****",
            "user": null,
            "topic_prefix": "shellyplus1pm- ****",
            "rpc_ntf": false,
            "status_ntf": true,
            "use_client_cert": true,
            "enable_rpc": true,
            "enable_control": true
        },
        "switch:0": {
            "id": 0,
            "name": "Shelly_solar",
            "in_mode": "follow",
            "initial_state": "restore_last",
            "auto_on": false,
            "auto_on_delay": 60,
            "auto_off": false,
            "auto_off_delay": 60,
            "power_limit": 4480,
            "voltage_limit": 280,
            "autorecover_voltage_errors": false,
            "current_limit": 16
        },
        "sys": {
            "device": {
                "name": null,
                "mac": " ****",
                "fw_id": "2 ****",
                "discoverable": true,
                "eco_mode": false,
                "addon_type": null
            },
            "location": {
                "tz": " **** n",
                "lat": 1234,
                "lon": 1234
            },
            "debug": {
                "mqtt": {
                    "enable": false
                },
                "websocket": {
                    "enable": false
                },
                "udp": {
                    "addr": null
                }
            },
            "ui_data": {
                "consumption_types": [
                    "relay"
                ]
            },
            "rpc_udp": {
                "dst_addr": null,
                "listen_port": null
            },
            "sntp": {
                "server": " ****"
            },
            "cfg_rev": 55
        },
        "wifi": {
            "ap": {
                "ssid": "ShellyPlus1PM- ****",
                "is_open": true,
                "enable": false,
                "range_extender": {
                    "enable": false
                }
            },
            "sta": {
                "ssid": " ****",
                "is_open": false,
                "enable": true,
                "ipv4mode": "static",
                "ip": " ****",
                "netmask": " ****",
                "gw": " ****",
                "nameserver": null
            },
            "sta1": {
                "ssid": " ****",
                "is_open": false,
                "enable": true,
                "ipv4mode": "static",
                "ip": " ****",
                "netmask": " ****",
                "gw": " ****",
                "nameserver": null
            },
            "roam": {
                "rssi_thr": -80,
                "interval": 60
            }
        },
        "ws": {
            "enable": true,
            "server": " ****",
            "ssl_ca": " ****"
        }
    }
}

```

Is rpc enabled in your shelly settings for device?

---

<div class="post-metadata">

**Author:** ![jnn](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@jnn](https://discourse.nodered.org/u/jnn)\
**Post date:** [22 September 2023 14:43 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/14 "2023-09-22T14:43:01Z")

</div>

Yes, RPC was enabled on the Shelly device. I tested your example flow again, and now it worked. Maybe I just had some typo somewhere. Many thanks for your help and patience!

---

<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:** [6 October 2023 14:44 UTC](https://discourse.nodered.org/t/shelly-2nd-generation-devices-mqtt-node/81400/15 "2023-10-06T14:44:02Z")

</div>

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