[ { "id": "70a2ced4.8f5d3", "type": "subflow", "name": "Update CloudantDB", "in": [ { "x": 57.500000953674316, "y": 91.25000190734863, "wires": [ { "id": "505c711a.afa39" } ] } ], "out": [] }, { "id": "505c711a.afa39", "type": "function", "z": "70a2ced4.8f5d3", "name": "Query CloudantDB for _rev", "func": "msg.payload={\n \"_id\":\"tokens\"\n};\nreturn msg;", "outputs": 1, "noerr": 0, "x": 223.75, "y": 91.25000095367432, "wires": [ [ "30f557f3.cf0aa8" ] ] }, { "id": "30f557f3.cf0aa8", "type": "cloudant in", "z": "70a2ced4.8f5d3", "service": "MeissenNodeRed-cloudantNoSQLDB", "cloudant": "", "name": "", "database": "ecobee_authtokens", "search": "_id_", "design": "", "index": "", "x": 466.25003814697266, "y": 91.25000381469727, "wires": [ [ "48e2f10b.b71d1" ] ] }, { "id": "48e2f10b.b71d1", "type": "function", "z": "70a2ced4.8f5d3", "name": "Update CloudantDB with new Tokens", "func": "context.global.Ecobee._rev = msg.payload._rev;\nmsg.payload={\n \"_id\":\"tokens\",\n \"_rev\":context.global.Ecobee._rev,\n \"access_token\":context.global.Ecobee.access_token,\n \"refresh_token\":context.global.Ecobee.refresh_token\n}\nreturn msg;", "outputs": 1, "noerr": 0, "x": 745.0000152587891, "y": 91.25000190734863, "wires": [ [ "2a943f1f.d56bc" ] ] }, { "id": "2a943f1f.d56bc", "type": "cloudant out", "z": "70a2ced4.8f5d3", "service": "MeissenNodeRed-cloudantNoSQLDB", "cloudant": "", "name": "", "database": "ecobee_authtokens", "payonly": true, "operation": "insert", "x": 1018.7500152587891, "y": 91.25000190734863, "wires": [] }, { "id": "33a2da81.cc5d26", "type": "inject", "z": "720116ea.8dfee8", "name": "Refresh Thermostat Data", "topic": "", "payload": "Refresh Thermostat Variables", "payloadType": "string", "repeat": "", "crontab": "", "once": false, "x": 148.25, "y": 442.52778816223145, "wires": [ [ "1a38d2f0.e5c72d" ] ] }, { "id": "b6a3b3e7.495c5", "type": "function", "z": "720116ea.8dfee8", "name": "Get ecobeePin Token", "func": "// Insert your Ecobee API Key into the following variable:\ncontext.global.Ecobee = {};\ncontext.global.Ecobee.ClientID=\"UiCU6RADRiIjZDO00bJm8nZo1XD81B7G\";\n// Insert your Ecobee API key into the above variable.\n\nvar newMsg ={\n \"url\":\"https://api.ecobee.com/authorize?response_type=ecobeePin&client_id=\"+context.global.Ecobee.ClientID+\"&scope=smartWrite\",\n \"method\": \"GET\",\n headers: {\n }\n};\nreturn newMsg;", "outputs": 1, "noerr": 0, "x": 272.3333435058594, "y": 90.49999809265137, "wires": [ [ "6ce3b2e5.931c4c", "b8425377.47bdb" ] ] }, { "id": "1a3e3501.e5c1cb", "type": "debug", "z": "720116ea.8dfee8", "name": "", "active": true, "console": "true", "complete": "payload", "x": 987.333251953125, "y": 90.25, "wires": [] }, { "id": "6ce3b2e5.931c4c", "type": "http request", "z": "720116ea.8dfee8", "name": "", "method": "use", "ret": "obj", "url": "", "x": 479.3333435058594, "y": 90.74999809265137, "wires": [ [ "1ceb2c88.e314d3" ] ] }, { "id": "e2c24dd3.1d3db", "type": "function", "z": "720116ea.8dfee8", "name": "Get Thermostats", "func": "if (context.global.Ecobee.refresh_token!==\"\")\n{\n var newMsg={\n \"url\":\"https://api.ecobee.com/1/thermostat?format=json&body=%7B%22selection%22%3A%7B%22includeAlerts%22%3A%22false%22%2C%22selectionType%22%3A%22registered%22%2C%22selectionMatch%22%3A%22%22%2C%22includeEvents%22%3A%22false%22%2C%22includeSettings%22%3A%22false%22%2C%22includeRuntime%22%3A%22true%22%2C%22includeSensors%22%3A%22true%22%7D%7D\",\n \"method\": \"GET\",\n headers: {\n \"Content-Type\":\"application/json;charset=UTF-8\",\n \"Authorization\":\"Bearer \"+context.global.Ecobee.access_token,\n }\n };\n}\nelse {\n var newMsg={\n \"url\":\"127.0.0.1\",\n \"method\":\"GET\"\n }\n}\nreturn newMsg;", "outputs": 1, "noerr": 0, "x": 500.5, "y": 442.02778816223145, "wires": [ [ "fec22be4.013dd8" ] ] }, { "id": "99500075.66b", "type": "debug", "z": "720116ea.8dfee8", "name": "", "active": false, "console": "true", "complete": "payload", "x": 1128.6388244628906, "y": 442.0278043746948, "wires": [] }, { "id": "fec22be4.013dd8", "type": "http request", "z": "720116ea.8dfee8", "name": "Get Thermostat Request", "method": "use", "ret": "obj", "url": "", "x": 712.7499694824219, "y": 442.02778816223145, "wires": [ [ "16e42b28.e91bd5", "24b75d7f.db48a2" ] ] }, { "id": "ad8940c6.5276c", "type": "inject", "z": "720116ea.8dfee8", "name": "Refresh token every 30 minutes", "topic": "", "payload": "", "payloadType": "none", "repeat": "", "crontab": "", "once": false, "x": 166.58334350585938, "y": 331.27778816223145, "wires": [ [ "4cf409f8.b30bf8" ] ] }, { "id": "4cf409f8.b30bf8", "type": "function", "z": "720116ea.8dfee8", "name": "Refresh Token", "func": "context.global.Ecobee.ClientID=\"UiCU6RADRiIjZDO00bJm8nZo1XD81B7G\";\n//context.global.EcobeeRefreshToken=\"\";\nvar newMsg ={\n \"url\":\"https://api.ecobee.com/token?grant_type=refresh_token&code=\"+context.global.Ecobee.refresh_token+\"&client_id=\"+context.global.Ecobee.ClientID+\"\",\n \"method\": \"POST\",\n headers: {\n }\n};\nreturn newMsg;", "outputs": 1, "noerr": 0, "x": 394, "y": 331.27778816223145, "wires": [ [ "f896bb42.076948" ] ] }, { "id": "f896bb42.076948", "type": "http request", "z": "720116ea.8dfee8", "name": "", "method": "use", "ret": "obj", "url": "", "x": 563.75, "y": 331.02778816223145, "wires": [ [ "466fa555.b9905c", "8bace55b.745318" ] ] }, { "id": "e99ff3b1.16601", "type": "function", "z": "720116ea.8dfee8", "name": "Define Access and Refresh Token vars", "func": "context.global.Ecobee.access_token=msg.payload.access_token;\ncontext.global.Ecobee.refresh_token=msg.payload.refresh_token;\nnode.warn(\"Tokens refreshed successfully.\");\nmsg.payload={\n \"_id\":\"tokens\",\n \"_rev\":context.global.Ecobee._rev,\n \"access_token\":context.global.Ecobee.access_token,\n \"refresh_token\":context.global.Ecobee.refresh_token\n};\nreturn msg;", "outputs": 1, "noerr": 0, "x": 980, "y": 337.52778816223145, "wires": [ [ "d29c3ecb.2d63c" ] ] }, { "id": "20b5ed3a.df4a12", "type": "debug", "z": "720116ea.8dfee8", "name": "", "active": false, "console": "false", "complete": "payload", "x": 1238.75, "y": 383.27778816223145, "wires": [] }, { "id": "cc0c7641.33f388", "type": "comment", "z": "720116ea.8dfee8", "name": "Step #3 - Refresh Token Flow a few times for good measure.", "info": "This flow will refresh your token every time the input button is pressed.\n\nGlobal variables set -- EcobeeAccessToken and EcobeeRefreshToken", "x": 232.5, "y": 296.77778816223145, "wires": [] }, { "id": "fe27967b.01d868", "type": "comment", "z": "720116ea.8dfee8", "name": "Step #4 - Get Thermostat Data", "info": "Get thermostat data", "x": 140.8888931274414, "y": 405.55558013916016, "wires": [] }, { "id": "16e42b28.e91bd5", "type": "function", "z": "720116ea.8dfee8", "name": "Display temperature", "func": "var currentTemp=\"\";\ncontext.global.Ecobee.Thermostats =new Object();\ncontext.global.Ecobee.Sensors =new Object();\nSensorCaps =new Object();\nfor(i = 0; i