Need help for a dynamic msg

Hi, I'm absolutely inexperienced with nodered, I use it as a beginner and I don't know either the modules or the language well.
I need to create a task in which, given a certain situation (the door opens), I would like Alexa to tell me if there are open shutters and possibly which ones.
My problem is that I managed to obtain the list of shutters that do not have position 0 (closed), now I should convert the output into a message to pass to Alexa composed like this:

"Attention, there are open shutters:" + variable1 + variable2 + variable3 + variable4

Where each variable represents the name of the room, and must be pronounced only if it is actually in the list of rooms with open shutters.

at the moment what I get from the job I tried to do is an output similar to this (room3 have closed shutter in this sample):

11/9/2023, 17:50:13node: debug 2
shelly.0.SHSW-2150#1.Shutter.Position : msg.payload : string[5]
"room1"

11/9/2023, 17:50:13node: debug 2
shelly.0.SHSW-2122#1.Shutter.Position : msg.payload : string[5]
"room2"

11/9/2023, 17:50:13node: debug 2
shelly.0.SHSW-210E#1.Shutter.Position : msg.payload : string[5]
"room4"

but it is likely that he did things that were not correct

This is a screenshot of node:

Hi
first you need to export your flow so we can see how the nodes are configured

How to import/export a flow

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

Then we need to see the data your shelly nodes are providing, add debugs after them and copy values.

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path or value 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

With this data forum members here will be able to help you with greater ease.

[
    {
        "id": "4cb4571451dafbb1",
        "type": "tab",
        "label": "Flow 4",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "05f7124adc9a7138",
        "type": "ioBroker get",
        "z": "4cb4571451dafbb1",
        "name": "% room1 curtain",
        "topic": "shelly.0.SHSW-21#32B250#1.Shutter.Position",
        "attrname": "payload",
        "payloadType": "value",
        "errOnInvalidState": "nothing",
        "x": 670,
        "y": 380,
        "wires": [
            [
                "eccd31ab15e6172c"
            ]
        ]
    },
    {
        "id": "7d899a2b688bb713",
        "type": "ioBroker get",
        "z": "4cb4571451dafbb1",
        "name": "% room2 curtain",
        "topic": "shelly.0.SHSW-21#32B922#1.Shutter.Position",
        "attrname": "payload",
        "payloadType": "value",
        "errOnInvalidState": "nothing",
        "x": 670,
        "y": 440,
        "wires": [
            [
                "9315c71444c3bbdc"
            ]
        ]
    },
    {
        "id": "6e095940d0d2cf63",
        "type": "ioBroker get",
        "z": "4cb4571451dafbb1",
        "name": "% room3 curtain",
        "topic": "shelly.0.SHSW-21#32BA8B#1.Shutter.Position",
        "attrname": "payload",
        "payloadType": "value",
        "errOnInvalidState": "nothing",
        "x": 670,
        "y": 500,
        "wires": [
            [
                "f664fefa9e3229d9"
            ]
        ]
    },
    {
        "id": "5ea6d5869d3ed44f",
        "type": "ioBroker get",
        "z": "4cb4571451dafbb1",
        "name": "% room4 curtain",
        "topic": "shelly.0.SHSW-21#55A50E#1.Shutter.Position",
        "attrname": "payload",
        "payloadType": "value",
        "errOnInvalidState": "nothing",
        "x": 670,
        "y": 560,
        "wires": [
            [
                "529055a22b4a154b"
            ]
        ]
    },
    {
        "id": "d08251f34c88fc87",
        "type": "ioBroker in",
        "z": "4cb4571451dafbb1",
        "name": "alert door open",
        "topic": "broadlink2.0._SendScene",
        "payloadType": "value",
        "onlyack": "",
        "func": "all",
        "gap": "",
        "x": 240,
        "y": 460,
        "wires": [
            [
                "9fa2ec0adc9dee36"
            ]
        ]
    },
    {
        "id": "9fa2ec0adc9dee36",
        "type": "switch",
        "z": "4cb4571451dafbb1",
        "name": "if door open",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "open",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 410,
        "y": 460,
        "wires": [
            [
                "05f7124adc9a7138",
                "7d899a2b688bb713",
                "6e095940d0d2cf63",
                "5ea6d5869d3ed44f"
            ]
        ]
    },
    {
        "id": "ba3627c89d0b866d",
        "type": "ioBroker out",
        "z": "4cb4571451dafbb1",
        "name": "announcement",
        "topic": "alexa2.0.Echo-Devices.3be5eb6a7a97442484dad5d0fa3e6e03.Commands.announcement",
        "ack": "false",
        "autoCreate": "false",
        "stateName": "",
        "role": "",
        "stateUnit": "",
        "stateMin": "",
        "stateMax": "",
        "x": 1500,
        "y": 480,
        "wires": []
    },
    {
        "id": "7a402309b03d9bad",
        "type": "change",
        "z": "4cb4571451dafbb1",
        "name": "room1",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "room1",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1090,
        "y": 380,
        "wires": [
            [
                "936306b944ff65d4"
            ]
        ]
    },
    {
        "id": "edc442b2283c8fe3",
        "type": "change",
        "z": "4cb4571451dafbb1",
        "name": "room2",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "room2",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1090,
        "y": 440,
        "wires": [
            [
                "936306b944ff65d4"
            ]
        ]
    },
    {
        "id": "30fcb12a95cff894",
        "type": "change",
        "z": "4cb4571451dafbb1",
        "name": "room3",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "room3",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1090,
        "y": 500,
        "wires": [
            [
                "936306b944ff65d4"
            ]
        ]
    },
    {
        "id": "082f56d8088ba762",
        "type": "change",
        "z": "4cb4571451dafbb1",
        "name": "room4",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "room4",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1090,
        "y": 560,
        "wires": [
            [
                "936306b944ff65d4"
            ]
        ]
    },
    {
        "id": "23105f13ad110543",
        "type": "inject",
        "z": "4cb4571451dafbb1",
        "name": "start",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "open",
        "payloadType": "str",
        "x": 230,
        "y": 380,
        "wires": [
            [
                "9fa2ec0adc9dee36"
            ]
        ]
    },
    {
        "id": "936306b944ff65d4",
        "type": "debug",
        "z": "4cb4571451dafbb1",
        "name": "debug 2",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1480,
        "y": 420,
        "wires": []
    },
    {
        "id": "eccd31ab15e6172c",
        "type": "switch",
        "z": "4cb4571451dafbb1",
        "name": "if !=0 ",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "neq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 850,
        "y": 380,
        "wires": [
            [
                "7a402309b03d9bad"
            ]
        ]
    },
    {
        "id": "9315c71444c3bbdc",
        "type": "switch",
        "z": "4cb4571451dafbb1",
        "name": "if !=0 ",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "neq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 850,
        "y": 440,
        "wires": [
            [
                "edc442b2283c8fe3"
            ]
        ]
    },
    {
        "id": "f664fefa9e3229d9",
        "type": "switch",
        "z": "4cb4571451dafbb1",
        "name": "if !=0 ",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "neq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 850,
        "y": 500,
        "wires": [
            [
                "30fcb12a95cff894"
            ]
        ]
    },
    {
        "id": "529055a22b4a154b",
        "type": "switch",
        "z": "4cb4571451dafbb1",
        "name": "if !=0 ",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "neq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 850,
        "y": 560,
        "wires": [
            [
                "082f56d8088ba762"
            ]
        ]
    }
]

