I'm assuming that you already have setup a server (mosquitto or Aedes??).
Firstly, enter the url of your shelly in a browser, for example 192.168.1.7, and then navigate to the 'ADVANCED - DEVELOPER SETTINGS' and then 'Internet & Security'. Scroll down to the MQTT section and ensure that your server details are correct.
Tick the 'Use custom MQTT prefix', and enter a suitable topic (less than 25 characters), such as 'shelly-switch', save & exit.
You can check if the shelly is subscribed to your server, by running the attached flow - just change the shelly's IP address in the function node.
It should return true
.
[{"id":"c105348b.9c8838","type":"inject","z":"217df193.d774ce","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":"15","topic":"","payload":"","payloadType":"str","x":115,"y":2025,"wires":[["2181481b.e73508"]]},{"id":"2181481b.e73508","type":"function","z":"217df193.d774ce","name":"subscribe check","func":"//IP address of your shelly\nvar IP = \"192.168.1.10\";\nmsg.url= \"http://\"+ IP + \"/status\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":275,"y":2025,"wires":[["82f34ec5.6b90e"]]},{"id":"82f34ec5.6b90e","type":"http request","z":"217df193.d774ce","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"basic","x":475,"y":2025,"wires":[["b9c2b635.a80028"]]},{"id":"b9c2b635.a80028","type":"debug","z":"217df193.d774ce","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.mqtt.connected","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":2025,"wires":[]}]
If it is connected, then load the flow below, and update the MQTT node with your server details. The flow should then operate your shelly.
[{"id":"637a5b46.1cfc04","type":"mqtt out","z":"217df193.d774ce","name":"","topic":"","qos":"0","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"aa11e6d8.6cd088","x":300,"y":2290,"wires":[]},{"id":"3e851ca5.bfdb04","type":"inject","z":"217df193.d774ce","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"shellies/shelly-switch/relay/0/command","payload":"on","payloadType":"str","x":170,"y":2270,"wires":[["637a5b46.1cfc04"]]},{"id":"a1d185f8.bc0848","type":"inject","z":"217df193.d774ce","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"shellies/shelly-switch/relay/0/command","payload":"off","payloadType":"str","x":170,"y":2310,"wires":[["637a5b46.1cfc04"]]},{"id":"aa11e6d8.6cd088","type":"mqtt-broker","name":"Local server","broker":"192.168.1.8","port":"1883","clientid":"Local node-RED","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"admin","birthQos":"0","birthRetain":"false","birthPayload":"Hello from Local node-RED","closeTopic":"admin","closeQos":"0","closeRetain":"false","closePayload":"Local node-RED is about to exit","willTopic":"admin","willQos":"0","willRetain":"false","willPayload":"Local node-RED has now exited"}]
You can find further help & all of the MQTT commands here - API Reference