I’m trying to make NR log the changes it made to entities to their corresponding HA logs. In Check State I’m using {{ payload }}
to pass the entity dynamically from the function node. If I’m only triggering one entity in the service call it works. If I call multiple entities in one service call I want it to get state of each entity separately. So I get each entity_id and send it as a separate message. I expect to get the state of each, but instead I get nothing.
The function node logs them individually and I can see the Check State is getting triggered as the timestamp and the state gets updated, but it doesn’t return any output using the same logic as a single entity just in a loop. Why am I not getting any output? Is there a better way of doing this?
I’ve attached my flow below.
[{"id":"50815637d537c3c4","type":"api-call-service","z":"b1520e6b7f9039b4","name":"Turn Light Off","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.lightstrip"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"data_log","propertyType":"msg","value":"","valueType":"config"},{"property":"data_sent","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":240,"y":1160,"wires":[["4953abfe19873e35"]]},{"id":"880b5b2b1158bfd2","type":"api-current-state","z":"b1520e6b7f9039b4","name":"Check State","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{ payload }}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":550,"y":1160,"wires":[["998c70643fb5eae8"]]},{"id":"88c93c38ea67813c","type":"inject","z":"b1520e6b7f9039b4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"light.lamp","payloadType":"str","x":400,"y":1100,"wires":[["880b5b2b1158bfd2"]]},{"id":"4953abfe19873e35","type":"function","z":"b1520e6b7f9039b4","name":"function 2","func":"var entities = msg.data_sent.data.entity_id;\nif (Array.isArray(entities)) {\n entities.forEach(e => {\n msg.payload = e;\n node.warn(msg.payload);\n node.send(msg);\n })\n node.done();\n} else {\n msg.payload = entities;\n node.send(msg);\n}\n\nreturn msg = null;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":1160,"wires":[["880b5b2b1158bfd2"]]},{"id":"998c70643fb5eae8","type":"debug","z":"b1520e6b7f9039b4","name":"Full Msg","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":1160,"wires":[]},{"id":"6d460b01ae9c0f39","type":"inject","z":"b1520e6b7f9039b4","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":125,"y":1160,"wires":[["50815637d537c3c4"]],"l":false}]