# Shelly Button with mqtt Nr flow

**URL:** <https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823>\
**Category:** General\
**Tags:** domoticz\
**Created:** [28 March 2024 06:17 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823 "2024-03-28T06:17:46Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dylantje](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dylantje/32/16492_2.png) [@Dylantje](https://discourse.nodered.org/u/Dylantje)\
**Post date:** [28 March 2024 06:17 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823/1 "2024-03-28T06:17:46Z")

</div>

Shelly Button.  
Wifi and mqtt.  
Would love to read it with a flow...  
I use domoticz, in combination with node red. [not a programmer:-(]

Doesn't seem that difficult,  
shellies/Shel-Button-Urinal-gen1/input\_event  
 ![ScreenShot052](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/c/8cb784990b449fa572f5d84825eb0af536930218.png)

 ![ScreenShot053](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c4b45b8cc40659a39aac6ddac7ee545e3fe8a3c5.png)

Where I need the "S" or the "L" as a command

The node output:  
code:

```auto
28-3-2024 07:06:32node: debug 594
shellies/Shel-Button-Urinal-gen1/input_event/0 : msg.payload : Object
object
event: "S"
event_cnt: 154

```

Or:

```auto
28-3-2024 07:06:51node: debug 594
shellies/Shel-Button-Urinal-gen1/input_event/0 : msg.payload : Object
object
event: "L"
event_cnt: 155

```

But I can't get the conversion from S to 1 [what Domoticz asks] right.

 ![ScreenShot055](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/d/1de178f14defd1a181daec5fd9d00608f1af2916.png)

 ![ScreenShot054](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/1/b1d9e285de4627e952c0fd2370ebc3fae460ad8c.png)

The flow:

```auto
[
    {
        "id": "2e2e6911.9a6a24",
        "type": "mqtt in",
        "z": "abbfc042b66eb59c",
        "name": "",
        "topic": "shellies/Shel-Button-Urinoir-gen1/input_event/0",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "4aaf39db27167f71",
        "nl": false,
        "rap": false,
        "inputs": 0,
        "x": 220,
        "y": 220,
        "wires": [
            [
                "2d9fa652.3e1de2",
                "931131d253083fae"
            ]
        ]
    },
    {
        "id": "2d9fa652.3e1de2",
        "type": "switch",
        "z": "abbfc042b66eb59c",
        "name": "Filter aan/uit",
        "property": "payload.event",
        "propertyType": "global",
        "rules": [
            {
                "t": "cont",
                "v": "\"S\"",
                "vt": "global"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 570,
        "y": 220,
        "wires": [
            [
                "f174a170449f7f5d",
                "5493943e93d0c59d"
            ]
        ]
    },
    {
        "id": "9ed66094.aa7cb8",
        "type": "mqtt out",
        "z": "abbfc042b66eb59c",
        "name": "",
        "topic": "domoticz/in",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "4aaf39db27167f71",
        "x": 1050,
        "y": 220,
        "wires": []
    },
    {
        "id": "931131d253083fae",
        "type": "debug",
        "z": "abbfc042b66eb59c",
        "name": "debug 593",
        "active": false,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 550,
        "y": 280,
        "wires": []
    },
    {
        "id": "f174a170449f7f5d",
        "type": "debug",
        "z": "abbfc042b66eb59c",
        "name": "debug 594",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 710,
        "y": 60,
        "wires": []
    },
    {
        "id": "5493943e93d0c59d",
        "type": "change",
        "z": "abbfc042b66eb59c",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "\"S\"",
                "fromt": "flow",
                "to": "1",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 800,
        "y": 220,
        "wires": [
            [
                "753d97f777a7e6db",
                "9ed66094.aa7cb8"
            ]
        ]
    },
    {
        "id": "753d97f777a7e6db",
        "type": "debug",
        "z": "abbfc042b66eb59c",
        "name": "debug 595",
        "active": false,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 970,
        "y": 140,
        "wires": []
    },
    {
        "id": "4aaf39db27167f71",
        "type": "mqtt-broker",
        "name": "",
        "broker": "192.168.5.70",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "verifyservercert": true,
        "protocolVersion": "3",
        "keepalive": "15",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "Domoticz",
        "birthQos": "2",
        "birthRetain": "true",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]

```

Maybe someone does O-)

---

<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:** [28 March 2024 06:45 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823/2 "2024-03-28T06:45:51Z")

</div>

Add 2 rows to the switch node to check property `payload.event`. Row 1 should have `== S` and row 2 should have `== L`. You'll see it now has 2 outputs. Connect them to 2 change nodes where you **set** payload to the required **number** value.

---

<div class="post-metadata">

**Author:** ![Dylantje](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dylantje/32/16492_2.png) [@Dylantje](https://discourse.nodered.org/u/Dylantje)\
**Post date:** [28 March 2024 15:36 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823/3 "2024-03-28T15:36:40Z")

</div>

Noob Windows here....

Not understaning what you mean.

This:

 ![ScreenShot057](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6ecd08bcb0f40b20953273e2a53115cbdee865fb.png)

And switch the S to 1 ..

 ![ScreenShot056](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/118682aee5f87c3e1b11a6ead2a23d98bd0c4dee.png)

And the set the idx [domoticz id] to on:

 ![ScreenShot058](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/4/742cf0b44f0e24e25e5070461e9ba48fa7531e2d.png)

Flow:

 ![ScreenShot059](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/71229df00a48c843e16220c11b03dbe12f11ba80.png)

Hope you can help me with that

---

<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:** [28 March 2024 20:54 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823/4 "2024-03-28T20:54:26Z")

</div>

> [@Dylantje](#):
>
> This:
> 
> ![ScreenShot057](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6ecd08bcb0f40b20953273e2a53115cbdee865fb.png)

Why are you selecting `global`? The data comes in the `msg`

Also, you need to compare to `string` `S` not global.S

> [@Dylantje](#):
>
> Hope you can help me with that

You did not follow what I said. If you had added 2 rows to the switch node, there would be 2 outputs visible.

* * *

There seems to be a fair bit you are not understanding. Perhaps some time in the docs or videos will help...

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![Dylantje](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dylantje/32/16492_2.png) [@Dylantje](https://discourse.nodered.org/u/Dylantje)\
**Post date:** [29 March 2024 08:20 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823/5 "2024-03-29T08:20:23Z")

</div>

THANKS!!!!

Make the change you says...  
Dombo here not any scripting experience. [so i do not understand why i do something]

Works very fine!!

Love

---

<div class="post-metadata">

**Author:** ![Dylantje](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dylantje/32/16492_2.png) [@Dylantje](https://discourse.nodered.org/u/Dylantje)\
**Post date:** [29 March 2024 08:31 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823/6 "2024-03-29T08:31:30Z")

</div>

Make all 4 options working:-)

 ![ScreenShot062](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/aec82699526c28a087c8ba89923926c3bfaa403a.png)

See some new item, for the fun:  
 ![ScreenShot063](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/670fef8574acde77e08a482432462c08d15c2a7c.png)

Can i use the firmware, ip, items also?

 ![ScreenShot064](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/07201a7638ae728acc2e80b410360fc06833d27c.png)

A example perhaps, how i can use that data

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [29 March 2024 09:23 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823/7 "2024-03-29T09:23:44Z")

</div>

You seem to have 4 mqtt-in nodes all subscribed to the same topic?  
This is unnecessary duplication of code.

It would be more usual to have something like this

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

There is nothing in what you have shown us to justify using global context variables like global.payload.event or global.S Get rid of them, instead use message properties and strings or you risk subtle and hard to diagnose bugs. For example this switch compares msg.payload.event with 4 different strings:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/5/35260760584d9e0a5b5bff33534fa81cd2f34590.png)

If you want to change msg.payload to 1, don't do this  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/c/0cba8878fc25be6bb1ce45c6200207347e948345.png)

Instead do this, much simpler.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/55471cb79539dccbec2216a2a667ff754a07ff52.png)

> [@Dylantje](#):
>
> Can i use the firmware, ip, items also?

The message with msg.payload.new\_fw has a different topic - shellies/Shel-Button-Urinoir-gen1/announce.  
Therefore you need to change your mqtt-in node to subscribe with a wildcard  
`shellies/Shel-Button-Urinoir-gen1/#`  
will receive both `shellies/Shel-Button-Urinoir-gen1/input_event/0` and `shellies/Shel-Button-Urinoir-gen1/announce` messages (and possibly others too)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a4eb153e6b582d18d388d3fec295eb875f90fbb7.png)

---

<div class="post-metadata">

**Author:** ![Dylantje](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dylantje/32/16492_2.png) [@Dylantje](https://discourse.nodered.org/u/Dylantje)\
**Post date:** [29 March 2024 10:41 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823/8 "2024-03-29T10:41:37Z")

</div>

> [@jbudd](#):
>
> shellies/Shel-Button-Urinoir-gen1/#

1 step for 1 step 🙂  
See some more items..  
Only not the firmware

 ![ScreenShot065](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/1/21358444da7894d9f20fecb54c5819c442dd7582.png)  
Or the wifi etc..

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [29 March 2024 10:55 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823/9 "2024-03-29T10:55:58Z")

</div>

> [@Dylantje](#):
>
> Only not the firmware

As far as I can see, subscribing to this topic  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/9/c90322b3a9aaaebfb69329a82bf0183721b05d71.png)

**will** capture messages whose topic is  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/6/d6ee0b6ffaafb2187c74c33c804815f2e3510c25.png)

---

<div class="post-metadata">

**Author:** ![Dylantje](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dylantje/32/16492_2.png) [@Dylantje](https://discourse.nodered.org/u/Dylantje)\
**Post date:** [29 March 2024 11:50 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823/10 "2024-03-29T11:50:01Z")

</div>

Yes with announce, only not with the wildcard.

And with annaounce i cannot get the topic.

 ![ScreenShot066](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/9551f5a2d1cff11e2b901cdf36de415a9ba24601.png)

wildcard:

 ![ScreenShot067](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/c/bc012360fa65f5137d47d21f12ecf11745336a7f.png)

Dombo here sorry..

---

<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:** [29 March 2024 12:55 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823/11 "2024-03-29T12:55:44Z")

</div>

I may be wrong. but isn't the announce message sent only when the device connects to the broker. So you would only get one message until the device(shelly) reconnects.

> Availability and announces

Since v1.4.3: [on MQTT connect](https://shelly-api-docs.shelly.cloud/gen1/#availability-and-announces), Shellies will publish:

- an announce message on `shellies/announce` and, since v1.6.0, on `shellies/<shellymodel>-<deviceid>/announce`. The message is JSON-formatted and contains a list of attributes: `id`, `mode` (if applicable), `model`, `mac`, `ip`, `new_fw` (`true` when an update is available), `fw_ver` (contains the current firmware version);
- availability message on `shellies/<shellymodel>-<deviceid>/online` with payload `true`;
- complete current state. This is device specific and is described in detail for each device below.

---

<div class="post-metadata">

**Author:** ![Dylantje](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dylantje/32/16492_2.png) [@Dylantje](https://discourse.nodered.org/u/Dylantje)\
**Post date:** [30 March 2024 13:41 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823/12 "2024-03-30T13:41:10Z")

</div>

I now the device only connect the broker when push the button.

The other things yoy sy i do not understand..

Is there a way to use this messages or not?

---

<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:** [28 June 2024 13:41 UTC](https://discourse.nodered.org/t/shelly-button-with-mqtt-nr-flow/86823/13 "2024-06-28T13:41:46Z")

</div>

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