Set values for multiple service nodes

I want to call multiple services in a chain, and set all necessary values in a function node at the beginning of the flow, but can’t pass the values to the service node. I must be doing wrong way. How can I correct this? Thanks.

Screen Shot 2020-02-06 at 11.21.44 PM

[{"id":"97ef2d54.967f5","type":"inject","z":"845016a6.b38828","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":600,"wires":[["f4f05ff3.7bb9d"]]},{"id":"46b8e2a4.45f71c","type":"api-call-service","z":"845016a6.b38828","name":"msg","server":"e8b4e59e.644ec8","version":1,"debugenabled":false,"service_domain":"notify","service":"alexa_media","entityId":"","data":"{\"data\":{\"type\":\"tts\",\"method\":\"all\"},\"message\": {{flow.get(\"v\")}},\"target\":[\"media_player.xx_s_echo_dot\"]}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":570,"y":600,"wires":[[]]},{"id":"1ea17760.839549","type":"api-call-service","z":"845016a6.b38828","name":"volume","server":"e8b4e59e.644ec8","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"media_player.xx_s_echo_dot","data":"{\"volume_level\": {{ flow.get(\"v\"}} }","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":420,"y":600,"wires":[["46b8e2a4.45f71c"]]},{"id":"f4f05ff3.7bb9d","type":"function","z":"845016a6.b38828","name":"","func":"flow.set(\"v\", 0.4);\nflow.set(\"m\", \"ok\")\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":600,"wires":[["1ea17760.839549"]]},{"id":"e8b4e59e.644ec8","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
[{"id":"a9785a1a.6ef108","type":"inject","z":"c9189e75.2de5e","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":284,"y":128,"wires":[["a12c7a2.17b0f88"]]},{"id":"988d69f2.42ad98","type":"api-call-service","z":"c9189e75.2de5e","name":"msg","version":1,"debugenabled":false,"service_domain":"notify","service":"alexa_media","entityId":"","data":"{\t   \"data\":{\"type\":\"tts\",\"method\":\"all\"},\t   \"message\": v,\t   \"target\":[\"media_player.xx_s_echo_dot\"]\t}","dataType":"jsonata","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":694,"y":128,"wires":[[]]},{"id":"420f22e8.b2047c","type":"api-call-service","z":"c9189e75.2de5e","name":"volume","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"media_player.xx_s_echo_dot","data":"{\"volume_level\": v }","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":544,"y":128,"wires":[["988d69f2.42ad98"]]},{"id":"a12c7a2.17b0f88","type":"function","z":"c9189e75.2de5e","name":"","func":"msg.v = 0.4;\nmsg.m = \"ok\";\nreturn msg;","outputs":1,"noerr":0,"x":414,"y":128,"wires":[["420f22e8.b2047c"]]}]
1 Like

works perfectly! thank you!

where can I read more about this msg passing mechanic in node-red?

say if I also want to pass values of domain, service and entity_id from the function node to the service node?

if there is flow and global values, what is the correct syntax to read them in the service node? {{flow.get(“v”)}} is not working.

first you need to use flow.set("v", 50);. then you can use this “v” in the same flow (or tab)
https://nodered.org/docs/user-guide/writing-functions#storing-data

flow and global variables are useful when you need to use a variable in different tabs or in nodes that are not connected. if the variable is going to be used in the nodes already connected, you don’t necessarily need that functions.

For how home-assistant web socket works with passing entity_id, domain etc, this might help
https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/mustache-templates.html

1 Like