iAqualink for Pool Equipment strike again

hello,
I found a post that exactly matches my problem:

and even the spotify example that goes with it. But unfortunately like Tico, I'm drooling hats tried to recover the bearer token to put it in another http request... I manage to put it in a flow or global variable... but I can't never with a node function or change to reuse it in another http...
{ "Authorization": "Bearer " +"the token from hell"}
that works
{ "Authorization": "Bearer " & $flowContext('iaqualink').TokenID}
it does not work....
for the love of code an saint axeerror. help me.

Welcome to the forum!
That doesn't look quite right. Have a read of Working with context : Node-RED which will help you retrieving flow context in the correct way.

hi Paul , thks ,
I've already gone through this doc, but to be honest I'm not into it enough to understand, I started with a few examples, like spotify , which I can't reproduce.
I get a nice token that I put in a flow.
image

it doesn't work anymore is when I try to reproduce this:
'{
"Authorization": "Bearer " & $flowContext('spotify').tokens.access_token
}'
how to replace <<& $flowContext('spotify').tokens.access_token>> by
image
that haven't no "copy path" by the way. (? Copy path of a variable from Debug Node does not work)
thks again

But you screenshot shows global.
Try $globalContext("TokenID")

Here's a flow that pulls info for two devices (Zodiac Chlorinator and Zodiac Heatpump) -

