[ { "id": "833243f.f7ccdc", "type": "inject", "name": "Refresh Thermostat Data", "topic": "", "payload": "Refresh Thermostat Variables", "payloadType": "string", "repeat": "120", "crontab": "", "once": true, "x": 163.66665649414062, "y": 458.5277900695801, "z": "bb6b9101.44947", "wires": [ [ "4e408652.b1bf78" ] ] }, { "id": "ab7a9fa3.54856", "type": "function", "name": "Get ecobeePin Token", "func": "// Insert your Ecobee API Key into the following variable:\ncontext.global.EcobeeClientID=\"\";\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.EcobeeClientID+\"&scope=smartWrite\",\n \"method\": \"GET\",\n headers: {\n }\n};\nreturn newMsg;", "outputs": 1, "noerr": 0, "x": 287.75, "y": 106.5, "z": "bb6b9101.44947", "wires": [ [ "ef8337a2.107cc8" ] ] }, { "id": "cad3e4d.f352c18", "type": "debug", "name": "", "active": true, "console": "true", "complete": "payload", "x": 867.7499389648438, "y": 106.25, "z": "bb6b9101.44947", "wires": [] }, { "id": "ef8337a2.107cc8", "type": "http request", "name": "", "method": "use", "ret": "obj", "url": "", "x": 494.75, "y": 106.75, "z": "bb6b9101.44947", "wires": [ [ "26581b88.d9a7e4" ] ] }, { "id": "bfc61497.4039e8", "type": "function", "name": "Get Thermostats", "func": "if (context.global.EcobeeRefreshtoken!==\"\")\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.EcobeeAccessToken,\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": 515.9166564941406, "y": 458.0277900695801, "z": "bb6b9101.44947", "wires": [ [ "1752a5d6.e8ad5a" ] ] }, { "id": "ccf88151.33078", "type": "debug", "name": "", "active": true, "console": "true", "complete": "payload", "x": 1144.0554809570312, "y": 458.02780628204346, "z": "bb6b9101.44947", "wires": [] }, { "id": "1752a5d6.e8ad5a", "type": "http request", "name": "Get Thermostat Request", "method": "use", "ret": "obj", "url": "", "x": 728.1666259765625, "y": 458.0277900695801, "z": "bb6b9101.44947", "wires": [ [ "b3a1fcbb.4c5e" ] ] }, { "id": "a9a0adb8.565f5", "type": "inject", "name": "Refresh token every 30 minutes", "topic": "", "payload": "", "payloadType": "none", "repeat": "1800", "crontab": "", "once": true, "x": 182, "y": 347.2777900695801, "z": "bb6b9101.44947", "wires": [ [ "a92a1e04.56d5e" ] ] }, { "id": "a92a1e04.56d5e", "type": "function", "name": "Refresh Token", "func": "context.global.EcobeeClientID=\"\";\n//context.global.EcobeeRefreshToken=\"\";\nvar newMsg ={\n \"url\":\"https://api.ecobee.com/token?grant_type=refresh_token&code=\"+context.global.EcobeeRefreshToken+\"&client_id=\"+context.global.EcobeeClientID+\"\",\n \"method\": \"POST\",\n headers: {\n }\n};\nreturn newMsg;", "outputs": 1, "noerr": 0, "x": 409.4166564941406, "y": 347.2777900695801, "z": "bb6b9101.44947", "wires": [ [ "5ab6f1a3.a5491" ] ] }, { "id": "5ab6f1a3.a5491", "type": "http request", "name": "", "method": "use", "ret": "obj", "url": "", "x": 579.1666564941406, "y": 347.0277900695801, "z": "bb6b9101.44947", "wires": [ [ "e680352c.197fc8" ] ] }, { "id": "ecbedcc9.13412", "type": "function", "name": "Define Access and Refresh Token vars", "func": "context.global.EcobeeAccessToken=msg.payload.access_token;\ncontext.global.EcobeeRefreshToken=msg.payload.refresh_token;\nvar msg={ payload:{\n access_token:context.global.EcobeeAccessToken,\n refresh_token:context.global.EcobeeRefreshToken\n }\n};\nreturn msg;", "outputs": 1, "noerr": 0, "x": 995.4166564941406, "y": 353.5277900695801, "z": "bb6b9101.44947", "wires": [ [ "c69826bf.3967d8", "44338f8.fbbcc7" ] ] }, { "id": "c69826bf.3967d8", "type": "debug", "name": "", "active": true, "console": "false", "complete": "payload", "x": 1254.1666564941406, "y": 399.2777900695801, "z": "bb6b9101.44947", "wires": [] }, { "id": "2671d0e3.d98e3", "type": "comment", "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": 247.91665649414062, "y": 312.7777900695801, "z": "bb6b9101.44947", "wires": [] }, { "id": "a13172f6.5ece9", "type": "comment", "name": "Step #4 - Get Thermostat Data", "info": "Get thermostat data", "x": 156.30554962158203, "y": 421.5555820465088, "z": "bb6b9101.44947", "wires": [] }, { "id": "b3a1fcbb.4c5e", "type": "function", "name": "Display temperature", "func": "var currentTemp=\"\";\ncontext.global.EcobeeThermostats =new Object();\ncontext.global.EcobeeSensors =new Object();\nSensorCaps =new Object();\nfor(i = 0; i