Ondilo ICO pool sensor API

Here is a simple way to get sensor data from your Ondilo ICO pool/spa probe

It is fully managed with simple node red http request, but need a few steps to get the tokens first.

1/ Get the Tokens

You will need to use this python script to get the Token: https://pypi.org/project/ondilo/

You can just follow the instruction and try the provided example script than can be launched with:

$ python test_ondilo.py

Assuming your test_ondilo.py contains:

from ondilo import Ondilo

client = Ondilo(redirect_uri="https://example.com/api")
print('Please go here and authorize,', client.get_authurl())

redirect_response = input('Paste the full redirect URL here:')
client.request_token(authorization_response=redirect_response)

print("Found all those pools: ", client.get_pools())

a chmod +x test_ondilo.py may be needed.

Follow the steps: the script will provide a link to ondilo oauth interface, login there with your ICO account (same as in the ICO phone app), it will redirect to a link to "example.com" that will not work: copy the link and paste it back on the script prompt. => This is all from https://pypi.org/project/ondilo/ not work from my side here.

If the script works, modify it as following:

from ondilo import Ondilo

client = Ondilo(redirect_uri="https://example.com/api")
print('Please go here and authorize,', client.get_authurl())

redirect_response = input('Paste the full redirect URL here:')
print(client.request_token(authorization_response=redirect_response))

print("Found all those pools: ", client.get_pools())

(just add a "print" to get the token displayed)

the script will now output your tokens as following:

{'access_token': '<your_token>', 'expires_in': 3600, 'token_type': 'Bearer', 'scope': ['api'], 'refresh_token': '<your_refresh_token>', 'expires_at': 1658787174.6044903}

the script will also give your pool id (a few digit number), you may want to make a note of it, it's needed in some API links.

That's it for tokens !!

2/ Node red

flow screenshot

Then import the flow, before deploy, please update following:

  • in top http request, in the link, replace <your_pool_id> by your pool id (4 or 5 digit number)
  • in the bottom left function, update <your_refresh_token> with your refresh token (make sure to use the refresh one, not the main) of course, do not keep the <>.

Deploy, make sure to trigger the refresh path first (both left inject), so that global variable ICO_access_token will receive your refreshed token (valid 1hour). you can check it works with debug messages and also ICO_access_token global variable shall have been filled with your new token. You may consider set the inject node to refresh token every hours (not more, to not overload ondilo servers).

Then you can trigger the measure path (top left inject node), it shall make a request and you will receive the data from your pool. The data shall be visible in debug message and also various global variable.

Hope that helps!

Check official API doc here, various information can be grabbed. Make sure to keep request rate low. The documentation says max 5 requests per second, 30 requests per hour. I suggest to keep it lower or equal to 1 request per hour, as this is the measurement rate of the probe.

https://interop.ondilo.com/docs/api/customer/v1/

[{"id":"587c9568a72202fa","type":"http request","z":"3e82460a1e5bae15","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://interop.ondilo.com/api/customer/v1/pools/<your_pool_id>/lastmeasures","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"credentials":{"user":"","password":""},"x":630,"y":220,"wires":[["257b62973c106a9d","a16e769114b82693"]]},{"id":"b1dbf47f6b5d838a","type":"http request","z":"3e82460a1e5bae15","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://interop.ondilo.com/oauth2/token","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"credentials":{},"x":630,"y":300,"wires":[["257b62973c106a9d","1d25c1faa3916aa9"]]},{"id":"257b62973c106a9d","type":"debug","z":"3e82460a1e5bae15","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":260,"wires":[]},{"id":"34c16eea1c6cfc39","type":"function","z":"3e82460a1e5bae15","name":"","func":"msg.payload = \"refresh_token=<your_refresh_token>&grant_type=refresh_token&client_id=customer_api\";\nmsg.headers = {};\nmsg.headers['Content-Type'] = 'application/x-www-form-urlencoded';\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":300,"wires":[["b1dbf47f6b5d838a"]]},{"id":"1d25c1faa3916aa9","type":"change","z":"3e82460a1e5bae15","name":"","rules":[{"t":"set","p":"ICO_access_token","pt":"global","to":"payload.access_token","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":300,"wires":[[]]},{"id":"f73907e39ed86df3","type":"function","z":"3e82460a1e5bae15","name":"","func":"msg.headers = {\n    Authorization: \"Bearer \" + global.get('ICO_access_token')\n}\ndelete msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":220,"wires":[["587c9568a72202fa"]]},{"id":"a16e769114b82693","type":"change","z":"3e82460a1e5bae15","name":"","rules":[{"t":"set","p":"ICO_temperature","pt":"global","to":"payload[0]","tot":"msg"},{"t":"set","p":"ICO_redox","pt":"global","to":"payload[1]","tot":"msg"},{"t":"set","p":"ICO_ph","pt":"global","to":"payload[2]","tot":"msg"},{"t":"set","p":"ICO_sel","pt":"global","to":"payload[3]","tot":"msg"},{"t":"set","p":"ICO_battery","pt":"msg","to":"payload[4]","tot":"msg"},{"t":"set","p":"ICO_rssi","pt":"msg","to":"payload[5].value","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":880,"y":220,"wires":[[]]},{"id":"9a6ad118492ee868","type":"inject","z":"3e82460a1e5bae15","name":"Refresh token","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":300,"wires":[["34c16eea1c6cfc39"]]},{"id":"022e32a49f9c0ec9","type":"inject","z":"3e82460a1e5bae15","name":"API request","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":220,"wires":[["f73907e39ed86df3"]]}]

Flow Info

Created 1 year, 10 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x2)
  • debug (x1)
  • function (x2)
  • http request (x2)
  • inject (x2)

Tags

  • sensor
  • api
  • ondilo
  • ico
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option