Bring your HA shopping list into nodered. Then use it for text or tts messages. Updated

Thanks to @Kermit for the endpoint, I can give you an example how to import your current shopping list from HA using the api node.

The api returns an array. This includes items that are both complete and incomplete.

Screenshot 2024-02-16 041611

In this state it is still a little to hard to deal with using the standard switch method. I’m including a function node to separate incomplete from complete and return a string that can be used for either texts or tts.

It will return 2 strings:

"You have x item/s in your list"

and

"You need x y and z" or "x is the only item on your list"

Flow:

[{"id":"9e3950c4e560b244","type":"api-call-service","z":"60f2d2277843c698","name":"","server":"","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_pixel_7","areaId":[],"deviceId":[],"entityId":[],"data":"{\t   \"message\": payload.message,\t   \"title\": payload.title,\t   \"data\":{\t        \"clickAction\": \"shopping-list/0\",\t        \"color\": \"#ffff00\"\t    }\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":730,"y":1080,"wires":[[]]},{"id":"65ab3989ad0bbc0b","type":"ha-api","z":"60f2d2277843c698","name":"","server":"","version":1,"debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\"type\": \"shopping_list/items\"}","dataType":"jsonata","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":350,"y":1080,"wires":[["521d0a7fedef4200","fae1eb5e8d2a1c59"]]},{"id":"7f7ba9d75df5a7fb","type":"inject","z":"60f2d2277843c698","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":1080,"wires":[["65ab3989ad0bbc0b"]]},{"id":"521d0a7fedef4200","type":"function","z":"60f2d2277843c698","name":"function 5","func":"// save payload\nlet sList = msg.payload;\n// isolate incomplete\nlet fList = sList.filter(x => x.complete === false);\n// isolate name value\nlet items = fList.map(a => a.name);\n// number of items in array\nlet tCount = items.length;\n\n\nif (tCount == 1){\n    // item to string\n    let only = (items.toString()).toLowerCase();\n    // capitalize first letter\n    let capitalized =\n        only.charAt(0).toUpperCase()\n        + only.slice(1);\n    // create 1 item message\n    msg.payload = {\n        \"title\": \"You have 1 item on your list.\",\n        \"message\": capitalized + \" is the only item on your list.\"\n    };\n} else if (tCount > 1) {\n    // seperate last item\n    let last = items.pop();\n    // remaining items to string and remove ,\n    let sItems = (items.toString()).replace(/,/g, \" \");\n    // create multi item message\n    msg.payload = {\n        \"title\": \"You have \" + tCount + \" items on your list.\",\n        \"message\": \"You need \" + sItems + \" and \" + last + \".\"\n    };\n} else {\n    msg.payload = null;\n};\n\n\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":1080,"wires":[["9e3950c4e560b244"]]}]

You can use an API node and hit the endpoint “shopping_list/items”.

1 Like