Some question about flow (flow env var and http request node)

hi all i new node-red developper for my domotic project .... i have some question .... (sorry by advance if what i say is not clear, english isn't my native language).

1- with change node i create some flow env var, i try to use it into url in http request node. example flow.sensorID = 12345 and url in http request is https://192.168.2.2/getvalue?sendorID={{{flow.sensor}}} and the uri sended must be look this https://192.168.2.2/getvalue?sendorID=12345 but don't work ....

2 - i have some node (api call some sensor value from my domotic controller) in parallel to optimize execution time, but the last node (condition salon) need all previous node execution is done before execution. how i can create this dependancy ?

part of my flow

[{"id":"ab1ae36c16c51361","type":"tab","label":"Flux 2","disabled":false,"info":"","env":[]},{"id":"3802d677cf600d39","type":"change","z":"ab1ae36c16c51361","name":"init var flow","rules":[{"t":"set","p":"api_user","pt":"flow","to":"XXXXXXX","tot":"str"},{"t":"set","p":"api_secret","pt":"flow","to":"XXXXXXXXXXX","tot":"str"},{"t":"set","p":"light_salon","pt":"flow","to":"660789","tot":"str"},{"t":"set","p":"bright_salon","pt":"flow","to":"1269446","tot":"str"},{"t":"set","p":"plex_scene_id","pt":"flow","to":"689480","tot":"str"},{"t":"set","p":"last_hc","pt":"flow","to":"804022","tot":"str"},{"t":"set","p":"last_salon","pt":"flow","to":"877998","tot":"str"},{"t":"set","p":"chromecast_id_salon","pt":"flow","to":"XXXXXXXXXXX","tot":"str"},{"t":"set","p":"chromecast_id_hc","pt":"flow","to":"XXXXXXXXXXX","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":150,"y":340,"wires":[[]]},{"id":"2e5df20e04e0afb0","type":"http in","z":"ab1ae36c16c51361","name":"plex web hook","url":"/plexwebhook","method":"post","upload":true,"swaggerDoc":"","x":180,"y":420,"wires":[["458f73f5960fc083","3802d677cf600d39","73d907570add7515","b939e1a651cb4321"]]},{"id":"458f73f5960fc083","type":"http response","z":"ab1ae36c16c51361","name":"","statusCode":"200","headers":{},"x":220,"y":460,"wires":[]},{"id":"b939e1a651cb4321","type":"http request","z":"ab1ae36c16c51361","name":"get light salon","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.xxxxxxxx.com/get?action=periph.caract&periph_id={{{light_salon}}}&api_user={{{api_user}}}&api_secret={{{api_secret}}}","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":500,"y":460,"wires":[["1d188e9d3646e25b"]]},{"id":"73d907570add7515","type":"http request","z":"ab1ae36c16c51361","name":"get brightness salon","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.xxxxxxxx.com/get?action=periph.caract&periph_id={{{bright_salon}}}&api_user={{{api_user}}}&api_secret={{{api_secret}}}","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":520,"y":380,"wires":[["45b37a4f075fa697"]]},{"id":"45b37a4f075fa697","type":"function","z":"ab1ae36c16c51361","name":"getbrightsalon","func":"flow.set(\"brightsalon\", msg.payload.body.last_value);\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":740,"y":380,"wires":[["e2dcab8b53a5ab0d"]]},{"id":"1d188e9d3646e25b","type":"function","z":"ab1ae36c16c51361","name":"getlightsalon","func":"flow.set(\"lightsalon\", msg.payload.body.last_value_text);\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":460,"wires":[["e2dcab8b53a5ab0d"]]},{"id":"e2dcab8b53a5ab0d","type":"function","z":"ab1ae36c16c51361","name":"condition_salon","func":"\nvar bright = flow.get('brightsalon')\nvar light = flow.get('lightsalon')\nif ( parseInt(bright)<50 && parseInt(light) >0 ) {\n    flow.set(\"salon_test\", 'OK');\n} else {\n    flow.set(\"salon_test\", 'NOK');\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":440,"wires":[[]]}]

thx by advance for your help. have a good day

  • 1 Flow vars do not work in the http request mustache style replacement. You would need to set a msg var prior to the http node. I would advise avoiding context vars unless really needed, best to pass the values down the wires in other msg properties.

  • 2 if you want the final http request to happen after the others, wire it in series after them. if you have multiple request then use a manual join node with a count to make sure all others have executed prior. Use switch nodes to check the http request return msg.statusCode 200 or 201.

Welcome to the forum @killpilot

I think you mean flow context variables.

As a beginner, please try to avoid flow and global context. It is virtually never required and only occasionally the best way to solve a problem. Try to pass the data using messages, that is the node red way.

hi all, thanks for your reply...

for the point 2- thx i try it soon. for the point 1- ok my bad....

for the recommandation about usage of flow context variables, ok... the idea behind the contextual variables was to be able to have a kind of centralised configuration table, so that when i share it with the members of the community of my domotic box there is no need to modify all the nodes and only have to edit the variables. but if there is a more "elegant" way of doing it i'm of course open to any proposal.

If these values are constant then you could set global environmental vars Version 3.1 released : Node-RED
And here is how you can recall them Using environment variables : Node-RED

You can also set environmental vars per flow, group or subflow

The difference being that environment variables are not variable, they are constant. They can be different on different systems, but they cannot be changed at run time.