Shopping List specific item checked as a trigger in Node RED

Hi,

within a Home Assistant Automation I was able to use a specific item when checked on my shopping list to trigger following events. I couldn’t figure out how to do it in Node RED. I tried to use “events:all” but didn’t get the result I want. Can someone help me?

Thanks.

You need to provide some more information about this service call. Link to the docs of the ingratiation/addon that creates it.

Edit: If it is the ha integration use a trigger node.

Thank you for the reply and sorry for the missing information. It’s the HA Shopping list. The way I did it does not work :slightly_frowning_face:

For prev entity use only state in lower case

image

But where to put the actual text which should act as the trigger?

image

This above is the trigger. Explained below

When entity: Shopping List’s

state changes

Conditions

this entity (“Shopping List”) implied

current state (“is”)

> this entity’s (“Shopping List”) previous state

I think we talk about different things. Here is an example (no real use case):

I add manually “Water” and “Milk” to the shopping list. If I checkmark “milk” the light should turn off and if I checkmark “water” the light should turn on. I need the trigger “Milk” and “Water” somewhere in the flow.

Okay so this will grab events for the shopping list. You will need to filter the message after. There is an example of how to do that included.

[{"id":"d9d55c2158ab9e46","type":"server-events","z":"60f2d2277843c698","name":"","server":"6b1110b5.183a4","version":3,"exposeAsEntityConfig":"","eventType":"shopping_list_updated","eventData":"","waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":710,"y":1260,"wires":[["cfeb0804bfc990c7"]]},{"id":"cfeb0804bfc990c7","type":"switch","z":"60f2d2277843c698","name":"add or complete?","property":"payload.event.action","propertyType":"msg","rules":[{"t":"eq","v":"add","vt":"str"},{"t":"eq","v":"update","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1010,"y":1260,"wires":[["05ef75f1ff1f1c04"],["27583d6714daf818"]]},{"id":"05ef75f1ff1f1c04","type":"debug","z":"60f2d2277843c698","name":"add","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1210,"y":1220,"wires":[]},{"id":"27583d6714daf818","type":"debug","z":"60f2d2277843c698","name":"complete","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1220,"y":1300,"wires":[]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Here is an example of how to use it to send a text when an item is added. Including what was added.

[{"id":"a810888e1f3a518b","type":"api-call-service","z":"60f2d2277843c698","name":"","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_pixel_7","areaId":[],"deviceId":[],"entityId":[],"data":"{\t   \"message\": msg.payload & \" has been added.\",\t   \"title\": \"An item was added\"\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":930,"y":1260,"wires":[[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

But where do I specify if it is “Milk” or “Water” which is check marked?

With another switch. the item name comes in message position payload.event.item.name so

image

now that would work if the entry is exactly milk. Capitals, punctuation, spaces would not be caught with that so use a regex or regular expression

image

[{"id":"d9d55c2158ab9e46","type":"server-events","z":"60f2d2277843c698","name":"","server":"6b1110b5.183a4","version":3,"exposeAsEntityConfig":"","eventType":"shopping_list_updated","eventData":"","waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":1770,"y":1100,"wires":[["cfeb0804bfc990c7"]]},{"id":"cfeb0804bfc990c7","type":"switch","z":"60f2d2277843c698","name":"add or complete?","property":"payload.event.action","propertyType":"msg","rules":[{"t":"eq","v":"add","vt":"str"},{"t":"eq","v":"update","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":2030,"y":1100,"wires":[["9327d9b9b4627962"],[]]},{"id":"9327d9b9b4627962","type":"switch","z":"60f2d2277843c698","name":"","property":"payload.event.item.name","propertyType":"msg","rules":[{"t":"regex","v":"milk","vt":"str","case":true},{"t":"regex","v":"water","vt":"str","case":true}],"checkall":"true","repair":false,"outputs":2,"x":2250,"y":1100,"wires":[["fd59c8b91976b6d9"],["fd59c8b91976b6d9"]]},{"id":"fd59c8b91976b6d9","type":"change","z":"60f2d2277843c698","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.event.item.name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2440,"y":1100,"wires":[[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

1 Like

Thank you so much! Couldn’t have figured that out by myself. Works perfect. :blush::pray:

How can I check before adding the item to the shopping list if the item is already on the list or not?

How are you adding items to the list?

Just with events:state and call service

[{"id":"0333aeb12134ae44","type":"api-call-service","z":"1dbabd96ff64761f","name":"Auf To Do Liste setzen","server":"d6e1a14d.333e1","version":5,"debugenabled":false,"domain":"shopping_list","service":"add_item","areaId":[],"deviceId":[],"entityId":[],"data":"{\"name\":\"Staubsauger - Filter wechseln\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":720,"y":140,"wires":[[]]},{"id":"d6e1a14d.333e1","type":"server","name":"Home Assistant","addon":true}]

How do you trigger that call service. How do you add the item? voice, text, send an email?

It’s triggered by an entity. For example if the Roborock’s filter or brush sensor is below 0 and needs to be changed. I use the HA shopping list as a To Do List.

That’s actually a good thing. I am assuming no user error meaning that items aren’t capitalized or punctuated differently from how they were originally entered.

i.e. Milk does not = milk and milk would be allowed to pass. The way it is set there will be 2 types of messages from the function node.

  1. the original payload, to be entered in the list.
  2. or "match" + original payload that can be filtered with a switch.

[{"id":"714c333921eb24c0","type":"debug","z":"60f2d2277843c698","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":1220,"wires":[]},{"id":"6f13fd431fb8e9bf","type":"function","z":"60f2d2277843c698","name":"function 6","func":"let cItem = msg.payload;\n// save payload\nlet sList = msg.results;\n// isolate incomplete\nlet fList = sList.filter(x => x.complete === false);\n// isolate name value\nlet items = fList.map(a => a.name);\n\n\nif (items.indexOf(cItem) === -1) {\n    msg.payload = cItem;\n} else {\n    msg.payload = \"match \" +cItem;\n}\n\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1220,"wires":[["714c333921eb24c0"]]},{"id":"3a640d1916193387","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":"msg.payload","valueType":"jsonata"},{"property":"results","propertyType":"msg","value":"","valueType":"results"}],"x":370,"y":1220,"wires":[["6f13fd431fb8e9bf"]]},{"id":"93cf0c6e33ea4c37","type":"inject","z":"60f2d2277843c698","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"one","payloadType":"str","x":190,"y":1220,"wires":[["3a640d1916193387"]]},{"id":"57d873e79ca331de","type":"inject","z":"60f2d2277843c698","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"four","payloadType":"str","x":190,"y":1320,"wires":[["3a640d1916193387"]]}]

Thank you for the solution. I tried to work on it in the last days but couldn’t get it to work. Can you please show me what it should totally look like from inject node until including the switch node? Thank you :pray:

Any entity that feeds into the shopping list would need the api and the check for duplicate node added. So if you have this

image
You would change it to

I added a second output so any duplicate messages come from the bottom output.

[{"id":"714c333921eb24c0","type":"debug","z":"60f2d2277843c698","name":"duplicate item","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2420,"y":1960,"wires":[]},{"id":"6f13fd431fb8e9bf","type":"function","z":"60f2d2277843c698","name":"check for duplicate","func":"let cItem = msg.payload;\n// save payload\nlet sList = msg.results;\n// isolate incomplete\nlet fList = sList.filter(x => x.complete === false);\n// isolate name value\nlet items = fList.map(a => a.name);\n\n\nif (items.indexOf(cItem) === -1) {\n    msg.payload = cItem;\n    return [msg, null]\n} else {\n    msg.payload = \"match \" + cItem;\n    return [null, msg]\n}\n\n","outputs":2,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2190,"y":1900,"wires":[["6cbbc05ec2348b2a"],["714c333921eb24c0"]]},{"id":"3a640d1916193387","type":"ha-api","z":"60f2d2277843c698","name":"get list","server":"6b1110b5.183a4","version":1,"debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\"type\": \"shopping_list/items\"}","dataType":"jsonata","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"msg.payload","valueType":"jsonata"},{"property":"results","propertyType":"msg","value":"","valueType":"results"}],"x":1990,"y":1900,"wires":[["6f13fd431fb8e9bf"]]},{"id":"6cbbc05ec2348b2a","type":"api-call-service","z":"60f2d2277843c698","name":"add to shopping list","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2430,"y":1900,"wires":[[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
1 Like

Yeah, it works :heart_eyes::blush:. Thank you so much for your time and effort! :pray:

1 Like