Shelly Button with mqtt Nr flow

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

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

The node output:
code:

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:

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.

The flow:

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

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.

Noob Windows here....

Not understaning what you mean.

This:

And switch the S to 1 ..

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

Flow:

Hope you can help me with that

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

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

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

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

Make all 4 options working:-)

See some new item, for the fun:
ScreenShot063

Can i use the firmware, ip, items also?

A example perhaps, how i can use that data

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

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:

If you want to change msg.payload to 1, don't do this
image

Instead do this, much simpler.
image

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)

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


Or the wifi etc..

As far as I can see, subscribing to this topic
image

will capture messages whose topic is
image

Yes with announce, only not with the wildcard.

And with annaounce i cannot get the topic.

wildcard:

Dombo here sorry..

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

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?

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