[{"id":"5dfd7c4fa8812f8b","type":"tab","label":"Netatmo New","disabled":false,"info":"","env":[]},{"id":"37c406c4251df006","type":"group","z":"5dfd7c4fa8812f8b","name":"retrieve data from Net Atmo","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["227b570a0ddb37d6","c90883e30af7414f","a6497c641eae2d3d","f03d6a1770671654","43cea1af6281e150","4272b4f37aaa8d85","d705af61f82a51a0","ccf05151b8977a17","b2aee11227c34965","06d4b90b7b3e2087","ead7a83a276da6d5","5b801eefb73d69e8","cbac66eef3ac6f68","f64a1f7a539e19ae","d09a9e75c1cb3fd9","39c95ea1197778ad"],"x":74,"y":579,"w":1792,"h":382},{"id":"1e6ac73d16d3e4fd","type":"group","z":"5dfd7c4fa8812f8b","name":"start and refresh access data","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["35b6ddece06e5a06","d273766e96d450e0","6ceb42cb69397e82","6247f8cc1cc3880c","fe38821d7708d05c","5d156d10e7192948","f4794e23ba9db104","a6e99594aa88149d","549a3c451e797ba0","a2a6fbccd8054ab7","fde679bf6c4b3a78","b50c27c613f7bfda","37572cdd83c4a88e"],"x":74,"y":339,"w":1632,"h":202},{"id":"f1d3eb19dd08efed","type":"group","z":"5dfd7c4fa8812f8b","name":"set NetAtmo credetials","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["033f7ad3bdf1e1f8","7537a9afc9d0ce1a"],"x":74,"y":99,"w":492,"h":82},{"id":"7bdfafd0d061bf13","type":"group","z":"5dfd7c4fa8812f8b","name":"single HTTP request","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["472e545334afadc6","2df1498ab5d28910","424bd2e4540e6da0"],"x":84,"y":219,"w":402,"h":82},{"id":"75adeef4d28b4d5f","type":"group","z":"5dfd7c4fa8812f8b","name":"error handling","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["c3d6f0104c69996d","1fc4771ca6ce3334","97d79dc47576aa9f","d92a122a85e3b0cc","653ae61d5333b989","bb043a8f9a80d5ea"],"x":74,"y":999,"w":732,"h":122},{"id":"b50c27c613f7bfda","type":"junction","z":"5dfd7c4fa8812f8b","g":"1e6ac73d16d3e4fd","x":500,"y":380,"wires":[["d273766e96d450e0"]]},{"id":"35b6ddece06e5a06","type":"inject","z":"5dfd7c4fa8812f8b","g":"1e6ac73d16d3e4fd","name":"Start","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":170,"y":380,"wires":[["b50c27c613f7bfda"]]},{"id":"d273766e96d450e0","type":"change","z":"5dfd7c4fa8812f8b","g":"1e6ac73d16d3e4fd","name":"Set param request & refresh","rules":[{"t":"set","p":"method","pt":"msg","to":"POST","tot":"str"},{"t":"set","p":"url","pt":"msg","to":"https://api.netatmo.com/oauth2/token","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"{\"grant_type\":\"refresh_token\",\"refresh_token\":$globalContext(\"NetatmoRefreshToken\"),\"client_id\":$globalContext(\"NetatmoClientId\"),\"client_secret\":$globalContext(\"NetatmoClientSecret\")}","tot":"jsonata"},{"t":"set","p":"headers[\"content-type\"]","pt":"msg","to":"application/x-www-form-urlencoded","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":440,"wires":[["37572cdd83c4a88e"]]},{"id":"6ceb42cb69397e82","type":"change","z":"5dfd7c4fa8812f8b","g":"1e6ac73d16d3e4fd","name":"Store tokens & delay","rules":[{"t":"set","p":"NetatmoAccessToken","pt":"global","to":"payload.access_token","tot":"msg"},{"t":"set","p":"NetatmoRefreshToken","pt":"global","to":"payload.refresh_token","tot":"msg"},{"t":"set","p":"delay","pt":"msg","to":"payload.expires_in*1000-300000","tot":"jsonata"},{"t":"set","p":"status","pt":"msg","to":"OK","tot":"str"},{"t":"set","p":"NetatmoLastUpdateTime","pt":"global","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":380,"wires":[["f4794e23ba9db104","a6e99594aa88149d"]]},{"id":"033f7ad3bdf1e1f8","type":"change","z":"5dfd7c4fa8812f8b","g":"f1d3eb19dd08efed","name":"Set Netatmo Creds & Tokens","rules":[{"t":"set","p":"NetatmoClientId","pt":"global","to":"","tot":"str"},{"t":"set","p":"NetatmoClientSecret","pt":"global","to":"","tot":"str"},{"t":"set","p":"NetatmoAccessToken","pt":"global","to":"581352d2e6da23fa898b49ae|f849008b26ca2aeb84a459cea673f283","tot":"str"},{"t":"set","p":"NetatmoRefreshToken","pt":"global","to":"581352d2e6da23fa898b49ae|fe902827ce3f122f9b0840592c3334b2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":140,"wires":[[]]},{"id":"7537a9afc9d0ce1a","type":"inject","z":"5dfd7c4fa8812f8b","g":"f1d3eb19dd08efed","name":"Set first info","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":140,"wires":[["033f7ad3bdf1e1f8"]]},{"id":"6247f8cc1cc3880c","type":"inject","z":"5dfd7c4fa8812f8b","g":"1e6ac73d16d3e4fd","name":"Stop","props":[{"p":"reset","v":"1","vt":"num"},{"p":"status","v":"STOP","vt":"str"},{"p":"delay","v":"1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":480,"wires":[["f4794e23ba9db104","fde679bf6c4b3a78"]]},{"id":"fe38821d7708d05c","type":"switch","z":"5dfd7c4fa8812f8b","g":"1e6ac73d16d3e4fd","name":"All ok ?","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"access_token","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1040,"y":440,"wires":[["6ceb42cb69397e82"],["5d156d10e7192948"]],"outputLabels":["Response OK","Error"]},{"id":"5d156d10e7192948","type":"change","z":"5dfd7c4fa8812f8b","g":"1e6ac73d16d3e4fd","name":"Delay 1 hour on error","rules":[{"t":"set","p":"delay","pt":"msg","to":"3600000","tot":"num"},{"t":"set","p":"status","pt":"msg","to":"KO","tot":"str"},{"t":"set","p":"NetatmoLastUpdateTime","pt":"global","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":500,"wires":[["f4794e23ba9db104","a6e99594aa88149d"]]},{"id":"f4794e23ba9db104","type":"delay","z":"5dfd7c4fa8812f8b","g":"1e6ac73d16d3e4fd","name":"Refresh","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":440,"y":440,"wires":[["d273766e96d450e0"]]},{"id":"a6e99594aa88149d","type":"delay","z":"5dfd7c4fa8812f8b","g":"1e6ac73d16d3e4fd","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":1600,"y":420,"wires":[["549a3c451e797ba0"]]},{"id":"549a3c451e797ba0","type":"function","z":"5dfd7c4fa8812f8b","g":"1e6ac73d16d3e4fd","name":"Next refresh in...","func":"var d = new Date();\nvar n = d.getTime();\nvar start_time = global.get('NetatmoLastUpdateTime')||0;\nvar duration = msg.delay/1000;\nvar elapsed_time = Math.round((n - start_time)/1000);\n\nvar remains = new Date(null);\nremains.setSeconds(duration - elapsed_time); // specify value for SECONDS here\nvar remains_h = remains.toISOString().substr(11, 8);\nif (msg.status == \"STOP\") {\n node.status({});\n msg.remains = \"00:00:00\";\n msg.payload = 0;\n return [null, msg];\n}\nif (elapsed_time < duration) {\n node.status({fill:msg.status == \"OK\" ? \"blue\" : \"red\",shape:\"dot\", text:remains_h});\n msg.remains = remains_h;\n return [ msg, null ];\n}\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1600,"y":480,"wires":[["a6e99594aa88149d"],[]]},{"id":"227b570a0ddb37d6","type":"change","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"set pram request","rules":[{"t":"set","p":"method","pt":"msg","to":"GET","tot":"str"},{"t":"set","p":"url","pt":"msg","to":"https://api.netatmo.com/api/getstationsdata","tot":"str"},{"t":"set","p":"headers[\"Authorization\"]","pt":"msg","to":"\"Bearer \" & $globalContext(\"NetatmoAccessToken\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":760,"wires":[["d09a9e75c1cb3fd9"]]},{"id":"c90883e30af7414f","type":"inject","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"Get Netatmo Data","props":[{"p":"payload"}],"repeat":"300","crontab":"","once":false,"onceDelay":"10","topic":"","payload":"","payloadType":"date","x":210,"y":760,"wires":[["227b570a0ddb37d6"]]},{"id":"a6497c641eae2d3d","type":"mqtt in","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"","topic":"Net_Atmo_record","qos":"0","datatype":"auto-detect","broker":"99603ece.52e2a","nl":false,"rap":true,"rh":0,"inputs":0,"x":1520,"y":740,"wires":[["f03d6a1770671654"]]},{"id":"f03d6a1770671654","type":"debug","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"netatmo record in","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1730,"y":740,"wires":[]},{"id":"43cea1af6281e150","type":"inject","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"Test","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":820,"wires":[["227b570a0ddb37d6"]]},{"id":"a2a6fbccd8054ab7","type":"link in","z":"5dfd7c4fa8812f8b","g":"1e6ac73d16d3e4fd","name":"stop-in","links":["fde679bf6c4b3a78"],"x":1335,"y":440,"wires":[["a6e99594aa88149d","549a3c451e797ba0"]]},{"id":"fde679bf6c4b3a78","type":"link out","z":"5dfd7c4fa8812f8b","g":"1e6ac73d16d3e4fd","name":"stop-out","mode":"link","links":["a2a6fbccd8054ab7"],"x":395,"y":500,"wires":[]},{"id":"4272b4f37aaa8d85","type":"switch","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"body?","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"body","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":930,"y":760,"wires":[["b2aee11227c34965","ccf05151b8977a17","d705af61f82a51a0","5b801eefb73d69e8","ead7a83a276da6d5"],["39c95ea1197778ad"]]},{"id":"d705af61f82a51a0","type":"mqtt out","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"Net_Atmo_record","topic":"Net_Atmo_record","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"99603ece.52e2a","x":1270,"y":740,"wires":[]},{"id":"5b801eefb73d69e8","type":"link out","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"link out 2","mode":"link","links":["9ceca7067dab4533","f122c9b8706c128b"],"x":1195,"y":800,"wires":[]},{"id":"ccf05151b8977a17","type":"function","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"time / record counter","func":"let counter = context.get(\"counter\");\ncounter = counter + 1;\ncontext.set(\"counter\", counter);\n\nlet time = moment().tz(\"Europe/Berlin\").format(\"HH:mm:ss\");\nnode.status({ fill: \"green\", shape: \"dot\", text: time + \" / \" + counter });\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\n\ncontext.set(\"counter\", 0);\n","finalize":"","libs":[{"var":"moment","module":"moment"},{"var":"momentTimezone","module":"moment-timezone"}],"x":1280,"y":680,"wires":[[]]},{"id":"ead7a83a276da6d5","type":"trigger","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"watchdog","op1":"","op2":"","op1type":"nul","op2type":"date","duration":"20","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1240,"y":840,"wires":[["cbac66eef3ac6f68"]]},{"id":"f64a1f7a539e19ae","type":"link out","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"link out 258","mode":"link","links":["4aa91ee5.08bf2"],"x":1485,"y":840,"wires":[]},{"id":"cbac66eef3ac6f68","type":"function","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"watchdog","func":"let text = \"NetAtmo länger als 20 min offline!\";\nreturn { payload: { 'room': 'error', 'value': text } };","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1380,"y":840,"wires":[["f64a1f7a539e19ae"]]},{"id":"b2aee11227c34965","type":"debug","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"status","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload.status","targetType":"msg","statusVal":"payload.status","statusType":"auto","x":1230,"y":620,"wires":[]},{"id":"06d4b90b7b3e2087","type":"switch","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"object?","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"object","vt":"object"},{"t":"istype","v":"string","vt":"string"}],"checkall":"true","repair":false,"outputs":2,"x":800,"y":760,"wires":[["4272b4f37aaa8d85"],[]]},{"id":"472e545334afadc6","type":"http request","z":"5dfd7c4fa8812f8b","g":"7bdfafd0d061bf13","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":270,"y":260,"wires":[["424bd2e4540e6da0"]]},{"id":"2df1498ab5d28910","type":"link in","z":"5dfd7c4fa8812f8b","g":"7bdfafd0d061bf13","name":"request_in","links":[],"x":125,"y":260,"wires":[["472e545334afadc6"]]},{"id":"424bd2e4540e6da0","type":"link out","z":"5dfd7c4fa8812f8b","g":"7bdfafd0d061bf13","name":"link out 273","mode":"return","links":[],"x":445,"y":260,"wires":[]},{"id":"d09a9e75c1cb3fd9","type":"link call","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"call request","links":["2df1498ab5d28910"],"linkType":"static","timeout":"30","x":650,"y":760,"wires":[["06d4b90b7b3e2087"]]},{"id":"37572cdd83c4a88e","type":"link call","z":"5dfd7c4fa8812f8b","g":"1e6ac73d16d3e4fd","name":"call request","links":["2df1498ab5d28910"],"linkType":"static","timeout":"30","x":890,"y":440,"wires":[["fe38821d7708d05c"]]},{"id":"c3d6f0104c69996d","type":"catch","z":"5dfd7c4fa8812f8b","g":"75adeef4d28b4d5f","name":"All errors","scope":null,"uncaught":false,"x":160,"y":1080,"wires":[["d92a122a85e3b0cc"]]},{"id":"1fc4771ca6ce3334","type":"link out","z":"5dfd7c4fa8812f8b","g":"75adeef4d28b4d5f","name":"link out 300","mode":"link","links":["d3422b90f8530fb4"],"x":615,"y":1080,"wires":[]},{"id":"97d79dc47576aa9f","type":"debug","z":"5dfd7c4fa8812f8b","g":"75adeef4d28b4d5f","name":"debug NetAtmo","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":680,"y":1040,"wires":[]},{"id":"d92a122a85e3b0cc","type":"function","z":"5dfd7c4fa8812f8b","g":"75adeef4d28b4d5f","name":"Time + Fehlermeldung","func":"if (msg.payload.type === \"reset\"){\n node.status({ fill: \"green\", shape: \"dot\", text: \" \" });\n return null;\n}\n\nlet counter = context.get(\"counter\");\ncounter = counter + 1;\ncontext.set(\"counter\", counter);\n\nlet time = moment().tz(\"Europe/Berlin\").format(\"DD-MM-YYYY HH:mm:ss\");\n\nlet text = \"Fehlerzeitpunkt: \" + time + \" / \" +\n \"RPI 201\" + \" / \" +\n \"Flow: netatmo EGWZ sensor\" + \" / \" +\n \"Fehlermeldung: \" + msg.error.message + \" / \" +\n \"Fehler ID: \" + msg.error.source.id + \" / \" +\n \"Fehlertyp: \" + msg.error.source.type + \" / \" +\n \"Fehlernode: \" + msg.error.source.name + \" / \" +\n \"Fehlerzähler: \" + msg.error.source.count;\n \nnode.status({ fill: \"red\", shape: \"dot\", text: text + \" / \" + counter });\n\nreturn{payload:text};","outputs":1,"timeout":"","noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\nif (context.get(\"counter\") === undefined) {\n context.set(\"counter\", 0);\n}","finalize":"","libs":[{"var":"moment","module":"moment"},{"var":"momentTimezone","module":"moment-timezone"}],"x":420,"y":1080,"wires":[["1fc4771ca6ce3334"]]},{"id":"653ae61d5333b989","type":"link in","z":"5dfd7c4fa8812f8b","g":"75adeef4d28b4d5f","name":"debug","links":["198aa8893d75f395","e0b35f90dd344f8f","39c95ea1197778ad"],"x":505,"y":1040,"wires":[["97d79dc47576aa9f","1fc4771ca6ce3334"]]},{"id":"bb043a8f9a80d5ea","type":"inject","z":"5dfd7c4fa8812f8b","g":"75adeef4d28b4d5f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"{\"type\":\"reset\"}","payloadType":"json","x":200,"y":1040,"wires":[["d92a122a85e3b0cc"]]},{"id":"39c95ea1197778ad","type":"link out","z":"5dfd7c4fa8812f8b","g":"37c406c4251df006","name":"to dedug","mode":"link","links":["653ae61d5333b989"],"x":1195,"y":920,"wires":[]},{"id":"99603ece.52e2a","type":"mqtt-broker","broker":"10.0.0.43","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":4,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]
Unfortunately there is a problem. The first request works ok but when it should request a second time for a new token it fails and I cannot figuere out what the probelem is.
The flow above is based on this flow in the node-red flow library
flow
which works.
If someone could help me find the problem it is very appreciated.
Not sure why you didnt use the oauth2 nodes, some time ago I posted a flow that works (i see that you participated in the discussion)
This does the same as your complete flow.
thanks for the tip! I just didn't remember your post ![]()
the difference to your flow is that I get my credentiels with the help of Postman which means some cut and paste before I can start.
So the oauth2 node is much smarter. I will give it a try.
The difference to your requirement is that I want the dashboard data and not rain and wind
my working flow without oaut2 nodes and little changes to the picture above.
You have to get the the tokens from postman or equivalent software.
[{"id":"d557eb264b53eeb0","type":"tab","label":"Netatmo New","disabled":false,"info":"","env":[]},{"id":"d508edfc10ca96d0","type":"group","z":"d557eb264b53eeb0","name":"retrieve data from Net Atmo","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["7737a67081eef4e8","0443074dd4250d9c","3a5362954f199d3f","db5a4a411ed57be8","f1eec459e2893317","17d01814707624be","89225a8f357232c5","12cb8cc73743c2ce","a1e6861787c7b9cd","949e6679a2befee3","6b8ba085179f4f56","400352be8a87340e","a6600fbe65e81cc1","74f8e9dde28cfcb1","df92a998996ce415","3adc726ebd0aa92a","960cea8488046a64","7f0d116c40b05764"],"x":94,"y":559,"w":1572,"h":322},{"id":"05a20f826b31f5bf","type":"group","z":"d557eb264b53eeb0","name":"start and refresh access data","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["f44dd0fb23b1a058","3b7c2e8aac54bd1a","82a46256fef4c8f5","e89fc6f5d7b6be61","aa6ab32c346b7dc2","c0220ac72c8668c7","dce0d347e9ad67cb","0108ed65d55f66e5","0df19651e9d47c89","1f2ae14226f8f2a4","2f6cacc4937ceef3","703af3c2779d3cf5"],"x":94,"y":379,"w":1612,"h":142},{"id":"60f0410cc18ffee9","type":"group","z":"d557eb264b53eeb0","name":"set NetAtmo credetials and start","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["fb90035c5ef5b644","551f9e6651a9f547","68711059597f7ccf","58fbce5537d2f00e","cd7cdb17d57e2264","18e55452af6627a7"],"x":94,"y":59,"w":552,"h":162},{"id":"ef5434100e820b14","type":"group","z":"d557eb264b53eeb0","name":"single HTTP request","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["60161afd811514a9","4a193c49e1768ca4","270c2571e554da91","477b057ce14583f1"],"x":104,"y":259,"w":482,"h":82},{"id":"a4f62c4a64ba8901","type":"group","z":"d557eb264b53eeb0","name":"error handling","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["44d2edbb03e5abfd","0faeaea554fc754d","bbfc8353d57ad7ed","e38f7a66d5d55cbd","d4721fd3bb1730ab","0e4979ab14b36035"],"x":94,"y":919,"w":732,"h":122},{"id":"8f7287410467fd3f","type":"group","z":"d557eb264b53eeb0","name":"Test Input","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["e541136a402b781c","1c0fa91ef5cd04aa"],"x":94,"y":1079,"w":432,"h":82},{"id":"f44dd0fb23b1a058","type":"inject","z":"d557eb264b53eeb0","g":"05a20f826b31f5bf","name":"refresh every 57 min","props":[{"p":"payload"}],"repeat":"3420","crontab":"","once":false,"onceDelay":"0","topic":"","payload":"","payloadType":"date","x":240,"y":440,"wires":[["1f2ae14226f8f2a4","0df19651e9d47c89"]]},{"id":"3b7c2e8aac54bd1a","type":"change","z":"d557eb264b53eeb0","g":"05a20f826b31f5bf","name":"Set param request & refresh","rules":[{"t":"set","p":"method","pt":"msg","to":"POST","tot":"str"},{"t":"set","p":"url","pt":"msg","to":"https://api.netatmo.com/oauth2/token","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"{\"grant_type\":\"refresh_token\",\"refresh_token\":$globalContext(\"NetatmoRefreshToken\"),\"client_id\":$globalContext(\"NetatmoClientId\"),\"client_secret\":$globalContext(\"NetatmoClientSecret\"),\"scope\": \"read_station\"}","tot":"jsonata"},{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers[\"content-type\"]","pt":"msg","to":"application/x-www-form-urlencoded","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":440,"wires":[["aa6ab32c346b7dc2"]]},{"id":"82a46256fef4c8f5","type":"change","z":"d557eb264b53eeb0","g":"05a20f826b31f5bf","name":"Store tokens & delay","rules":[{"t":"set","p":"NetatmoAccessToken","pt":"global","to":"payload.access_token","tot":"msg","dc":true},{"t":"set","p":"NetatmoRefreshToken","pt":"global","to":"payload.refresh_token","tot":"msg","dc":true},{"t":"set","p":"NetatmoLastUpdateTime","pt":"global","to":"","tot":"date"},{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":1380,"y":420,"wires":[["c0220ac72c8668c7"]]},{"id":"fb90035c5ef5b644","type":"change","z":"d557eb264b53eeb0","g":"60f0410cc18ffee9","name":"Set Netatmo Creds & Tokens","rules":[{"t":"set","p":"NetatmoClientId","pt":"global","to":"xxxxxxxxxxxxxxxxxxxxxxxxxx","tot":"str"},{"t":"set","p":"NetatmoClientSecret","pt":"global","to":"yyyyyyyyyyyyyyyyyyyyyyyyyyyy","tot":"str"},{"t":"set","p":"NetatmoAccessToken","pt":"global","to":"","tot":"str"},{"t":"set","p":"NetatmoRefreshToken","pt":"global","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":140,"wires":[[]]},{"id":"551f9e6651a9f547","type":"inject","z":"d557eb264b53eeb0","g":"60f0410cc18ffee9","name":"Set first credentials","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":230,"y":160,"wires":[["fb90035c5ef5b644","68711059597f7ccf"]]},{"id":"e89fc6f5d7b6be61","type":"switch","z":"d557eb264b53eeb0","g":"05a20f826b31f5bf","name":"access_token ok?","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"access_token","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1130,"y":440,"wires":[["82a46256fef4c8f5"],["0108ed65d55f66e5"]],"outputLabels":["Response OK","Error"]},{"id":"7737a67081eef4e8","type":"change","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"set pram request","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"method","pt":"msg","to":"GET","tot":"str"},{"t":"set","p":"url","pt":"msg","to":"https://api.netatmo.com/api/getstationsdata","tot":"str"},{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers[\"Authorization\"]","pt":"msg","to":"\"Bearer \" & $globalContext(\"NetatmoAccessToken\")\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":720,"wires":[["400352be8a87340e"]]},{"id":"0443074dd4250d9c","type":"inject","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"Get Netatmo Data","props":[{"p":"payload"}],"repeat":"300","crontab":"","once":false,"onceDelay":"10","topic":"","payload":"","payloadType":"date","x":230,"y":720,"wires":[["df92a998996ce415"]]},{"id":"3a5362954f199d3f","type":"inject","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"Test","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":760,"wires":[["df92a998996ce415"]]},{"id":"db5a4a411ed57be8","type":"switch","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"body?","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"body","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1090,"y":720,"wires":[["89225a8f357232c5","17d01814707624be","f1eec459e2893317","a1e6861787c7b9cd"],["a6600fbe65e81cc1"]]},{"id":"f1eec459e2893317","type":"mqtt out","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"Net_Atmo_record","topic":"Net_Atmo_record","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"99603ece.52e2a","x":1410,"y":720,"wires":[]},{"id":"17d01814707624be","type":"function","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"time / record counter","func":"let counter = context.get(\"counter\");\ncounter = counter + 1;\ncontext.set(\"counter\", counter);\n\nlet time = moment().tz(\"Europe/Berlin\").format(\"HH:mm:ss\");\nnode.status({ fill: \"green\", shape: \"dot\", text: time + \" / \" + counter });\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\n\ncontext.set(\"counter\", 0);\n","finalize":"","libs":[{"var":"moment","module":"moment"},{"var":"momentTimezone","module":"moment-timezone"}],"x":1420,"y":660,"wires":[[]]},{"id":"a1e6861787c7b9cd","type":"trigger","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"watchdog","op1":"","op2":"","op1type":"nul","op2type":"date","duration":"20","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1380,"y":780,"wires":[["949e6679a2befee3"]]},{"id":"6b8ba085179f4f56","type":"link out","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"link out 258","mode":"link","links":["d4721fd3bb1730ab"],"x":1625,"y":780,"wires":[]},{"id":"949e6679a2befee3","type":"function","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"watchdog","func":"let text = \"NetAtmo-Record länger als 20 min offline!\";\nreturn { payload: { 'room': 'error', 'value': text } };","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1520,"y":780,"wires":[["6b8ba085179f4f56"]]},{"id":"89225a8f357232c5","type":"debug","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"status","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload.status","targetType":"msg","statusVal":"payload.status","statusType":"auto","x":1370,"y":600,"wires":[]},{"id":"12cb8cc73743c2ce","type":"switch","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"object?","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"object","vt":"object"},{"t":"istype","v":"string","vt":"string"}],"checkall":"true","repair":false,"outputs":2,"x":940,"y":720,"wires":[["db5a4a411ed57be8"],["74f8e9dde28cfcb1"]]},{"id":"60161afd811514a9","type":"http request","z":"d557eb264b53eeb0","g":"ef5434100e820b14","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":430,"y":300,"wires":[["270c2571e554da91"]]},{"id":"4a193c49e1768ca4","type":"link in","z":"d557eb264b53eeb0","g":"ef5434100e820b14","name":"netatmo_request_in","links":[],"x":145,"y":300,"wires":[["60161afd811514a9"]]},{"id":"270c2571e554da91","type":"link out","z":"d557eb264b53eeb0","g":"ef5434100e820b14","name":"link out 273","mode":"return","links":[],"x":545,"y":300,"wires":[]},{"id":"400352be8a87340e","type":"link call","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"call request 2","links":["4a193c49e1768ca4"],"linkType":"static","timeout":"30","x":770,"y":720,"wires":[["12cb8cc73743c2ce","3adc726ebd0aa92a"]]},{"id":"aa6ab32c346b7dc2","type":"link call","z":"d557eb264b53eeb0","g":"05a20f826b31f5bf","name":"call request 1","links":["4a193c49e1768ca4"],"linkType":"static","timeout":"30","x":850,"y":440,"wires":[["e89fc6f5d7b6be61","2f6cacc4937ceef3"]]},{"id":"44d2edbb03e5abfd","type":"catch","z":"d557eb264b53eeb0","g":"a4f62c4a64ba8901","name":"All errors","scope":["400352be8a87340e","aa6ab32c346b7dc2","60161afd811514a9","4a193c49e1768ca4","960cea8488046a64","3adc726ebd0aa92a"],"uncaught":false,"x":180,"y":1000,"wires":[["e38f7a66d5d55cbd"]]},{"id":"0faeaea554fc754d","type":"link out","z":"d557eb264b53eeb0","g":"a4f62c4a64ba8901","name":"link out 300","mode":"link","links":["d3422b90f8530fb4"],"x":635,"y":1000,"wires":[]},{"id":"bbfc8353d57ad7ed","type":"debug","z":"d557eb264b53eeb0","g":"a4f62c4a64ba8901","name":"debug NetAtmo","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":700,"y":960,"wires":[]},{"id":"e38f7a66d5d55cbd","type":"function","z":"d557eb264b53eeb0","g":"a4f62c4a64ba8901","name":"Time + Fehlermeldung","func":"if (msg.payload.type === \"reset\"){\n node.status({ fill: \"green\", shape: \"dot\", text: \" \" });\n return null;\n}\n\nlet counter = context.get(\"counter\");\ncounter = counter + 1;\ncontext.set(\"counter\", counter);\n\nlet time = moment().tz(\"Europe/Berlin\").format(\"DD-MM-YYYY HH:mm:ss\");\n\nlet text = \"Fehlerzeitpunkt: \" + time + \" / \" +\n \"RPI 45\" + \" / \" +\n \"Flow: Netatmo New\" + \" / \" +\n \"Fehlermeldung: \" + msg.error.message + \" / \" +\n \"Fehler ID: \" + msg.error.source.id + \" / \" +\n \"Fehlertyp: \" + msg.error.source.type + \" / \" +\n \"Fehlernode: \" + msg.error.source.name + \" / \" +\n \"Fehlerzähler: \" + msg.error.source.count;\n \nnode.status({ fill: \"red\", shape: \"dot\", text: text + \" / \" + counter });\n\nreturn{payload:text};","outputs":1,"timeout":"","noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\nif (context.get(\"counter\") === undefined) {\n context.set(\"counter\", 0);\n}","finalize":"","libs":[{"var":"moment","module":"moment"},{"var":"momentTimezone","module":"moment-timezone"}],"x":440,"y":1000,"wires":[["0faeaea554fc754d"]]},{"id":"d4721fd3bb1730ab","type":"link in","z":"d557eb264b53eeb0","g":"a4f62c4a64ba8901","name":"debug","links":["198aa8893d75f395","e0b35f90dd344f8f","6b8ba085179f4f56"],"x":525,"y":960,"wires":[["bbfc8353d57ad7ed","0faeaea554fc754d"]]},{"id":"0e4979ab14b36035","type":"inject","z":"d557eb264b53eeb0","g":"a4f62c4a64ba8901","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"{\"type\":\"reset\"}","payloadType":"json","x":220,"y":960,"wires":[["e38f7a66d5d55cbd"]]},{"id":"c0220ac72c8668c7","type":"debug","z":"d557eb264b53eeb0","g":"05a20f826b31f5bf","name":"refresh-count","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"counter","x":1570,"y":420,"wires":[]},{"id":"dce0d347e9ad67cb","type":"function","z":"d557eb264b53eeb0","g":"05a20f826b31f5bf","name":"Error no access token ","func":"node.error(\"Error Netatmo access token: \", msg);\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1580,"y":480,"wires":[[]]},{"id":"0108ed65d55f66e5","type":"change","z":"d557eb264b53eeb0","g":"05a20f826b31f5bf","name":"set flow error true","rules":[{"t":"set","p":"error","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1370,"y":480,"wires":[["dce0d347e9ad67cb"]]},{"id":"0df19651e9d47c89","type":"switch","z":"d557eb264b53eeb0","g":"05a20f826b31f5bf","name":"error?","property":"error","propertyType":"flow","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":450,"y":440,"wires":[["3b7c2e8aac54bd1a"]]},{"id":"68711059597f7ccf","type":"delay","z":"d557eb264b53eeb0","g":"60f0410cc18ffee9","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":460,"y":180,"wires":[["58fbce5537d2f00e"]]},{"id":"58fbce5537d2f00e","type":"link out","z":"d557eb264b53eeb0","g":"60f0410cc18ffee9","name":"link out 301","mode":"link","links":["7f0d116c40b05764"],"x":595,"y":180,"wires":[]},{"id":"a6600fbe65e81cc1","type":"function","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"Error body","func":"node.error(\"Netatmo no body Error: \", msg);\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1390,"y":840,"wires":[[]]},{"id":"74f8e9dde28cfcb1","type":"function","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"Error object","func":"node.error(\"Netatmo no object Error: \", msg);\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1190,"y":840,"wires":[[]]},{"id":"e541136a402b781c","type":"mqtt in","z":"d557eb264b53eeb0","g":"8f7287410467fd3f","name":"","topic":"Net_Atmo_record","qos":"0","datatype":"auto-detect","broker":"99603ece.52e2a","nl":false,"rap":true,"rh":0,"inputs":0,"x":200,"y":1120,"wires":[["1c0fa91ef5cd04aa"]]},{"id":"1c0fa91ef5cd04aa","type":"debug","z":"d557eb264b53eeb0","g":"8f7287410467fd3f","name":"netatmo record","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":400,"y":1120,"wires":[]},{"id":"df92a998996ce415","type":"switch","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"error?","property":"error","propertyType":"flow","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":430,"y":720,"wires":[["7737a67081eef4e8"]]},{"id":"1f2ae14226f8f2a4","type":"function","z":"d557eb264b53eeb0","g":"05a20f826b31f5bf","name":"next refresh at","func":"let t_end = Date.now() + 57 * 60 * 1000;\nlet x = new Date(t_end);\nlet text = x.toLocaleTimeString();\nnode.status({ fill: \"red\", shape: \"dot\", text: text });\nreturn null;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":480,"wires":[[]]},{"id":"cd7cdb17d57e2264","type":"change","z":"d557eb264b53eeb0","g":"60f0410cc18ffee9","name":"","rules":[{"t":"set","p":"error","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":100,"wires":[[]]},{"id":"477b057ce14583f1","type":"change","z":"d557eb264b53eeb0","g":"ef5434100e820b14","name":"request timeout","rules":[{"t":"set","p":"requestTimeout","pt":"msg","to":"20000","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":300,"wires":[[]]},{"id":"18e55452af6627a7","type":"inject","z":"d557eb264b53eeb0","g":"60f0410cc18ffee9","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":100,"wires":[["cd7cdb17d57e2264"]]},{"id":"3adc726ebd0aa92a","type":"switch","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"= 200?","property":"statusCode","propertyType":"msg","rules":[{"t":"neq","v":"200","vt":"str"},{"t":"eq","v":"200","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":840,"wires":[["960cea8488046a64"],[]]},{"id":"960cea8488046a64","type":"function","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"Error != 200 2","func":"node.error(\"Statuscode != 200: \", msg);\nreturn null;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":980,"y":840,"wires":[[]]},{"id":"2f6cacc4937ceef3","type":"switch","z":"d557eb264b53eeb0","g":"05a20f826b31f5bf","name":"= 200?","property":"statusCode","propertyType":"msg","rules":[{"t":"neq","v":"200","vt":"str"},{"t":"eq","v":"200","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1010,"y":480,"wires":[["703af3c2779d3cf5"],[]]},{"id":"703af3c2779d3cf5","type":"function","z":"d557eb264b53eeb0","g":"05a20f826b31f5bf","name":"Error != 200 1","func":"node.error(\"Statuscode != 200: \", msg);\nreturn null;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1160,"y":480,"wires":[[]]},{"id":"7f0d116c40b05764","type":"link in","z":"d557eb264b53eeb0","g":"d508edfc10ca96d0","name":"link in 203","links":["58fbce5537d2f00e"],"x":305,"y":680,"wires":[["df92a998996ce415"]]},{"id":"99603ece.52e2a","type":"mqtt-broker","broker":"10.0.0.43","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":4,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]
yes, I know.
Unfortunately I had some troubles with NetAtmo account due to too many requests - most probably
because I ran my application (potman) and oauth2in parallel. This took some time to fix it.
I am just working on integrating it into my flow.
I am taking the output of oauth2 and put it into my globals.
and run it with my flow.
btw - I found, that if you get your data every 5 min you should not have the refresh interval at a time that could be divided by 5. Lets say not 55 but 57min assuming both start a the same time.
I am not sure what you are saying. there is an authorisation part with a scope, for which you need to use a browser (oauth2 is really focussed on mobile which makes it so cumbersome), from which an access token is returned and a refresh token, which has an expiration time and needs to be refreshed ever so often to keep the validity of the access token (in case of netatmo it is 10800 seconds), while the token is valid you can query as much as the api allows.
Finaly it works and you are right!
This is the best solution!
Many thanks for your support
![]()
[{"id":"999dfdb30289d3e3","type":"tab","label":"NetAtmo Station Data","disabled":false,"info":"","env":[]},{"id":"5272032c77a66b98","type":"group","z":"999dfdb30289d3e3","name":"setup credentials","style":{"label":true,"fill":"#ffefbf","fill-opacity":"0.18"},"nodes":["6e08afb36e7f96f5","145a182f704b76ac","d2cc08c89ff1d00f","8c4a4fcc63ce3978","60d9f744b1e07999","f64122e6596886fc","05f984fb87660d8f","3d527fa8ed4c1cfa","60ae9a4aeb1d38e4"],"x":354,"y":179,"w":642,"h":142},{"id":"75782c100f960c0c","type":"group","z":"999dfdb30289d3e3","name":"","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["aecdb575a82f1861","19ad1fa190620d37","1030561746bc5493","3452925d5ab99995","58283c72ded21f3a","e1d21a232577dec5","441df4bb7c2529c4","680d790b9a320732","99765cb02d0d44cd","0795e6725bcb0437","9192ea574d6e3ebe","afb5b58294ab7b9f","56523039f55483c3"],"x":354,"y":359,"w":1252,"h":322},{"id":"f8330cd67bea0c0a","type":"group","z":"999dfdb30289d3e3","name":"","style":{"fill":"#ffefbf","fill-opacity":"0.18","label":true},"nodes":["341c320f0b5b02a9","2d5c1a99a92ecf5f"],"x":354,"y":719,"w":432,"h":82},{"id":"aecdb575a82f1861","type":"inject","z":"999dfdb30289d3e3","g":"75782c100f960c0c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"300","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":470,"y":520,"wires":[["1030561746bc5493"]]},{"id":"19ad1fa190620d37","type":"http request","z":"999dfdb30289d3e3","g":"75782c100f960c0c","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":765,"y":520,"wires":[["9192ea574d6e3ebe"]],"l":false},{"id":"1030561746bc5493","type":"function","z":"999dfdb30289d3e3","g":"75782c100f960c0c","name":"get public data","func":"const access_token = global.get('netatmo_oauth2').token.access_token\n\nmsg.headers = {};\n\nmsg.headers[\"Authorization\"] = `Bearer ${access_token}`\n\nmsg.url = \"https://api.netatmo.com/api/getstationsdata\";\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":520,"wires":[["19ad1fa190620d37"]]},{"id":"6e08afb36e7f96f5","type":"oauth2","z":"999dfdb30289d3e3","g":"5272032c77a66b98","name":"Authorization Code","container":"oauth2Response","grant_type":"authorization_code","access_token_url":"https://api.netatmo.com/oauth2/token","authorization_endpoint":"https://api.netatmo.com/oauth2/authorize","redirect_uri":"http://10.0.0.206:1880/oauth2/redirect","open_authentication":"","username":"","password":"","client_id":"","client_secret":"","response_type":"","access_type":"","refresh_token":"","prompt":"","scope":"read_station","resource":"","state":"","proxy":"","debug":false,"force":false,"senderr":false,"client_credentials_in_body":false,"rejectUnauthorized":true,"headers":{},"x":630,"y":220,"wires":[["f64122e6596886fc"]]},{"id":"145a182f704b76ac","type":"inject","z":"999dfdb30289d3e3","g":"5272032c77a66b98","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":460,"y":220,"wires":[["6e08afb36e7f96f5"]]},{"id":"d2cc08c89ff1d00f","type":"inject","z":"999dfdb30289d3e3","g":"5272032c77a66b98","name":"Refresh Token","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3300","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":480,"y":280,"wires":[["3d527fa8ed4c1cfa"]]},{"id":"8c4a4fcc63ce3978","type":"oauth2","z":"999dfdb30289d3e3","g":"5272032c77a66b98","name":"Set by msg.oauth2Request","container":"oauth2Response","grant_type":"set_by_credentials","access_token_url":"http://localhost:3000/oauth/token ","authorization_endpoint":"","redirect_uri":"http://10.0.0.67:1880/oauth2/redirect","open_authentication":"","username":"","password":"","client_id":"","client_secret":"","response_type":"","access_type":"","refresh_token":"","prompt":"","scope":"*","resource":"","state":"","proxy":"","debug":true,"force":true,"senderr":false,"client_credentials_in_body":true,"rejectUnauthorized":true,"headers":{},"x":755,"y":280,"wires":[["60ae9a4aeb1d38e4"]],"l":false},{"id":"60d9f744b1e07999","type":"debug","z":"999dfdb30289d3e3","g":"5272032c77a66b98","name":"DBG 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":900,"y":280,"wires":[]},{"id":"f64122e6596886fc","type":"function","z":"999dfdb30289d3e3","g":"5272032c77a66b98","name":"Set refreshToken","func":"const access_token_url = \"https://api.netatmo.com/oauth2/token\"\n\nif (msg.oauth2Response.access_token) {\n const netatmo_oauth2 = {}\n netatmo_oauth2.url = access_token_url\n netatmo_oauth2.token = msg.oauth2Response\n\n global.set(\"netatmo_oauth2\", netatmo_oauth2)\n}\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":755,"y":220,"wires":[["05f984fb87660d8f"]],"l":false},{"id":"05f984fb87660d8f","type":"debug","z":"999dfdb30289d3e3","g":"5272032c77a66b98","name":"DBG 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":220,"wires":[]},{"id":"3d527fa8ed4c1cfa","type":"function","z":"999dfdb30289d3e3","g":"5272032c77a66b98","name":"credentials","func":"let netatmo = global.get('netatmo_oauth2');\n\nmsg.oauth2Request = { \n \"access_token_url\": netatmo.url,\n \"credentials\": {\n \"grant_type\": \"refresh_token\",\n \"client_id\": \"\",\n \"client_secret\": \"\",\n \"scope\": \"read_station\",\n \"refresh_token\": netatmo.token.refresh_token \n },\n};\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":280,"wires":[["8c4a4fcc63ce3978"]]},{"id":"60ae9a4aeb1d38e4","type":"function","z":"999dfdb30289d3e3","g":"5272032c77a66b98","name":"Set refreshToken","func":"const access_token_url = \"https://api.netatmo.com/oauth2/token\"\n\nif (msg.oauth2Response.access_token) {\n const netatmo_oauth2 = {}\n netatmo_oauth2.url = access_token_url\n netatmo_oauth2.token = msg.oauth2Response\n\n global.set(\"netatmo_oauth2\", netatmo_oauth2)\n}\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":805,"y":280,"wires":[["60d9f744b1e07999"]],"l":false},{"id":"3452925d5ab99995","type":"switch","z":"999dfdb30289d3e3","g":"75782c100f960c0c","name":"body?","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"body","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1030,"y":520,"wires":[["0795e6725bcb0437","e1d21a232577dec5","58283c72ded21f3a","441df4bb7c2529c4"],["afb5b58294ab7b9f"]]},{"id":"58283c72ded21f3a","type":"mqtt out","z":"999dfdb30289d3e3","g":"75782c100f960c0c","name":"Net_Atmo_record","topic":"Net_Atmo_record","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"99603ece.52e2a","x":1350,"y":520,"wires":[]},{"id":"e1d21a232577dec5","type":"function","z":"999dfdb30289d3e3","g":"75782c100f960c0c","name":"time / record counter","func":"let counter = context.get(\"counter\");\ncounter = counter + 1;\ncontext.set(\"counter\", counter);\n\nlet time = moment().tz(\"Europe/Berlin\").format(\"HH:mm:ss\");\nnode.status({ fill: \"green\", shape: \"dot\", text: time + \" / \" + counter });\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\n\ncontext.set(\"counter\", 0);\n","finalize":"","libs":[{"var":"moment","module":"moment"},{"var":"momentTimezone","module":"moment-timezone"}],"x":1360,"y":460,"wires":[[]]},{"id":"441df4bb7c2529c4","type":"trigger","z":"999dfdb30289d3e3","g":"75782c100f960c0c","name":"watchdog","op1":"","op2":"","op1type":"nul","op2type":"date","duration":"20","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1320,"y":580,"wires":[["99765cb02d0d44cd"]]},{"id":"680d790b9a320732","type":"link out","z":"999dfdb30289d3e3","g":"75782c100f960c0c","name":"link out 258","mode":"link","links":[],"x":1565,"y":580,"wires":[]},{"id":"99765cb02d0d44cd","type":"function","z":"999dfdb30289d3e3","g":"75782c100f960c0c","name":"watchdog","func":"let text = \"NetAtmo-Record länger als 20 min offline!\";\nreturn { payload: { 'room': 'error', 'value': text } };","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1460,"y":580,"wires":[["680d790b9a320732"]]},{"id":"0795e6725bcb0437","type":"debug","z":"999dfdb30289d3e3","g":"75782c100f960c0c","name":"status","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload.status","targetType":"msg","statusVal":"payload.status","statusType":"auto","x":1310,"y":400,"wires":[]},{"id":"9192ea574d6e3ebe","type":"switch","z":"999dfdb30289d3e3","g":"75782c100f960c0c","name":"object?","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"object","vt":"object"},{"t":"istype","v":"string","vt":"string"}],"checkall":"true","repair":false,"outputs":2,"x":880,"y":520,"wires":[["3452925d5ab99995"],["56523039f55483c3"]]},{"id":"afb5b58294ab7b9f","type":"function","z":"999dfdb30289d3e3","g":"75782c100f960c0c","name":"Error body","func":"node.error(\"Netatmo no body Error: \", msg);\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1330,"y":640,"wires":[[]]},{"id":"56523039f55483c3","type":"function","z":"999dfdb30289d3e3","g":"75782c100f960c0c","name":"Error object","func":"node.error(\"Netatmo no object Error: \", msg);\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":640,"wires":[[]]},{"id":"341c320f0b5b02a9","type":"mqtt in","z":"999dfdb30289d3e3","g":"f8330cd67bea0c0a","name":"","topic":"Net_Atmo_record","qos":"0","datatype":"auto-detect","broker":"99603ece.52e2a","nl":false,"rap":true,"rh":0,"inputs":0,"x":460,"y":760,"wires":[["2d5c1a99a92ecf5f"]]},{"id":"2d5c1a99a92ecf5f","type":"debug","z":"999dfdb30289d3e3","g":"f8330cd67bea0c0a","name":"debug 2527","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":760,"wires":[]},{"id":"99603ece.52e2a","type":"mqtt-broker","broker":"10.0.0.43","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":4,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]



