# Shelly Gen2 MQTT Help

**URL:** https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024
**Category:** General
**Created:** [31 October 2021 19:41 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024 "2021-10-31T19:41:37Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![CTRDevelopments](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ctrdevelopments/32/50298_2.png) [@CTRDevelopments](https://discourse.nodered.org/u/CTRDevelopments)
#### Post date: [31 October 2021 19:41 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/1 "2021-10-31T19:41:37Z")

</div>

Hi, I am fairly new to Node Red but have managed to configure a number of Shelly Gen1 Devices to control lighting. I now have a Gen2 device and the MQTT structure is entirly different and I am a bit stuck.

I have my input MQTT subscribed to the topic shellyplus1-a8032abd78a0/events/rpc which seems to work as I can see items appearing in the debug window when I press the switch connected to the shelly. However when I run the below flow it doesnt do anything so there must be somethign wrong with my logic

Any help would be greatly appreciated

cheers

```auto
[{"id":"3b526e4b9eaed659","type":"tab","label":"Master Bedroom","disabled":false,"info":""},{"id":"8b6ebd648cdf2ca2","type":"node-lifx-in","z":"3b526e4b9eaed659","server":"396bbcdbf33a4c89","name":"Master Bedroom LifX","lightID":"d073d52d2bb8","x":680,"y":280,"wires":[]},{"id":"2e9c027016b6159e","type":"mqtt in","z":"3b526e4b9eaed659","name":"Input status","topic":"shellyplus1-a8032abd78a0/events/rpc","qos":"2","datatype":"json","broker":"2fd5bebaac766e96","nl":false,"rap":false,"x":130,"y":280,"wires":[["169b43a126bb7e7f"]]},{"id":"d1372af601a04d86","type":"comment","z":"3b526e4b9eaed659","name":"mqtt","info":"","x":110,"y":190,"wires":[]},{"id":"faf0c79fa1570f2a","type":"function","z":"3b526e4b9eaed659","name":"","func":"const Switch = msg.payload.params[\"input:0\"].State\n\nif (Switch =='true')\n{\n msg.payload=true \n}\n if (Switch =='false')\n{\n msg.payload=false \n}\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":280,"wires":[["8b6ebd648cdf2ca2","450888c621532251"]]},{"id":"775b4629a399ca07","type":"comment","z":"3b526e4b9eaed659","name":"Description","info":"uses mqtt from Shelly switch to command the LifX bulb","x":1090,"y":200,"wires":[]},{"id":"169b43a126bb7e7f","type":"rbe","z":"3b526e4b9eaed659","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":310,"y":280,"wires":[["faf0c79fa1570f2a"]]},{"id":"a5937025617e9404","type":"function","z":"3b526e4b9eaed659","name":"","func":"if(msg.payload.params[\"input:0\"].state==true)\n{\n msg.payload=true\n}\n\nif(msg.payload.params[\"input:0\"].state==false)\n{\n msg.payload=false\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":200,"wires":[[]]},{"id":"450888c621532251","type":"debug","z":"3b526e4b9eaed659","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":400,"wires":[]},{"id":"396bbcdbf33a4c89","type":"node-lifx-server","name":"Lifx Server","address":"","broadcast":"","lights":"","interval":"10000"},{"id":"2fd5bebaac766e96","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/2/e2dbb361e534321806a300f7cb9f2573a2148158.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a90a6d5bb72be3e0d2e03534b61959eef99f35f1.png)

---

<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: [31 October 2021 21:00 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/2 "2021-10-31T21:00:31Z")

</div>

I see that you have a node in your flow that isn't installed in a 'stock' node-RED install (Master BedroomLifX ??), which means that anyone loading your flow to try and help you, would need to install that node in their own system. You would be more likely to get support if you didn't include that node in your exported flow.

When you "see items appearing in the debug window", is that originating from the debug node in your flow above? and if so please show us what the message is.  
Also, what did you expect the message to be?

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [31 October 2021 21:24 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/3 "2021-10-31T21:24:32Z")

</div>

Add a `debug ` node to the output of the `filter` node so you can see what the data is you are testing.

Then ask yourself “What if the value I’m testing is a string true or false and not a Boolean? Or what if it isn’t true or false?”

---

<div class="post-metadata">

### Author: ![CTRDevelopments](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ctrdevelopments/32/50298_2.png) [@CTRDevelopments](https://discourse.nodered.org/u/CTRDevelopments)
#### Post date: [1 November 2021 07:33 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/4 "2021-11-01T07:33:17Z")

</div>

If I move the debug node to the filter output

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/19b1c5a2cbb90b633ea3a7afecad6b66231d410e.png)

I am getting this output

```auto
{"src":"shellyplus1-a8032abd78a0","dst":"shellyplus1-a8032abd78a0/events","method":"NotifyStatus","params":{"ts":1635751127.78,"input:0":{"id":0,"state":false}}}

```

The variable that changes state is the "input:0" state

The input to the LifX node needs to be true or false (true for on, and false for off)

I am trying to output to the Lifx node a value of true when the "input:0" state is 1 and an output of false when the "input:0" state is 0

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [1 November 2021 09:11 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/5 "2021-11-01T09:11:31Z")

</div>

The code will in the function node will be complicated by the fact that the property name `input:0` has a special character in it. However there’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<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: [1 November 2021 10:00 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/6 "2021-11-01T10:00:10Z")

</div>

Got to say @CTRDevelopments, that the [Shelly Gen 2 api guide](https://shelly-api-docs.shelly.cloud/gen2/Components/SystemComponents/Mqtt) is not easy reading...

---

<div class="post-metadata">

### Author: ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)
#### Post date: [1 November 2021 10:03 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/7 "2021-11-01T10:03:10Z")

</div>

this is how I receive MQTT from a shelly 4 pro pm

```auto
[{"id":"18f1c280a57f5b40","type":"mqtt in","z":"9120cee1.edcfb","name":"","topic":"shellypro4pm-94b97ec035e8/status/switch:0","qos":"0","datatype":"auto","broker":"36a1d46c.15334c","nl":false,"rap":true,"rh":0,"x":270,"y":420,"wires":[["bcfe805d6c325d7c","84528b3260458079","fb76b1a3aee80f68"]]},{"id":"15c0f7bcb90abf85","type":"mqtt in","z":"9120cee1.edcfb","name":"","topic":"shellypro4pm-94b97ec035e8/status/switch:1","qos":"0","datatype":"auto","broker":"36a1d46c.15334c","nl":false,"rap":true,"rh":0,"x":270,"y":460,"wires":[["0d73ddc899de87a2","b46cc81da1f5e519","b669dadb9fe424a2"]]},{"id":"9bc05a2f74729ffd","type":"mqtt in","z":"9120cee1.edcfb","name":"","topic":"shellypro4pm-94b97ec035e8/status/switch:2","qos":"0","datatype":"auto","broker":"36a1d46c.15334c","nl":false,"rap":true,"rh":0,"x":270,"y":500,"wires":[["d436f4f1ae97a4d1","284ea4c77de8fe10","42b53ff7a3f872b6"]]},{"id":"b66b34da6865a753","type":"mqtt in","z":"9120cee1.edcfb","name":"","topic":"shellypro4pm-94b97ec035e8/status/switch:3","qos":"0","datatype":"auto","broker":"36a1d46c.15334c","nl":false,"rap":true,"rh":0,"x":270,"y":540,"wires":[["0c86e5d8a6f509f2","54428b441d310b6a","c88f4b0e31682834","66d61fcde98a446f"]]},{"id":"36a1d46c.15334c","type":"mqtt-broker","broker":"10.0.0.43","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

 ![shelly MQTT](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/df498551d8363c90396461a40a62fc30a41cc7ce.jpeg)

---

<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: [1 November 2021 10:03 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/8 "2021-11-01T10:03:12Z")

</div>

input:0 is already ture/false according to you debug output.

---

<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: [1 November 2021 10:10 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/9 "2021-11-01T10:10:10Z")

</div>

Isn't it the 'output' value that is required?

---

<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: [1 November 2021 10:12 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/10 "2021-11-01T10:12:28Z")

</div>

There is no "output" in the mqtt payload  
Just a matter of moving `input:0.state` to msg.payload.

---

<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: [1 November 2021 10:15 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/11 "2021-11-01T10:15:26Z")

</div>

It's not shown in the posts above, but as far as I can recall reading a while ago, there should be - `output: true` that shows the state of the relay.

---

<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: [1 November 2021 10:16 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/12 "2021-11-01T10:16:25Z")

</div>

> [@CTRDevelopments](#):
>
> I am getting this output
> 
> ```auto
> {"src":"shellyplus1-a8032abd78a0","dst":"shellyplus1-a8032abd78a0/events","method":"NotifyStatus","params":{"ts":1635751127.78,"input:0":{"id":0,"state":false}}}
> 
> ```

@Paul-Reed shown here from debug output.

---

<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: [1 November 2021 10:17 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/13 "2021-11-01T10:17:53Z")

</div>

Yes, I'm aware of that.

---

<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: [1 November 2021 10:19 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/14 "2021-11-01T10:19:15Z")

</div>

> [@Paul-Reed](#):
>
> It's not shown in the posts above

Thought not as you said, crossed wires.

@CTRDevelopments

```auto
[{"id":"2f3857b0.d52508","type":"mqtt in","z":"b779de97.b1b46","name":"","topic":"+/events","qos":"2","datatype":"auto","broker":"d675b749.04b9c8","x":100,"y":4840,"wires":[["15a091a2.300d5e"]]},{"id":"15a091a2.300d5e","type":"change","z":"b779de97.b1b46","name":"","rules":[{"t":"set","p":"device","pt":"msg","to":"payload.src","tot":"msg"},{"t":"move","p":"payload.params[\"input:0\"].state","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":4840,"wires":[["79ad3f9a.085908"]]},{"id":"79ad3f9a.085908","type":"switch","z":"b779de97.b1b46","name":"","property":"device","propertyType":"msg","rules":[{"t":"eq","v":"shellyplus1-a8032abd78a0","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":500,"y":4840,"wires":[["4678db9d.b6641c"]]},{"id":"e039615d.30aa9","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"shellyplus1-a8032abd78a0/events","payload":"{\"src\":\"shellyplus1-a8032abd78a0\",\"dst\":\"shellyplus1-a8032abd78a0/events\",\"method\":\"NotifyStatus\",\"params\":{\"ts\":1635751127.78,\"input:0\":{\"id\":0,\"state\":false}}}","payloadType":"json","x":130,"y":4900,"wires":[["15a091a2.300d5e"]]},{"id":"4678db9d.b6641c","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":690,"y":4880,"wires":[]},{"id":"d675b749.04b9c8","type":"mqtt-broker","name":"Localhost","broker":"localhost","port":"1883","clientid":"","usetls":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<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: [1 November 2021 10:44 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/15 "2021-11-01T10:44:26Z")

</div>

@juntiedt Could you post the MQTT output message from **your** Shelly please, so we can see the expected format.

---

<div class="post-metadata">

### Author: ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)
#### Post date: [1 November 2021 10:46 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/16 "2021-11-01T10:46:19Z")

</div>

{"id": 3, "source": "HTTP", "output": false, "apower": 0.000, "voltage": 232.168,"aenergy": {"total":47.131,"by\_minute":[0.000,0.000,0.000],"minute\_ts":1635763499},"temperature":{"tC":null, "tF":null}}

EDIT by moderator (for easier reading...)

```auto
{
   "id":3,
   "source":"HTTP",
   "output":false,
   "apower":0.000,
   "voltage":232.168,
   "aenergy":{
      "total":47.131,
      "by_minute":[
         0.000,
         0.000,
         0.000
      ],
      "minute_ts":1635763499
   },
   "temperature":{
      "tC":null,
      "tF":null
   }
}

```

---

<div class="post-metadata">

### Author: ![juntiedt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/juntiedt/32/58357_2.png) [@juntiedt](https://discourse.nodered.org/u/juntiedt)
#### Post date: [1 November 2021 10:54 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/17 "2021-11-01T10:54:43Z")

</div>

this is the MQTT output of switch 3 of a shelly 4pro pm.  
it gives you:

on off status  
apower in Watt  
voltage in Volt  
energy used and  
internal temp of the switch (in this case switch 3)

---

<div class="post-metadata">

### Author: ![CTRDevelopments](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ctrdevelopments/32/50298_2.png) [@CTRDevelopments](https://discourse.nodered.org/u/CTRDevelopments)
#### Post date: [1 November 2021 11:10 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/18 "2021-11-01T11:10:59Z")

</div>

I am not too worried about the relay state, as I set that to always be on. That way the bulb is always powered and ready. It's the input switch state that I want to know. Although I assume it's a similar problem to solve? Cheers

---

<div class="post-metadata">

### Author: ![CTRDevelopments](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ctrdevelopments/32/50298_2.png) [@CTRDevelopments](https://discourse.nodered.org/u/CTRDevelopments)
#### Post date: [1 November 2021 11:12 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/19 "2021-11-01T11:12:33Z")

</div>

> [@E1cid](#):
>
> There is no "output" in the mqtt payload  
> Just a matter of moving `input:0.state` to msg.payload.

This is probably a better way of describing my issue

---

<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: [1 November 2021 11:15 UTC](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024/20 "2021-11-01T11:15:12Z")

</div>

> [@CTRDevelopments](#):
>
> I am not too worried about the relay state, as I set that to always be on.

Now I'm confused... why are you using a shelly to control a light if it's never switched off?

[Next page](https://discourse.nodered.org/t/shelly-gen2-mqtt-help/53024.md?page=2)
