I know I could do this with a function node (or perhaps a jsonata value in a switch node), but I'm wondering if there's a (simple) way to do this with the basic (i.e. core) nodes that come with a fresh node red install...
I have a flow variable stored as JSON that contains a list of key/value pairs and I want to check if an incoming message's values are among the values in the flow variable.
E.g. the incoming message has values for keys names "list", "title", and "changed". I want to see if the msg.payload.list
value matches one of the corresponding flow.spoken_reminders[x].list
values in the flow variable. I then want to see if the msg.payload.title
value matches one of the corresponding flow.spoken_reminders[x].reminder
value. Then I just want to see if msg.payload.changed
matches "duedate"
.
I wrote a working example that checks 3 static members of the flow variable. But I'd like it to work on a flow variable containing a list of variable size. It would also be nice if there was a single output (as opposed to the 3 outputs of each switch in my example. It would even be cooler if I could do all 3 checks (on list, title, and changed) in a single node. The ideal solution would do all that and also use the "Spoken Reminders" template without need to store it in a flow variable. But any solution which satisfies any one of these goals would be helpful.
Here's my static example. It initializes the flow variable. Then you can run the test and get a single matching output in the debug panel...
[{"id":"c6d2cb6e.6beec8","type":"template","z":"f1e2fb56.ef74a","name":"Spoken Reminders","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"[\n {\n \"list\": \"ToDo Home Recurring\",\n \"reminder\": \"Recycling is every other Monday\"\n },\n {\n \"list\": \"ToDo Home Recurring\",\n \"reminder\": \"Trash pickup is Wednesday\"\n },\n {\n \"list\": \"ToDo Home Recurring\",\n \"reminder\": \"Compost pickup is Thursday\"\n }\n]\n","output":"json","x":810,"y":200,"wires":[["3f2071af.fa19a6"]]},{"id":"39ecc5db.dafeaa","type":"switch","z":"f1e2fb56.ef74a","name":"list","property":"payload.list","propertyType":"msg","rules":[{"t":"eq","v":"spoken_reminders[0].list","vt":"flow"},{"t":"eq","v":"spoken_reminders[1].list","vt":"flow"},{"t":"eq","v":"spoken_reminders[2].list","vt":"flow"}],"checkall":"false","repair":false,"outputs":3,"x":950,"y":140,"wires":[["755f6d4c.c4ef64"],["755f6d4c.c4ef64"],["755f6d4c.c4ef64"]]},{"id":"a035cd29.01691","type":"inject","z":"f1e2fb56.ef74a","name":"Init","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":650,"y":200,"wires":[["c6d2cb6e.6beec8"]]},{"id":"82cc268f.867a6","type":"debug","z":"f1e2fb56.ef74a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1230,"y":200,"wires":[]},{"id":"3f2071af.fa19a6","type":"change","z":"f1e2fb56.ef74a","name":"Set Spoken Reminders","rules":[{"t":"set","p":"spoken_reminders","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1030,"y":200,"wires":[["82cc268f.867a6"]]},{"id":"3641807d.d648","type":"template","z":"f1e2fb56.ef74a","name":"Test false event","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"{\n\"id_new\": \"0BFCB5FC-14F8-43EB-AFAB-A37894E31D83\",\n\"when\": \"2021-06-20T18:52:36\",\n\"iscurrent\": \"1\",\n\"title\": \"Take my mid-day sulfasalazine\",\n\"id_old\": \"086A3F9B-308D-54CE-8CBD-2EBC24508025\",\n\"id_cur\": \"0BFCB5FC-14F8-43EB-AFAB-A37894E31D83\",\n\"val_new\": \"2021-06-20T18:52:36\",\n\"val_old\": \"\",\n\"val_cur\": \"2021-06-20T18:52:36\",\n\"list\": \"Reminders Recurring\",\n\"changed\": \"completeddate\"\n}","output":"json","x":800,"y":160,"wires":[["39ecc5db.dafeaa"]]},{"id":"28182ab.14f24d6","type":"inject","z":"f1e2fb56.ef74a","name":"Test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":650,"y":140,"wires":[["3641807d.d648","53877301.bd7904"]]},{"id":"6313100d.cb17e8","type":"debug","z":"f1e2fb56.ef74a","name":"Test","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1310,"y":140,"wires":[]},{"id":"53877301.bd7904","type":"template","z":"f1e2fb56.ef74a","name":"Test true event","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"{\n\"id_new\": \"0BFCB5FC-14F8-43EB-AFAB-A37894E31D83\",\n\"when\": \"2021-06-20T18:52:36\",\n\"iscurrent\": \"1\",\n\"title\": \"Recycling is every other Monday\",\n\"id_old\": \"086A3F9B-308D-54CE-8CBD-2EBC24508025\",\n\"id_cur\": \"0BFCB5FC-14F8-43EB-AFAB-A37894E31D83\",\n\"val_new\": \"2021-06-20T18:52:36\",\n\"val_old\": \"\",\n\"val_cur\": \"2021-06-20T18:52:36\",\n\"list\": \"ToDo Home Recurring\",\n\"changed\": \"duedate\"\n}","output":"json","x":800,"y":120,"wires":[["39ecc5db.dafeaa"]]},{"id":"755f6d4c.c4ef64","type":"switch","z":"f1e2fb56.ef74a","name":"rem","property":"payload.reminder","propertyType":"msg","rules":[{"t":"eq","v":"spoken_reminders[0].title","vt":"flow"},{"t":"eq","v":"spoken_reminders[1].title","vt":"flow"},{"t":"eq","v":"spoken_reminders[2].title","vt":"flow"}],"checkall":"false","repair":false,"outputs":3,"x":1070,"y":140,"wires":[["b83b5cb0.695738"],["b83b5cb0.695738"],["b83b5cb0.695738"]]},{"id":"b83b5cb0.695738","type":"switch","z":"f1e2fb56.ef74a","name":"due","property":"payload.changed","propertyType":"msg","rules":[{"t":"eq","v":"duedate","vt":"str"}],"checkall":"false","repair":false,"outputs":1,"x":1190,"y":140,"wires":[["6313100d.cb17e8"]]}]