ssadams11 / node-red-contrib-netatmo

Some Node-red nodes for acting the Netatmo sensor APIs
Apache License 2.0
8 stars 17 forks source link

added get public data - node #11

Closed osos closed 6 years ago

osos commented 6 years ago

Added the possibiliti to use NetAtmos getPublicData API.

This requires an update to netatmo library. Thus this PR is conditional of https://github.com/karbassi/netatmo/pull/38

karbassi commented 6 years ago

karbassi/netatmo#38 merged.

jensfr1 commented 5 years ago

Do you have an example flow for this?

ssadams11 commented 5 years ago

I don't have access to a device anymore to test these, and the Netatmo APIs may have changed, but I hope this gives you an idea. Regards, Sam

On Dec 21, 2018, at 6:04 AM, jensfr1 notifications@github.com wrote:

Do you have an example flow for this?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ssadams11/node-red-contrib-netatmo/pull/11#issuecomment-449359320, or mute the thread https://github.com/notifications/unsubscribe-auth/AE9qWtfYrSePDRk7XpljO5oF_bVS6g1vks5u7MBDgaJpZM4SoOYn.

[{"id":"b7c1d784.b35e7","type":"tab","label":"Netatmo Weather"},{"id":"9d07661c.c00688","type":"http response","z":"b7c1d784.b35e7","name":"","x":781,"y":661,"wires":[]},{"id":"e74ab1ac.5f627","type":"debug","z":"b7c1d784.b35e7","name":"","active":true,"console":"false","complete":"false","x":542,"y":566,"wires":[]},{"id":"181114d2.3d2f5b","type":"http in","z":"b7c1d784.b35e7","name":"","url":"/netatmo/weather/all","method":"get","swaggerDoc":"","x":122,"y":576,"wires":[["f0614009.b0d0b"]]},{"id":"bc972497.b59bf8","type":"inject","z":"b7c1d784.b35e7","name":"Do it now","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":117,"y":615,"wires":[["f0614009.b0d0b"]]},{"id":"c7e9079a.6580d8","type":"inject","z":"b7c1d784.b35e7","name":"do it now","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":234,"y":86,"wires":[["50a5a141.bed38"]]},{"id":"9a94ead1.237348","type":"debug","z":"b7c1d784.b35e7","name":"","active":true,"console":"false","complete":"false","x":658,"y":72,"wires":[]},{"id":"82b8d06a.bea768","type":"http in","z":"b7c1d784.b35e7","name":"","url":"/netatmo/weather/devices","method":"get","swaggerDoc":"","x":225,"y":144,"wires":[["50a5a141.bed38"]]},{"id":"51f14c9e.7b4d34","type":"http response","z":"b7c1d784.b35e7","name":"","x":677,"y":172,"wires":[]},{"id":"93f3dd4c.a6829","type":"comment","z":"b7c1d784.b35e7","name":"Get the latest weather readings","info":"","x":193,"y":34,"wires":[]},{"id":"136a8abb.6009bd","type":"comment","z":"b7c1d784.b35e7","name":"Get the latest weather readings every 5 minutes and drive to IBM IOT","info":"","x":266,"y":220,"wires":[]},{"id":"ea479688.24623","type":"debug","z":"b7c1d784.b35e7","name":"","active":true,"console":"false","complete":"false","x":641,"y":266,"wires":[]},{"id":"333221e9.3d471e","type":"inject","z":"b7c1d784.b35e7","name":"Every 10 minutes","topic":"","payload":"","payloadType":"date","repeat":"600","crontab":"","once":false,"x":121,"y":277,"wires":[["6ae4eb9b.68e704"]]},{"id":"9cc4c67f.d13aa8","type":"function","z":"b7c1d784.b35e7","name":"Split out readings from all modules","func":"readings = [];\n//do the main module first\ndata = msg.payload.devices[0].dashboard_data;\ntimestamp = (new Date(data.time_utc1000)).toISOString();\nreadings.push(\n {displayName: msg.payload.devices[0].module_name, \n timestamp: timestamp,\n temperature: Math.trunc((data.Temperature 9 / 5 + 32)100)/100, //convert to F from C\n noise: data.Noise,\n humidity: data.Humidity,\n CO2: data.CO2,\n pressure: data.Pressure\n });\n//now for the remote modules\nfor (var mod of msg.payload.devices[0].modules){\n node.log(mod);\n if (mod.type == \"NAModule1\") { //this is an outdoor module\n data = mod.dashboard_data;\n timestamp = (new Date(data.time_utc1000)).toISOString();\n displayName = mod.module_name;\n readings.push(\n {displayName: displayName, \n timestamp: timestamp,\n temperature: Math.trunc((data.Temperature 9 / 5 + 32)100)/100, //convert to F from C\n humidity: data.Humidity,\n });\n }\n if (mod.type == \"NAModule4\") { //this is an indoor remote module\n data = mod.dashboard_data;\n timestamp = (new Date(data.time_utc1000)).toISOString();\n displayName = mod.module_name;\n readings.push(\n {displayName: displayName, \n timestamp: timestamp,\n temperature: Math.trunc((data.Temperature 9 / 5 + 32)100)/100, //convert to F from C\n humidity: data.Humidity,\n CO2: data.CO2,\n });\n }\n}\nmsg.payload = readings;\nreturn msg;","outputs":1,"noerr":0,"x":358,"y":333,"wires":[["74bf8594.a6edac"]]},{"id":"74bf8594.a6edac","type":"split","z":"b7c1d784.b35e7","name":"Split 1 event/module","splt":"\n","x":635,"y":331,"wires":[["968653f0.e1e788"]]},{"id":"968653f0.e1e788","type":"function","z":"b7c1d784.b35e7","name":"Split into smartthings-style events","func":"events = [];\nd = msg.payload;\ndisplayName = d.displayName;\ntimestamp = d.timestamp;\nevents.push({displayName: displayName, timestamp: timestamp, temperature: d.temperature});\nif (d.humidity){events.push({displayName: displayName, timestamp: timestamp, humidity: d.humidity})}\nif (d.noise){events.push({displayName: displayName, timestamp: timestamp, noise: d.noise})}\nif (d.CO2){events.push({displayName: displayName, timestamp: timestamp, CO2: d.CO2})}\nif (d.pressure){events.push({displayName: displayName, timestamp: timestamp, pressure: d.pressure})}\nmsg.payload = events;\nreturn msg;","outputs":1,"noerr":0,"x":189,"y":383,"wires":[["c43a434.98f784"]]},{"id":"c43a434.98f784","type":"split","z":"b7c1d784.b35e7","name":"Split 1 event/module","splt":"\n","x":457,"y":383,"wires":[["74e1a902.72da08"]]},{"id":"8dc86661.c08a88","type":"debug","z":"b7c1d784.b35e7","name":"","active":true,"console":"false","complete":"false","x":706,"y":450,"wires":[]},{"id":"74e1a902.72da08","type":"function","z":"b7c1d784.b35e7","name":"target the smartthings eventType using the key in the payload","func":"d = msg.payload;\nif (d.temperature){msg.eventOrCommandType = 'temperature'}\nif (d.humidity){msg.eventOrCommandType = 'humidity'}\nif (d.pressure){msg.eventOrCommandType = 'pressure'}\nif (d.noise){msg.eventOrCommandType = 'noise'}\nif (d.CO2){msg.eventOrCommandType = 'CO2'}\nts = msg.payload.timestamp;\nts = new Date(ts);\n/\nmsg.payload.year = ts.getFullYear();\nmsg.payload.month = ts.getMonth()+1;\nmsg.payload.dayOfMonth = ts.getDate();\nmsg.payload.hours = ts.getHours();\nmsg.payload.minutes = ts.getMinutes();\nmsg.payload.seconds = ts.getSeconds();\nmsg.payload.milliseconds = ts.getMilliseconds();\nmsg.payload.timezoneOffset = ts.getTimezoneOffset();\n/\nreturn msg;","outputs":1,"noerr":0,"x":313,"y":438,"wires":[["8dc86661.c08a88"]]},{"id":"f4b9acbf.02001","type":"comment","z":"b7c1d784.b35e7","name":"Get all weather readings on the devices","info":"","x":155,"y":535,"wires":[]},{"id":"2c483626.1ee27a","type":"function","z":"b7c1d784.b35e7","name":"allow CORS","func":"msg.headers =\n{\n 'Access-Control-Allow-Origin': '',\n 'Content-Type': 'text/plain',\n };\nreturn msg;","outputs":1,"noerr":0,"x":656,"y":612,"wires":[["9d07661c.c00688"]]},{"id":"bec77606.a6a19","type":"function","z":"b7c1d784.b35e7","name":"allow CORS","func":"msg.headers =\n{\n 'Access-Control-Allow-Origin': '',\n 'Content-Type': 'text/plain',\n };\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":120,"wires":[["51f14c9e.7b4d34"]]},{"id":"ed0238bf.222898","type":"function","z":"b7c1d784.b35e7","name":"Split out readings from all modules","func":"readings = [];\n//do the main module first\ndata = msg.payload.devices[0].dashboard_data;\ntimestamp = (new Date(data.time_utc1000)).toISOString();\nreadings.push(\n {displayName: msg.payload.devices[0].module_name, \n timestamp: timestamp,\n temperature: Math.trunc((data.Temperature 9 / 5 + 32)100)/100, //convert to F from C\n noise: data.Noise,\n humidity: data.Humidity,\n CO2: data.CO2,\n pressure: data.Pressure\n });\n//now for the remote modules\n\nfor (var mod of msg.payload.devices[0].modules){\n node.log(mod);\n if (mod.type == \"NAModule1\") { //this is an outdoor module\n data = mod.dashboard_data;\n timestamp = (new Date(data.time_utc1000)).toISOString();\n displayName = mod.module_name;\n readings.push(\n {displayName: displayName, \n timestamp: timestamp,\n temperature: Math.trunc((data.Temperature 9 / 5 + 32)100)/100, //convert to F from C\n humidity: data.Humidity,\n });\n }\n if (mod.type == \"NAModule4\") { //this is an indoor remote module\n data = mod.dashboard_data;\n timestamp = (new Date(data.time_utc1000)).toISOString();\n displayName = mod.module_name;\n readings.push(\n {displayName: displayName, \n timestamp: timestamp,\n temperature: Math.trunc((data.Temperature 9 / 5 + 32)100)/100, //convert to F from C\n humidity: data.Humidity,\n CO2: data.CO2,\n });\n }\n}\n\nmsg.payload = readings;\nreturn msg;","outputs":1,"noerr":0,"x":403,"y":1102,"wires":[["8384d986.51ad18"]]},{"id":"8384d986.51ad18","type":"split","z":"b7c1d784.b35e7","name":"Split 1 event/module","splt":"\n","x":680,"y":1100,"wires":[["d4ee62a9.a5372"]]},{"id":"d4ee62a9.a5372","type":"function","z":"b7c1d784.b35e7","name":"Split into smartthings-style events","func":"events = [];\nd = msg.payload;\ndisplayName = d.displayName;\ntimestamp = d.timestamp;\nevents.push({displayName: displayName, timestamp: timestamp, temperature: d.temperature});\nif (d.humidity){events.push({displayName: displayName, timestamp: timestamp, humidity: d.humidity})}\nif (d.noise){events.push({displayName: displayName, timestamp: timestamp, noise: d.noise})}\nif (d.CO2){events.push({displayName: displayName, timestamp: timestamp, CO2: d.CO2})}\nif (d.pressure){events.push({displayName: displayName, timestamp: timestamp, pressure: d.pressure})}\nmsg.payload = events;\nreturn msg;","outputs":1,"noerr":0,"x":234,"y":1152,"wires":[["f8c1ce3f.6b9ee8"]]},{"id":"b718f630.17689","type":"inject","z":"b7c1d784.b35e7","name":"Push me","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":136,"y":1046,"wires":[["95fc2125.7925b"]]},{"id":"17cb7d05.82bb8b","type":"debug","z":"b7c1d784.b35e7","name":"","active":true,"console":"false","complete":"false","x":686,"y":1035,"wires":[]},{"id":"f8c1ce3f.6b9ee8","type":"split","z":"b7c1d784.b35e7","name":"Split 1 event/module","splt":"\n","x":502,"y":1152,"wires":[["60677792.5938a"]]},{"id":"60677792.5938a","type":"function","z":"b7c1d784.b35e7","name":"target the smartthings eventType using the key in the payload","func":"d = msg.payload;\nif (d.temperature){msg.eventOrCommandType = 'temperature'}\nif (d.humidity){msg.eventOrCommandType = 'humidity'}\nif (d.pressure){msg.eventOrCommandType = 'pressure'}\nif (d.noise){msg.eventOrCommandType = 'noise'}\nif (d.CO2){msg.eventOrCommandType = 'CO2'}\nts = msg.payload.timestamp;\nts = new Date(ts);\nmsg.payload.year = ts.getFullYear();\nmsg.payload.month = ts.getMonth()+1;\nmsg.payload.dayOfMonth = ts.getDate();\nmsg.payload.hours = ts.getHours();\nmsg.payload.minutes = ts.getMinutes();\nmsg.payload.seconds = ts.getSeconds();\nmsg.payload.milliseconds = ts.getMilliseconds();\nmsg.payload.timezoneOffset = ts.getTimezoneOffset();\nreturn msg;","outputs":1,"noerr":0,"x":358,"y":1207,"wires":[["d9974ee9.69337"]]},{"id":"d9974ee9.69337","type":"debug","z":"b7c1d784.b35e7","name":"","active":true,"console":"false","complete":"false","x":751,"y":1219,"wires":[]},{"id":"377b4480.31a684","type":"function","z":"b7c1d784.b35e7","name":"allow CORS","func":"msg.headers =\n{\n 'Access-Control-Allow-Origin': '*',\n 'Content-Type': 'text/plain',\n };\nreturn msg;","outputs":1,"noerr":0,"x":592,"y":984,"wires":[["6aaa0b40.c243dc"]]},{"id":"6aaa0b40.c243dc","type":"http response","z":"b7c1d784.b35e7","name":"","x":762,"y":969,"wires":[]},{"id":"7383bd1f.8eae84","type":"http in","z":"b7c1d784.b35e7","name":"","url":"/netatmo/weather/data","method":"get","swaggerDoc":"","x":247,"y":976,"wires":[["95fc2125.7925b"]]},{"id":"a877acca.4cf13","type":"comment","z":"b7c1d784.b35e7","name":"Use below to test get and parse of netatmo data","info":"","x":223,"y":879,"wires":[]},{"id":"f0614009.b0d0b","type":"get measurements","z":"b7c1d784.b35e7","name":"Get is all","scale":"max","types":"Temperature,CO2,Humidity,Pressure,Noise","creds":"2e0d17df.c9d518","x":299,"y":673,"wires":[["e74ab1ac.5f627","2c483626.1ee27a"]]},{"id":"50a5a141.bed38","type":"get stations data","z":"b7c1d784.b35e7","name":"","creds":"2e0d17df.c9d518","x":453,"y":73,"wires":[["9a94ead1.237348","bec77606.a6a19"]]},{"id":"6ae4eb9b.68e704","type":"get stations data","z":"b7c1d784.b35e7","name":"","creds":"2e0d17df.c9d518","x":352,"y":266,"wires":[["ea479688.24623","9cc4c67f.d13aa8"]]},{"id":"95fc2125.7925b","type":"get stations data","z":"b7c1d784.b35e7","name":"","creds":"2e0d17df.c9d518","x":397,"y":1035,"wires":[["17cb7d05.82bb8b","ed0238bf.222898","377b4480.31a684"]]}]

karbassi commented 5 years ago

Formatted json listed above:

https://gist.githubusercontent.com/karbassi/80b379243a56e3afc2ba902b35d85649/raw/58466c48a0056db7f17ed4ad908481dffecca766/data.json

jensfr1 commented 5 years ago

Thanks, it is still working and I am using it for some time already for my station. Just fiund the public api but also made it to work. Somehow just a bit tricky as the ID's change all the time...