Node Red Not Finding a Todo Item

I have the following flow:

[{"id":"5","type":"api-call-service","z":"c8971be928290274","name":"Mark as Complete","server":"6e751b1b.8f17c4","version":7,"debugenabled":false,"action":"todo.update_item","floorId":[],"areaId":[],"deviceId":[],"entityId":["todo.house"],"labelId":[],"data":"{\"item\": $string(payload[0].id), \"status\": \"completed\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"queue":"none","blockInputOverrides":false,"domain":"todo","service":"update_item","target":{"entity_id":"todo.house"},"service_domain":"todo","x":1190,"y":1560,"wires":[[]]},{"id":"4","type":"switch","z":"c8971be928290274","name":"Found?","property":"payload","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"$count(payload) > 0"}],"checkall":"true","repair":false,"outputs":1,"x":980,"y":1580,"wires":[["5"]]},{"id":"3","type":"change","z":"c8971be928290274","name":"Find 'Charge the Tesla' Task","rules":[{"t":"set","p":"payload","pt":"msg","to":"$filter(\t   payload[\"todo.house\"].items,\t   function($v) { $v.summary = \"Charge the Tesla.\" }\t)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":1580,"wires":[["4","7de2f97003fb6957"]]},{"id":"2","type":"api-call-service","z":"c8971be928290274","name":"Get all House Tasks","server":"6e751b1b.8f17c4","version":7,"debugenabled":false,"action":"todo.get_items","floorId":[],"areaId":[],"deviceId":[],"entityId":["todo.house"],"labelId":[],"data":"{\"status\":\"needs_action\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"queue":"none","blockInputOverrides":false,"domain":"todo","service":"get_items","target":{"entity_id":"todo.house"},"service_domain":"todo","x":460,"y":1580,"wires":[["3","c89ce0b12df876e5"]]},{"id":"7de2f97003fb6957","type":"debug","z":"c8971be928290274","name":"debug 109","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":990,"y":1480,"wires":[]},{"id":"1","type":"server-state-changed","z":"c8971be928290274","name":"Tesla Starts Charging","server":"6e751b1b.8f17c4","version":6,"outputs":2,"exposeAsEntityConfig":"","entities":{"entity":["binary_sensor.bennett_charging"],"substring":[],"regex":[]},"outputInitially":false,"ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"entityidfilter":"binary_sensor.bennett_charging","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","output_only_on_state_change":true,"x":180,"y":1580,"wires":[["2"],[]]},{"id":"2876fc0a2a2b8961","type":"inject","z":"c8971be928290274","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":1520,"wires":[["2"]]},{"id":"c89ce0b12df876e5","type":"debug","z":"c8971be928290274","name":"debug 108","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":1500,"wires":[]},{"id":"6e751b1b.8f17c4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"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}]

This flow would search todo.house for any task where the Summary = “Charge the Tesla.” From there it would update the item from status: needs_action to status: completed.

Following a recent update, the Flow no longer finds the item “Charge the Tesla”.

Anyone have any idea why?

That is an easy one to solve.

You are attempting to use

$filter(
   payload["todo.house"].items,
   function($v) { $v.summary = "Charge the Tesla." }
)

to filter the return from the action call. However this is invalid JSONata, and should never have worked in the first place.

Referencing in JS uses the [" "] notation, but JSONata requires a different syntax. The following should work for you.

$filter(
   payload.'todo.house'.items,
   function($v) { $v.summary = "Charge the Tesla." }
)

payload[ ] in JSONata uses the [ ] as a filter, and is looking for a predicate to apply to an array, hence “todo.house” needs to return true or false for each item in the array. In this case it is just a string, and does not work as a filter predicate.

I don’t see that you need the $filter() function at all, since

payload.'todo.house'.items[summary = "Charge the Tesla."]

does exactly the same thing.

1 Like