# Shelly integration Nodered

**URL:** https://discourse.nodered.org/t/shelly-integration-nodered/44820
**Category:** General
**Created:** [27 April 2021 18:35 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820 "2021-04-27T18:35:19Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![automati](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@automati](https://discourse.nodered.org/u/automati)
#### Post date: [27 April 2021 18:35 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/1 "2021-04-27T18:35:19Z")

</div>

Hello everybody

A question, does anyone know how I can integrate a Shelly switch in Nodered?  
At the end I want to switch off the Shellys from Nodered and always know the status of the Shelly (whether closed or open)

Can someone help me there ?

Many Thanks!

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [27 April 2021 18:37 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/2 "2021-04-27T18:37:12Z")

</div>

The easiest way to control Shellys is using MQTT. You can also query their status.

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [27 April 2021 18:38 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/3 "2021-04-27T18:38:57Z")

</div>

Alternatively take look at the [node-red-contrib-shelly](https://flows.nodered.org/node/node-red-contrib-shelly) node.  
(However I agree with @ghayne, MQTT is a better option)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [27 April 2021 18:39 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/4 "2021-04-27T18:39:42Z")

</div>

Or use [node-red-contrib-shelly](https://flows.nodered.org/node/node-red-contrib-shelly). That gives you the option of still using cloud services (correct me if I'm wrong but enabling MQTT disables cloud service?)

---

<div class="post-metadata">

### Author: ![automati](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@automati](https://discourse.nodered.org/u/automati)
#### Post date: [27 April 2021 18:49 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/5 "2021-04-27T18:49:16Z")

</div>

Yes, I think so too, but I've been trying for a while, but can't get to the Shelly ...

---

<div class="post-metadata">

### Author: ![automati](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@automati](https://discourse.nodered.org/u/automati)
#### Post date: [27 April 2021 18:49 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/6 "2021-04-27T18:49:38Z")

</div>

Yes, I think so too, but I've been trying for a while, but can't get to the Shelly

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [27 April 2021 20:38 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/7 "2021-04-27T20:38:53Z")

</div>

> [@automati](#):
>
> but I've been trying for a while, but can't get to the Shelly

Have you enabled MQTT in the Shelly?

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [27 April 2021 20:43 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/8 "2021-04-27T20:43:04Z")

</div>

To enable MQTT on a Shelly, you need recent firmware and you need to not be using the Shelly cloud.

You could also re-flash the Shelly with alternative firmware such as Tasmota or ESPHome.

---

<div class="post-metadata">

### Author: ![automati](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@automati](https://discourse.nodered.org/u/automati)
#### Post date: [28 April 2021 05:51 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/10 "2021-04-28T05:51:50Z")

</div>

Yes, I have, but I don't know exactly how I have to do the whole thing in Nodered to make it work. Does anyone have instructions on how this works?

---

<div class="post-metadata">

### Author: ![Simon01011](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Simon01011](https://discourse.nodered.org/u/Simon01011)
#### Post date: [28 April 2021 08:17 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/11 "2021-04-28T08:17:05Z")

</div>

You can start here: [Shelly RGBW2 mit RGBW LED Strip Nodered Flow?](https://discourse.nodered.org/t/shelly-rgbw2-mit-rgbw-led-strip-nodered-flow/22083)

This will get you started if you compare the flow to the documentation on the Shelly website. Afterwards you can change the flow to use different shellies.

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [28 April 2021 08:43 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/12 "2021-04-28T08:43:09Z")

</div>

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.

 ![shell](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/f/2fad26765e2d4f235145a9f34eddecbb7581676a.jpeg)

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`.

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

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

```

![shell2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/83dda5c93e806af018c323b14295bca298c8f0f1.jpeg)

You can find further help & all of the MQTT commands here - [API Reference](https://shelly-api-docs.shelly.cloud/#shelly1-1pm-mqtt)

---

<div class="post-metadata">

### Author: ![automati](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@automati](https://discourse.nodered.org/u/automati)
#### Post date: [28 April 2021 10:41 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/13 "2021-04-28T10:41:28Z")

</div>

what kind of server should I already have set up?

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [28 April 2021 11:12 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/14 "2021-04-28T11:12:42Z")

</div>

> [@automati](#):
>
> what kind of server

I did say in my last post...

> [@Paul-Reed](#):
>
> (mosquitto or Aedes??)

You need a MQTT broker for the Shelly to talk & listen to.  
'Server' is another term for 'Broker' (I called it a Server because that's what the Shelly calls it in the config)

---

<div class="post-metadata">

### Author: ![automati](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@automati](https://discourse.nodered.org/u/automati)
#### Post date: [28 April 2021 15:52 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/15 "2021-04-28T15:52:01Z")

</div>

So with Nodered I can't control the Shellys directly?

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [28 April 2021 15:56 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/16 "2021-04-28T15:56:37Z")

</div>

Yes, using the [node-red-contrib-shelly](https://flows.nodered.org/node/node-red-contrib-shelly) node, as discussed above, but if you want to use MQTT, you do need to use a MQTT server.  
Unless you want a learning experience, maybe use the shelly node, and leave MQTT for another day 😉

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [28 April 2021 15:56 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/17 "2021-04-28T15:56:40Z")

</div>

> [@Steve-Mcl](#):
>
> Or use [node-red-contrib-shelly](https://flows.nodered.org/node/node-red-contrib-shelly). That gives you the option of still using cloud services (correct me if I'm wrong but enabling MQTT disables cloud service?)

Correct @Steve-Mcl

 ![Opera Snapshot_2021-04-28_165511_192.168.1.200](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/aba8853f589e78d9d1ccf18bd2e5f4d3d68bd892.png)

---

<div class="post-metadata">

### Author: ![automati](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@automati](https://discourse.nodered.org/u/automati)
#### Post date: [28 April 2021 16:44 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/18 "2021-04-28T16:44:42Z")

</div>

was für ein MQTT Broker empfehlen Sie?

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [28 April 2021 17:12 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/19 "2021-04-28T17:12:18Z")

</div>

I would suggest reading the [basics about MQTT](https://www.hivemq.com/mqtt-essentials/) before going further, it will answer most of your questions, and enable you to determine if MQTT is the correct approach for you.

---

<div class="post-metadata">

### Author: ![mrdvt92](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrdvt92/32/33122_2.png) [@mrdvt92](https://discourse.nodered.org/u/mrdvt92)
#### Post date: [30 April 2021 01:41 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/20 "2021-04-30T01:41:08Z")

</div>

I have a Shelly EM and I use my Perl lib which uses the HTTP API with the device and then an HTTP API with Node-Red.

> **[Power::Outlet::Shelly - Control and query a Shelly GIPO Relay with HTTP REST...](https://metacpan.org/pod/Power::Outlet::Shelly)**
>
> Control and query a Shelly GIPO Relay with HTTP REST API

Using the included CGI script [power-outlet-json.cgi - Control Power::Outlet device with JSON web service (e.g. Node-Red) - metacpan.org](https://metacpan.org/pod/distribution/Power-Outlet/scripts/power-outlet-json.cgi.pod)

Configure the INI file

```auto
$ cat /etc/power-outlet.ini
[MyShelly]
type=Shelly
style=relay
index=0
host=192.168.88.99

```

Then you use a standard http request node to make it turn on and off.

```auto
[{"id":"379199c2.aa7f06","type":"http request","z":"1d254cc8.5925b3","name":"power-outlet","method":"GET","ret":"obj","paytoqs":false,"url":"https://127.0.0.1/power-outlet/power-outlet-json.cgi?name={{topic}};action={{payload}}","tls":"","persist":false,"proxy":"","authType":"","x":250,"y":280,"wires":[["ee0ca2cf.7c35d"]],"inputLabels":["Topic=>name, Payload=>action"]},{"id":"7543ad3a.13e6c4","type":"inject","z":"1d254cc8.5925b3","name":"","topic":"MyShelly","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":80,"y":260,"wires":[["379199c2.aa7f06"]]},{"id":"9abe2d4.518afd","type":"inject","z":"1d254cc8.5925b3","name":"","topic":"MyShelly","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":80,"y":300,"wires":[["379199c2.aa7f06"]]},{"id":"ee0ca2cf.7c35d","type":"debug","z":"1d254cc8.5925b3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":430,"y":280,"wires":[]}]

```

If you are on an RPM based platform use the RPMs to install

```auto
wget https://cpan.metacpan.org/authors/id/M/MR/MRDVT/Power-Outlet-0.42.tar.gz
rpmbuild -ba Power-Outlet-0.42.tar.gz

```

If not use CPAN to install.

```auto
cpan 
install Power::Outlet

```

Then copy the CGI file to /vaw/www/cgi-bin/ or something like that for Apache.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [30 April 2021 09:54 UTC](https://discourse.nodered.org/t/shelly-integration-nodered/44820/21 "2021-04-30T09:54:39Z")

</div>

The REST API is well documented I seem to remember, you should be able to use native Node-RED http-request nodes to do everything if you don't want to use MQTT.

The REST API does not require a connection to Shelly Cloud.

[Next page](https://discourse.nodered.org/t/shelly-integration-nodered/44820.md?page=2)
