Shelly 2nd generation devices & MQTT node

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!

Try something like this -

topic shellyplus1pm/command
payload status_update

And to see the data -

topic shellyplus1pm/status

Thanks. Can you please provide a simple example flow?

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

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

Thanks but please have a look on my flow.

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

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

Did you try the flow I posted ?

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!

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

{
    "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

[{"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.

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.

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.

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

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

{
    "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?

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!

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