Now we can see the nodes, we need the debug values the ibroker nodes are outputting ( From image before i called them shelly nodes, as i did not have the flow you just posted). Add debugs and copy values, as described in above post above.

I have posted the debug in the first post!

11/9/2023, 18:35:34[node: debug 2](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)shelly.0.SHSW-21#32B250#1.Shutter.Position : msg.payload : string[5]

"room1"

11/9/2023, 18:35:34[node: debug 2](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)shelly.0.SHSW-21#32B922#1.Shutter.Position : msg.payload : string[5]

"room2"

11/9/2023, 18:35:34[node: debug 2](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)shelly.0.SHSW-21#55A50E#1.Shutter.Position : msg.payload : string[5]

"room4"

NO, the ibroker nodes not the change node outputs. Again please use the copy value button described above. The copy value wil provide the data in a format that can be copied and pasted easily.

I do not have Ibroker installed, to help we need the outputs. Then we can provide a demo.

Sorry but I don't understand!..
I have no errors, I'm here to ask for a solution in a problem that I have described, I need a way to solve a general problem.
The only output on debug (all flow) is the once I have posted, the value of the Shellys can be from 0 to 100, I get only values >0 that means "is open", and in my sample I have changed that value in something other "room1", "room2"...and so on.

The problem is:
that I have 4 rooms that may have the shutters open; to verify that they are open I captured the position given by the installed Shellys.
Starting from this data I would need an output to feed to Alexa that describes the situation if some shutters are open, so if, as in the example, 3 rooms are open I would need it to tell me:
"Attention, the shutters in the rooms are open: room1, room2, room4"

That's all...

I have posted in first post how to copy a value from a debug.

If you can not provide the message values coming out of the ibroker nodes, i can not provide a demo/solution that will create a dynamic message.

I suggest to read the links provide and supply the information request. or wait for a user using Ibroker to respond.
I fully understand what you would like to do, but i need info to help you.

I know how to copy values but this is the only debug output I have from the task that I've post

