[Solved] Use list of entity ids in call service node

Hi,

I’m trying to use function node to make an entity_id list to be used in call service node but without success here is what I’m using:

[{"id":"4278b032e0ddcfec","type":"api-call-service","z":"d05daf04de9e815b","name":"reboot deco","server":"68c26a11.2f8a04","version":5,"debugenabled":true,"domain":"tplink_deco","service":"reboot_deco","areaId":[],"deviceId":[],"entityId":["{{payload.entity_id}}"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":true,"outputProperties":[],"queue":"none","x":450,"y":140,"wires":[[]]},{"id":"f0711a1e44ba92f1","type":"function","z":"d05daf04de9e815b","name":"","func":"if (msg.payload === \"test\") msg.payload = {\"entity_id\":\"device_tracker.roof_deco\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":140,"wires":[["4278b032e0ddcfec"]]},{"id":"4d3e31e8fdf7e08d","type":"inject","z":"d05daf04de9e815b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"test","payloadType":"str","x":130,"y":140,"wires":[["f0711a1e44ba92f1"]]}]

the flow above get this error:

if I use this flow it works:

[{"id":"df962c72291077d9","type":"api-call-service","z":"b30b34f03c8840d2","name":"reboot deco","server":"68c26a11.2f8a04","version":5,"debugenabled":true,"domain":"tplink_deco","service":"reboot_deco","areaId":[],"deviceId":[],"entityId":["device_tracker.roof_deco","{{payload.entity_id}}"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":true,"outputProperties":[],"queue":"none","x":470,"y":120,"wires":[[]]},{"id":"3cd1ad0e2e7282be","type":"function","z":"b30b34f03c8840d2","name":"","func":"if (msg.payload === \"test\") msg.payload = {\"entity_id\":\"device_tracker.roof_deco\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":120,"wires":[["df962c72291077d9"]]},{"id":"1175e2e19e78eb62","type":"inject","z":"b30b34f03c8840d2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"test","payloadType":"str","x":150,"y":120,"wires":[["3cd1ad0e2e7282be"]]}]

any help to make it work on the first code ?

thank you

Your first code doesn’t recognise the payload as an array but as a string which i think is causing it to fail
Try this in the function node instead of the code you currently have as this will define the entity_id as an array

if (msg.payload === "test") 
    msg.payload = {"entity_id":["device_tracker.roof_deco"]};
return msg;

Hi, thanks for the reply, I tried the code you suggested but I got the same error.

To send a list the entities need brackets and separated by a comma.

["device_tracker.one","device_tracker.two"]
1 Like

Hi @Mikefila I tried but I got the same error using this code in the function node.

if (msg.payload === "test") 
    msg.payload = {"entity_id":["device_tracker.roof_deco","device_tracker.roof_deco"]};
return msg;

It works like that for me at least with a light entity. I don’t have that service so I cannot test it. Could you try turning on 2 light entities with that format, to see if that works?

Hi,

I got it solved with the following code in the function node:

if (msg.payload === "test") 
    msg.payload = {"entity_id":["device_tracker.roof_deco"]};
return msg;

and adding this code in the data section in the call service as JSON:

{"entity_id":["{{payload.entity_id}}"]}

thanks for the guidance :grinning_face_with_smiling_eyes:

1 Like