[{"id":"1e47a52e3f1755e1","type":"inject","z":"0ae35cdfe7f81cdd","name":"Every hour","repeat":"3540","crontab":"","once":true,"onceDelay":"60","topic":"","payload":"","payloadType":"date","x":110,"y":80,"wires":[["6808aab954fc8b01"]]},{"id":"7849f0c750568181","type":"http request","z":"0ae35cdfe7f81cdd","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":590,"y":80,"wires":[["18bf3f43ad2e6aa4"]]},{"id":"18bf3f43ad2e6aa4","type":"change","z":"0ae35cdfe7f81cdd","name":"IDToken","rules":[{"t":"move","p":"payload.userPoolOAuth.IdToken","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":80,"wires":[["ea244732498b9412"]]},{"id":"6808aab954fc8b01","type":"function","z":"0ae35cdfe7f81cdd","name":"Format Post Request","func":"msg.method = 'POST';\nmsg.headers = {};\nmsg.headers['Host'] = 'prod.zodiac-io.com';\nmsg.headers['accept'] = 'application/json';\nmsg.headers['content-type'] = 'application/json';\nmsg.headers['accept-encoding'] = 'gzip';\nmsg.headers['user-agent'] = 'okhttp/3.12.0';\nmsg.url = 'https://prod.zodiac-io.com/users/v1/login';\nmsg.payload = '{\"api_key\":\"yourapikeyhere\", \"email\":\"youremail@address.com\", \"password\":\"youriAqualinkpassword\"}';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":80,"wires":[["7849f0c750568181"]]},{"id":"ea244732498b9412","type":"function","z":"0ae35cdfe7f81cdd","name":"Set variable IDToken","func":"global.set(\"IDToken\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":80,"wires":[[]]},{"id":"dcd9bc84914a71f6","type":"http request","z":"0ae35cdfe7f81cdd","name":"Chlorinator","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":590,"y":400,"wires":[["02b59259a14e8461","b8075e9783a1eb4f","f0bb9145a81ce74a","eba07f6046f035d6","4ac01fee0ba334b1","018a8ddf5da0b1f2","9c4298d655076b55"]]},{"id":"9df6c312e595c863","type":"function","z":"0ae35cdfe7f81cdd","name":"Format Get Request","func":"let bearer = global.get(\"IDToken\");\nmsg.method = 'GET';\nmsg.headers = {};\nmsg.headers['Host'] = 'prod.zodiac-io.com';\nmsg.headers['accept'] = 'application/json';\nmsg.headers['authorization'] = bearer;\nmsg.headers['accept-encoding'] = 'gzip';\nmsg.headers['user-agent'] = 'okhttp/3.12.0';\nmsg.url = 'https://prod.zodiac-io.com/devices/v1/yourDeviceIDhere/shadow';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":400,"wires":[["dcd9bc84914a71f6"]]},{"id":"a56824124abf6deb","type":"inject","z":"0ae35cdfe7f81cdd","name":"Every 10 mins","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"600","crontab":"","once":true,"onceDelay":"300","topic":"","payloadType":"date","x":120,"y":400,"wires":[["9df6c312e595c863","295782e3c29ee112"]]},{"id":"02b59259a14e8461","type":"change","z":"0ae35cdfe7f81cdd","name":"ORP","rules":[{"t":"move","p":"payload.state.reported.equipment.swc_0.sns_2.value","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":320,"wires":[[]]},{"id":"b8075e9783a1eb4f","type":"change","z":"0ae35cdfe7f81cdd","name":"pH","rules":[{"t":"move","p":"payload.state.reported.equipment.swc_0.sns_1.value","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":160,"wires":[["0e3f2e3e62511c3a"]]},{"id":"f0bb9145a81ce74a","type":"change","z":"0ae35cdfe7f81cdd","name":"Filter Temp","rules":[{"t":"move","p":"payload.state.reported.equipment.swc_0.sns_3.value","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":480,"wires":[[]]},{"id":"0e3f2e3e62511c3a","type":"range","z":"0ae35cdfe7f81cdd","minin":"0","maxin":"10","minout":"0","maxout":"1","action":"scale","round":false,"property":"payload","name":"Divide by 10","x":1030,"y":160,"wires":[[]]},{"id":"eba07f6046f035d6","type":"change","z":"0ae35cdfe7f81cdd","name":"ORP Setpoint","rules":[{"t":"move","p":"payload.state.reported.equipment.swc_0.orp_sp","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":400,"wires":[[]]},{"id":"4ac01fee0ba334b1","type":"change","z":"0ae35cdfe7f81cdd","name":"pH Setpoint","rules":[{"t":"move","p":"payload.state.reported.equipment.swc_0.ph_sp","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":240,"wires":[["874e523fa6c7da37"]]},{"id":"874e523fa6c7da37","type":"range","z":"0ae35cdfe7f81cdd","minin":"0","maxin":"10","minout":"0","maxout":"1","action":"scale","round":false,"property":"payload","name":"Divide by 10","x":1030,"y":240,"wires":[[]]},{"id":"018a8ddf5da0b1f2","type":"change","z":"0ae35cdfe7f81cdd","name":"Zodiac Error Code","rules":[{"t":"move","p":"payload.state.reported.equipment.swc_0.error_code","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":560,"wires":[[]]},{"id":"e64f08a15e168247","type":"function","z":"0ae35cdfe7f81cdd","name":"Format Get Request","func":"let bearer = global.get(\"IDToken\");\nmsg.method = 'GET';\nmsg.headers = {};\nmsg.headers['Host'] = 'prod.zodiac-io.com';\nmsg.headers['accept'] = 'application/json';\nmsg.headers['authorization'] = bearer;\nmsg.headers['accept-encoding'] = 'gzip';\nmsg.headers['user-agent'] = 'okhttp/3.12.0';\nmsg.url = 'https://prod.zodiac-io.com/devices/v1/yourDeviceIDhere/shadow';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":720,"wires":[["c6ca1d3e24bfb92e"]]},{"id":"c6ca1d3e24bfb92e","type":"http request","z":"0ae35cdfe7f81cdd","name":"Heat Pump","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":590,"y":720,"wires":[["8b1cfc1cd0be14da","3c3f9237065a8ad6","5c21887674341499","98851fd84020e5da","5df5ed4f4d40d4ef"]]},{"id":"295782e3c29ee112","type":"delay","z":"0ae35cdfe7f81cdd","name":"5 mins","pauseType":"delay","timeout":"5","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":230,"y":560,"wires":[["e64f08a15e168247"]]},{"id":"8b1cfc1cd0be14da","type":"change","z":"0ae35cdfe7f81cdd","name":"Heat Pump Setpoint","rules":[{"t":"move","p":"payload.state.reported.equipment.hp_0.tsp","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":720,"wires":[[]]},{"id":"5c21887674341499","type":"change","z":"0ae35cdfe7f81cdd","name":"Heap Pump Air Temp","rules":[{"t":"move","p":"payload.state.reported.equipment.hp_0.sns_2.value","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":880,"wires":[[]]},{"id":"3c3f9237065a8ad6","type":"change","z":"0ae35cdfe7f81cdd","name":"Heap Pump Water Temp","rules":[{"t":"move","p":"payload.state.reported.equipment.hp_0.sns_1.value","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":800,"wires":[[]]},{"id":"17a5e515d5f4c27f","type":"inject","z":"0ae35cdfe7f81cdd","name":"Test only","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":100,"y":720,"wires":[["e64f08a15e168247"]]},{"id":"98851fd84020e5da","type":"change","z":"0ae35cdfe7f81cdd","name":"Heat Pump Status","rules":[{"t":"move","p":"payload.state.reported.equipment.hp_0.status","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":960,"wires":[[]]},{"id":"5df5ed4f4d40d4ef","type":"change","z":"0ae35cdfe7f81cdd","name":"Heat Pump Reason","rules":[{"t":"move","p":"payload.state.reported.equipment.hp_0.reason","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":1040,"wires":[[]]},{"id":"9c4298d655076b55","type":"change","z":"0ae35cdfe7f81cdd","name":"Low Setting","rules":[{"t":"move","p":"payload.state.reported.equipment.swc_0.low","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":640,"wires":[[]]}]

Note that in the Function node (Format Post Request) preceeding the first HTTP Request , you will require three bits of info -

API Key (generic for all users) - EOOEMOW4YR6QNB11
Email
Password

In the Function node (Format Get Request) preceeding the Device, you will need 'yourDeviceIDhere' where specified. It's the serial number of the device and looks something like -

JT19000123
or
JX19100123

The post you originally linked to has the curl commands necessary to pull the DeviceID. They might also be physically printed on the device somewhere but I haven't looked.

hi Guys,
thks a lot
@ E1cid
yes i try an other way in the meantime, but is consistent
@Tico
hey, I was hoping that you had finalized on your side, iwill try your solution
I have no problem recovering the token and getting the info from the chlorinator, but doing it automatically...


(and sorry..yes...i'm french.)

you make my day...my week..and after.
image
thks a lot everybody.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.