Add debugs to each ibroker node. We need info in text format. I hope you don't think i should type it all out when you can provide it in a easy to copy format. help me help you.

11/9/2023, 19:09:56[node: debug start 1](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)msg.payload : string[4]

"open"

11/9/2023, 19:09:56[node: debug if door is open](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)msg.payload : string[4]

"open"

11/9/2023, 19:09:56[node: debug % rooms](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)shelly.0.SHSW-21#32B250#1.Shutter.Position : msg.payload : number

100

11/9/2023, 19:09:56[node: debug % rooms](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)shelly.0.SHSW-21#32B922#1.Shutter.Position : msg.payload : number

100

11/9/2023, 19:09:56[node: debug if !=0](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)shelly.0.SHSW-21#32B250#1.Shutter.Position : msg.payload : number

100

11/9/2023, 19:09:56[node: debug if !=0](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)shelly.0.SHSW-21#32B922#1.Shutter.Position : msg.payload : number

100

11/9/2023, 19:09:56[node: debug 3](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)shelly.0.SHSW-21#32B250#1.Shutter.Position : msg.payload : string[5]

"room1"

11/9/2023, 19:09:56[node: debug 3](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)shelly.0.SHSW-21#32B922#1.Shutter.Position : msg.payload : string[5]

"room2"

11/9/2023, 19:09:56[node: debug % rooms](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)shelly.0.SHSW-21#32BA8B#1.Shutter.Position : msg.payload : number

0

11/9/2023, 19:09:56[node: debug % rooms](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)shelly.0.SHSW-21#55A50E#1.Shutter.Position : msg.payload : number

100

11/9/2023, 19:09:57[node: debug if !=0](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)shelly.0.SHSW-21#55A50E#1.Shutter.Position : msg.payload : number

100

