NetAtmo get station data

Finaly it works and you are right!
This is the best solution!
Many thanks for your support :clap: :+1:

[{"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":""}]
1 Like