11/9/2023, 19:09:57[node: debug 3](http://192.168.2.8:1880/?instance=0&newReact=true&0&react=colored#)shelly.0.SHSW-21#55A50E#1.Shutter.Position : msg.payload : string[5]

"room4"

there are 4 data...
the first "open" activates the reading step of the shelly position.
The shellys respond with a value of 100 for 3 of the 4 questioned and one responds with 0
the "if task" locks those at 0.
Then I change the payload value to "room1" or "room2" or "room3" or "room4"

if there were complex values I could understand but they are 4 lines... and I still haven't understood if there is a way to create a compound message.
A generic example would be enough for me

use the task function and write the code like this: "...."

I posted my task to better understand the process I had in mind, but in the end it would be enough for me to know how I can create a payload.msg composed of a text string and the output of 4 nodes that can report the name of a room.
Unfortunately, as I wrote, I'm not an expert and I'm not sure if my flow is suitable for the purpose, which is why I was asking for advice.

Therefore, starting from 4 sensors that can report values from 0 to 100, I would like a warning, a payload.msg to be clear, which is made up of a text string and the names of the rooms in which the number is greater than 0.

Any help is precious and I still thank you for any support, I'm sorry if I don't respond well to any requests but this may be due to the fact that I don't know the processes well.

I also have another problem, from my task I can get a generic non-compound sentence to be pronounced (be careful, there are open shutters), but this is repeated for each output present, so if I have three rooms with open shutters Alexa gives me the announcement 3 times...

You did not use the copy value button described in first post

Please help others help you, If you provide requested data in correct format it is a simple copy and paste to use your data. In the format you provided it is not easy. Why make our lifes harder, we volunteer our time, it is only fair that you try not to make life harder.

I can see from your post that the output is a number 0 - 100. I have knocked up an example.

[{"id":"74b4876ff34778ec","type":"ioBroker get","z":"4cb4571451dafbb1","name":"% room1 curtain","topic":"shelly.0.SHSW-21#32B250#1.Shutter.Position","attrname":"payload","payloadType":"value","errOnInvalidState":"nothing","x":650,"y":380,"wires":[["7a402309b03d9bad"]]},{"id":"288bbb856931f013","type":"switch","z":"4cb4571451dafbb1","name":"if door open","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"open","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":460,"wires":[["74b4876ff34778ec","e79074233838b2e3","8a8eda11111da889","280eddfbaed673f3"]]},{"id":"7a402309b03d9bad","type":"change","z":"4cb4571451dafbb1","name":"room1","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.value","tot":"msg"},{"t":"set","p":"payload.topic","pt":"msg","to":"room1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":380,"wires":[["167e171e8227322b"]]},{"id":"598df7db39b3b148","type":"ioBroker in","z":"4cb4571451dafbb1","name":"alert door open","topic":"broadlink2.0._SendScene","payloadType":"value","onlyack":"","func":"all","gap":"","x":150,"y":460,"wires":[["288bbb856931f013"]]},{"id":"f1ba609f742e4fa2","type":"inject","z":"4cb4571451dafbb1","name":"start","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"open","payloadType":"str","x":210,"y":380,"wires":[["288bbb856931f013"]]},{"id":"e79074233838b2e3","type":"ioBroker get","z":"4cb4571451dafbb1","name":"% room2 curtain","topic":"shelly.0.SHSW-21#32B922#1.Shutter.Position","attrname":"payload","payloadType":"value","errOnInvalidState":"nothing","x":650,"y":440,"wires":[["80ee262a9caa0826"]]},{"id":"8a8eda11111da889","type":"ioBroker get","z":"4cb4571451dafbb1","name":"% room3 curtain","topic":"shelly.0.SHSW-21#32BA8B#1.Shutter.Position","attrname":"payload","payloadType":"value","errOnInvalidState":"nothing","x":650,"y":500,"wires":[["29db024395cff0eb"]]},{"id":"280eddfbaed673f3","type":"ioBroker get","z":"4cb4571451dafbb1","name":"% room4 curtain","topic":"shelly.0.SHSW-21#55A50E#1.Shutter.Position","attrname":"payload","payloadType":"value","errOnInvalidState":"nothing","x":650,"y":560,"wires":[["e71079455c37993f"]]},{"id":"bce8102ef97b16cd","type":"inject","z":"4cb4571451dafbb1","name":"testing","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":730,"y":300,"wires":[["7a402309b03d9bad","80ee262a9caa0826","29db024395cff0eb"]]},{"id":"167e171e8227322b","type":"join","z":"4cb4571451dafbb1","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"payload.topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1030,"y":460,"wires":[["7a57cda7762dc021"]]},{"id":"80ee262a9caa0826","type":"change","z":"4cb4571451dafbb1","name":"room2","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.value","tot":"msg"},{"t":"set","p":"payload.topic","pt":"msg","to":"room2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":440,"wires":[["167e171e8227322b"]]},{"id":"29db024395cff0eb","type":"change","z":"4cb4571451dafbb1","name":"room3","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.value","tot":"msg"},{"t":"set","p":"payload.topic","pt":"msg","to":"room3","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":500,"wires":[["167e171e8227322b"]]},{"id":"e71079455c37993f","type":"change","z":"4cb4571451dafbb1","name":"room1","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.value","tot":"msg"},{"t":"set","p":"payload.topic","pt":"msg","to":"room4","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":560,"wires":[["167e171e8227322b"]]},{"id":"7a57cda7762dc021","type":"change","z":"4cb4571451dafbb1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"\"Attention, the shutters in the rooms are open: \" & $join($$.payload.*[$.value = 0]^($.topic).topic, \", \")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":460,"wires":[["7098caa8d5372934"]]},{"id":"f0cf720e08f421f0","type":"inject","z":"4cb4571451dafbb1","name":"testing ","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":710,"y":340,"wires":[["e71079455c37993f"]]},{"id":"7098caa8d5372934","type":"debug","z":"4cb4571451dafbb1","name":"debug 334","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1250,"y":360,"wires":[]}]

The example joins the messages into one message, then uses JSONata to output messages with value of 0, it also sorts the rooms alphbetically just incase.

output

The flow should work fine on your node-red. On mine i added test inputs, as you can see i do not have ibroker installed.

thanks for now! the message is exactly as I would like it except that I see that it is repeated n times, I would have to figure out how to take just one to prevent Alexa from repeating it N times.
the copy value tool would only report 100 or 0, there are no fields like in your example, that's why I posted a screen of the initial debug.
Not all the structure appears but only that data.

It is only repeated once, every time input says door is opened. I tested it n times to make sure sorting was working.

Yes i wanted to see the 0 -100 to confirm the data was a string or number, again please in future respond to all requests, so we can help you with the least effort.

Thanks again....and sorry if I wasn't precise, in the future I will try to be more attentive, hoping to understand the requests.

As you are new take some time and view the essentials videos
They will help you better understand the basic concepts.

thanks, I started watching several videos, now I will follow others too, unfortunately in some cases the limits are linked to the knowledge of the scripts (expression).
I imagined there was a code but I didn't know what it could do and how to get to feed it in the right way.
I would never have been able to solve it without your help, I would have to learn a lot and unfortunately I can only dedicate myself to it when I have something to set up like in this case...

$join($$.payload.*[$.value = 0]^($.topic).topic, ", ")

$$.payload.* returns an array the values of the object msg.payload.
[$.value = 0] filters the array for only elements where the value is 0.
^($.topic) sorts the array into alphabetic order using the msg.payload.topic.
.topic returns the msg.payload.topic values from the array of objects.
$join(... , ", ") joins the topics, e.g room1, room2 etc toogether using , as the joint.
You are always free to ask, but remember to give relevant info and respond to requests
There are no silly questions when learning.

1 Like

UAO...again top help!

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