├── .sample_wink_auth.json
├── test
└── service
│ ├── devices.js
│ ├── device
│ ├── eggtray.js
│ ├── light.js
│ └── thermostat.js
│ ├── robot_id.js
│ └── user.js
├── .gitignore
├── mock-server
├── server.csr
├── server.key
├── server.crt
└── wink_api.md
├── package.json
├── .jshintrc
├── Gruntfile.js
├── lib
└── model
│ ├── light.js
│ ├── group
│ └── light.js
│ ├── eggtray.js
│ ├── robot.js
│ └── thermostat.js
├── index.js
├── LICENSE
└── README.md
/.sample_wink_auth.json:
--------------------------------------------------------------------------------
1 | {
2 | "client_id": "CLIENT_ID_HERE",
3 | "client_secret": "CLIENT_SECRET_HERE",
4 | "username": "WINK_EMAIL_HERE",
5 | "password": "WINK_PASSWORD_HERE"
6 | }
7 |
--------------------------------------------------------------------------------
/test/service/devices.js:
--------------------------------------------------------------------------------
1 | var expect = require('chai').expect;
2 | var wink = require('../../index');
3 |
4 | describe("Wink devices", function() {
5 |
6 | before(function(done) {
7 | wink.init({
8 | conf: process.env.WINK_CONF || '.wink_auth.json'
9 | }, function(data) {
10 | expect(data).to.be.ok;
11 | done();
12 | });
13 | });
14 |
15 | it("should return device", function(done) {
16 | wink.device_group('light_bulbs').device_id('562635').get(function(data) {
17 | expect(data).to.be.an('object');
18 | expect(data.data).to.include.keys('name');
19 | done();
20 | });
21 | });
22 |
23 | });
24 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # swap files
6 | *.swp
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 |
13 | # authentication informaiton
14 | .wink_auth.json
15 |
16 | # Directory for instrumented libs generated by jscoverage/JSCover
17 | lib-cov
18 |
19 | # Coverage directory used by tools like istanbul
20 | coverage
21 |
22 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
23 | .grunt
24 |
25 | # node-waf configuration
26 | .lock-wscript
27 |
28 | # Compiled binary addons (http://nodejs.org/api/addons.html)
29 | build/Release
30 |
31 | # Dependency directory
32 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
33 | node_modules
34 |
--------------------------------------------------------------------------------
/mock-server/server.csr:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE REQUEST-----
2 | MIIBwTCCASoCAQAwgYAxCzAJBgNVBAYTAlVTMRAwDgYDVQQIDAdGbG9yaWRhMRYw
3 | FAYDVQQHDA1Cb3ludG9uIEJlYWNoMREwDwYDVQQKDAh3aW5maW5pdDERMA8GA1UE
4 | AwwId2luZmluaXQxITAfBgkqhkiG9w0BCQEWEndpbmZpbml0QGdtYWlsLmNvbTCB
5 | nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA8ECTGZxf7Z96m5uLaG7h3po3oZMo
6 | 9k82XAOj9OciXSBelm5gC+TXd6rkx2ecLhRsNG+fLjYEAyHMmIPfEvCLTBZEZGKK
7 | saw5kOItaq7zKdYYDJ1nvlf0Xoutk2qQ9ZzHQrMvjWC8TsqqZTCP8P7xLCPGX+Qs
8 | VNzKs3m5r+XsTe0CAwEAAaAAMA0GCSqGSIb3DQEBCwUAA4GBADD5riCgH3cGP56B
9 | OCNUCvwIMvbK2hVSvwe+UqnqHmfQRWLJD9SDBMcKUVhoX3UdT0ho2y7Np/XDA43q
10 | lJMWTnki5zRW0BWve9e+X5g4GeoYl7TivHNbRWwZy+3vzlL7tznDuomMqMzaXT9y
11 | iNn2eaZWslhCv6mCR1G8APIH+ij/
12 | -----END CERTIFICATE REQUEST-----
13 |
--------------------------------------------------------------------------------
/test/service/device/eggtray.js:
--------------------------------------------------------------------------------
1 | var expect = require('chai').expect;
2 | var wink = require('../../../index');
3 |
4 | describe("Wink devices", function() {
5 |
6 | before(function(done) {
7 | wink.init({
8 | conf: process.env.WINK_CONF || '.wink_auth.json'
9 | }, function(data) {
10 | expect(data).to.be.ok;
11 | done();
12 | });
13 | });
14 |
15 | it("should get eggminder", function(done) {
16 | wink.user().device('Egg Minder', function(device) {
17 | expect(device.device_group).to.equal('eggtrays');
18 | done();
19 | });
20 | });
21 |
22 | it("should return egg quantity", function(done) {
23 | wink.user().device('Egg Minder', function(device) {
24 | expect(device.quantity).to.be.a('number');
25 | done();
26 | });
27 | });
28 |
29 | });
30 |
--------------------------------------------------------------------------------
/mock-server/server.key:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIICXwIBAAKBgQDwQJMZnF/tn3qbm4tobuHemjehkyj2TzZcA6P05yJdIF6WbmAL
3 | 5Nd3quTHZ5wuFGw0b58uNgQDIcyYg98S8ItMFkRkYoqxrDmQ4i1qrvMp1hgMnWe+
4 | V/Rei62TapD1nMdCsy+NYLxOyqplMI/w/vEsI8Zf5CxU3Mqzebmv5exN7QIDAQAB
5 | AoGBANiHuowojaSiSWSZaamz1cpEf8MV2KM1fS6s8UY2UphQJi+6RsIxe6iU0yCM
6 | 1wwIyATyXSrO8ArKmZUTtSdiuIcZiPW8hUi7ELkvj7zHH8r7HyKI63nrUkgeOmMp
7 | Tb7lJx9Dpx9qVJ+SBky1xyq63eXg0HrHoSddxO08ZVYLCUJBAkEA/1bQAiplwDba
8 | KkjE/qS/fmWsAi04FUE1lzRYnGkn34DWKj0pwVR5lpH2XUaIi0hwW0rkm97EOgCV
9 | rmom4Y1RpQJBAPDfw/nndJnAR28RKEW+q0XJosVh4ih4Aph+CxIKm6rjvhmZ6om5
10 | 4OB5JEB7QczB7dA0SDwJpRAhOmcELhgPSKkCQQDj5RrAZBDuzsZHaS2RzX8wlBRC
11 | 2RMuPUZUjx7rcxtoa3g6uN5UtE3VKq+Frtdd4SiPArgpuljPIAh4ZDwRoe0VAkEA
12 | qfuviGcvYOVRQ+8etYFlyr0N0i9Oc3KlmkmwtE2qJ0HKwLRe0EzNhnvW+m5BNCdT
13 | FRAgPcYspyJb3aEUikQW6QJBAILOhDqbkUcLwUFjYzg0rH42e/Iw63T1rCjz/9qc
14 | raO9BTMJpy5j+9m6wwn1mtQ9uAmvwAcfTINsLG1RRWJ5Jh8=
15 | -----END RSA PRIVATE KEY-----
16 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "wink-js",
3 | "version": "0.1.3",
4 | "description": "Wink API wrapper",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "node index.js",
8 | "test": "mocha --recursive --no-timeouts test"
9 | },
10 | "dependencies": {
11 | "async": "*",
12 | "config-file": "~0.3.0",
13 | "debug": ""
14 | },
15 | "devDependencies": {
16 | "chai": "~2.2.0",
17 | "grunt": "~0.4.5",
18 | "grunt-cli": "~0.1.13",
19 | "grunt-contrib-jshint": "0.11.1",
20 | "grunt-contrib-watch": "0.6.1",
21 | "grunt-mocha-test": "0.12.7",
22 | "grunt-apimock": "~0.1.2",
23 | "grunt-env": "~0.4.4",
24 | "mocha": "~2.2.4"
25 | },
26 | "engines": {
27 | "node": ">= 0.10.0"
28 | },
29 | "repository": {
30 | "type": "git",
31 | "url": "https://github.com/winfinit/wink-js"
32 | },
33 | "keywords": [
34 | "wink",
35 | "home automation",
36 | "wink api"
37 | ],
38 | "license": "GPL"
39 | }
40 |
--------------------------------------------------------------------------------
/mock-server/server.crt:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICeTCCAeICCQCIgUPfKXPRjTANBgkqhkiG9w0BAQsFADCBgDELMAkGA1UEBhMC
3 | VVMxEDAOBgNVBAgMB0Zsb3JpZGExFjAUBgNVBAcMDUJveW50b24gQmVhY2gxETAP
4 | BgNVBAoMCHdpbmZpbml0MREwDwYDVQQDDAh3aW5maW5pdDEhMB8GCSqGSIb3DQEJ
5 | ARYSd2luZmluaXRAZ21haWwuY29tMB4XDTE1MDQyMDE0MDg1M1oXDTQyMDkwNDE0
6 | MDg1M1owgYAxCzAJBgNVBAYTAlVTMRAwDgYDVQQIDAdGbG9yaWRhMRYwFAYDVQQH
7 | DA1Cb3ludG9uIEJlYWNoMREwDwYDVQQKDAh3aW5maW5pdDERMA8GA1UEAwwId2lu
8 | ZmluaXQxITAfBgkqhkiG9w0BCQEWEndpbmZpbml0QGdtYWlsLmNvbTCBnzANBgkq
9 | hkiG9w0BAQEFAAOBjQAwgYkCgYEA8ECTGZxf7Z96m5uLaG7h3po3oZMo9k82XAOj
10 | 9OciXSBelm5gC+TXd6rkx2ecLhRsNG+fLjYEAyHMmIPfEvCLTBZEZGKKsaw5kOIt
11 | aq7zKdYYDJ1nvlf0Xoutk2qQ9ZzHQrMvjWC8TsqqZTCP8P7xLCPGX+QsVNzKs3m5
12 | r+XsTe0CAwEAATANBgkqhkiG9w0BAQsFAAOBgQCtXKaBFyfA54X+7MsUx3aUgQkf
13 | ZuTzkTwopntLSoLjwGVboMbNTzC8r+AWLQfM7Ab4Zq8ZXJQfkGjXLYUQbNvQnPj2
14 | Ah/opZdwRghqEBszQodBISRw7HcOIxF2oUphU7POEuwPgKwYqxbzShDF4VtpWaxv
15 | VlS2UMsffvFT/DehSQ==
16 | -----END CERTIFICATE-----
17 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "maxerr": 50,
3 | "bitwise": true,
4 | "camelcase": true,
5 | "curly": true,
6 | "eqeqeq": true,
7 | "forin": false,
8 | "immed": false,
9 | "indent": 4,
10 | "latedef": false,
11 | "newcap": true,
12 | "noarg": true,
13 | "noempty": true,
14 | "nonew": false,
15 | "plusplus": false,
16 | "quotmark": "single",
17 | "undef": true,
18 | "unused": true,
19 | "strict": true,
20 | "trailing": false,
21 | "maxparams": 5,
22 | "maxdepth": 3,
23 | "maxlen": 160,
24 | "browser": true,
25 | "devel": false,
26 | "jquery": false,
27 | "node": true,
28 |
29 | "predef": [
30 | "delete",
31 | "define",
32 | "xdescribe",
33 | "describe",
34 | "it",
35 | "xit",
36 | "afterAll",
37 | "beforeAll",
38 | "beforeEach",
39 | "afterEach",
40 | "expect",
41 | "default",
42 | "spyOn",
43 | "after",
44 | "before"
45 | ]
46 | }
47 |
--------------------------------------------------------------------------------
/test/service/device/light.js:
--------------------------------------------------------------------------------
1 | var expect = require('chai').expect;
2 | var wink = require('../../../index');
3 |
4 | describe("Wink devices", function() {
5 |
6 | before(function(done) {
7 | wink.init({
8 | conf: process.env.WINK_CONF || '.wink_auth.json'
9 | }, function(data) {
10 | expect(data).to.be.ok;
11 | done();
12 | });
13 | });
14 |
15 | it("should turn lights on", function(done) {
16 | wink.user().device('Kitchen', function(device) {
17 | device.power.on(function(response) {
18 | expect(response).to.be.ok;
19 | done();
20 | });
21 | // expect(data).to.be.an('object');
22 | // expect(data.data).to.include.keys('name');
23 | });
24 | });
25 |
26 | it("should dim lights to 50%", function(done) {
27 | wink.user().device('Kitchen', function(device) {
28 | device.brightness(50, function(response) {
29 | expect(response).to.be.ok;
30 | done();
31 | });
32 | });
33 | });
34 |
35 | it("should turn lights off", function(done) {
36 | wink.user().device('Kitchen', function(device) {
37 | device.power.off(function(response) {
38 | expect(response).to.be.ok;
39 | done();
40 | });
41 | // expect(data).to.be.an('object');
42 | // expect(data.data).to.include.keys('name');
43 | });
44 | });
45 |
46 |
47 | });
48 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = function (grunt) {
4 |
5 | //Default task runs tests, jshint and watches for changes.
6 | grunt.registerTask('default',
7 | ['mochaTest', 'jshint']);
8 |
9 | //Just run tests
10 | grunt.registerTask('test', ['env:test', 'mochaTest']);
11 |
12 | //Start mock server
13 | grunt.registerTask('mock', ['env:test', 'apimock']);
14 |
15 | // Project configuration.
16 | grunt.initConfig({
17 | pkg: grunt.file.readJSON('package.json'),
18 |
19 | env: {
20 | test: {
21 | WINK_HOST: "localhost",
22 | WINK_PORT: 3999,
23 | NODE_TLS_REJECT_UNAUTHORIZED: 0,
24 | WINK_CONF: ".sample_wink_auth.json"
25 | }
26 | },
27 |
28 | //Mock server
29 | apimock: {
30 | options: {
31 | "port": 3998,
32 | "ssl-enable": true,
33 | "ssl-port": 3999,
34 | "ssl-host": "localhost",
35 | "ssl-key": "mock-server/server.key",
36 | "ssl-cert": "mock-server/server.crt",
37 | "src": "mock-server/wink_api.md",
38 | "keepalive": true
39 | }
40 | },
41 |
42 | //Tests
43 | mochaTest: {
44 | test: {
45 | options: {
46 | "no-timeouts": true
47 | },
48 | src: ['test/**/*.js']
49 | }
50 | },
51 |
52 | //Clean code.
53 | jshint: {
54 | options: {
55 | jshintrc: '.jshintrc'
56 | },
57 | files: { src: ['index.js', 'lib/*.js', 'test/**/*.js']}
58 | },
59 |
60 | //Files to watch and actions to take when they are changed.
61 | watch: {
62 | files: ['index.js', 'test/**/*.js', 'lib/**/*.js'],
63 | tasks: ['jshint', 'mochaTest']
64 | }
65 | });
66 |
67 | // Load the plugins
68 | // Watch the file system for changes.
69 | grunt.loadNpmTasks('grunt-contrib-watch');
70 | // Start mock server
71 | grunt.loadNpmTasks('grunt-apimock');
72 | // Start mock server
73 | grunt.loadNpmTasks('grunt-env');
74 | // Runs tests.
75 | grunt.loadNpmTasks('grunt-mocha-test');
76 | // Clean code validator.
77 | grunt.loadNpmTasks('grunt-contrib-jshint');
78 | };
79 |
--------------------------------------------------------------------------------
/lib/model/light.js:
--------------------------------------------------------------------------------
1 | module.exports = function(data, http) {
2 | data.http = http;
3 | data.device_group = "light_bulbs";
4 | data.device_id = data.light_bulb_id;
5 | data.power = {
6 | on: function(callback) {
7 | data.
8 | http.
9 | device_group(data.device_group).
10 | device_id(data.device_id).
11 | update({
12 | "desired_state": {
13 | "powered": true
14 | }
15 | }, callback);
16 | },
17 | off: function(callback) {
18 | data.
19 | http.
20 | device_group(data.device_group).
21 | device_id(data.device_id).
22 | update({
23 | "desired_state": {
24 | "powered": false
25 | }
26 | }, callback);
27 | },
28 | toggle: function(callback) {
29 | if ( data.desired_state.powered === true ) {
30 | this.off(callback);
31 | } else {
32 | this.on(callback);
33 | }
34 | }
35 | };
36 | data.brightness = function(value, callback) {
37 | value = Number(value);
38 | if ( value > 1 ) {
39 | value = value / 100;
40 | }
41 | data.
42 | http.
43 | device_group(data.device_group).
44 | device_id(data.device_id).
45 | update({
46 | "desired_state": {
47 | "brightness": value
48 | }
49 | }, callback);
50 | };
51 | return data;
52 | }
53 |
54 |
55 | /*
56 | {
57 | "light_bulb_id": "389264",
58 | "name": "Office",
59 | "locale": "en_us",
60 | "units": {},
61 | "created_at": 1425698691,
62 | "hidden_at": null,
63 | "capabilities": {},
64 | "triggers": [],
65 | "desired_state": {
66 | "powered": true,
67 | "brightness": 1
68 | },
69 | "manufacturer_device_model": "ge_",
70 | "manufacturer_device_id": null,
71 | "device_manufacturer": "ge",
72 | "model_name": "GE light bulb",
73 | "upc_id": "73",
74 | "hub_id": "114516",
75 | "local_id": "1",
76 | "radio_type": "zigbee",
77 | "linked_service_id": null,
78 | "last_reading": {
79 | "connection": true,
80 | "connection_updated_at": 1429354212.3576825,
81 | "firmware_version": "0.1b03 / 0.4b00",
82 | "firmware_version_updated_at": 1429354212.3577092,
83 | "firmware_date_code": "20140812",
84 | "firmware_date_code_updated_at": 1429354212.3576903,
85 | "powered": true,
86 | "powered_updated_at": 1429354212.3576972,
87 | "brightness": 1,
88 | "brightness_updated_at": 1429354212.3577034,
89 | "desired_powered": true,
90 | "desired_powered_updated_at": 1428490204.9604716,
91 | "desired_brightness": 1,
92 | "desired_brightness_updated_at": 1425698897.9915164
93 | },
94 | "lat_lng": [
95 | null,
96 | null
97 | ],
98 | "location": "",
99 | "order": 0
100 | }
101 | */
102 |
--------------------------------------------------------------------------------
/lib/model/group/light.js:
--------------------------------------------------------------------------------
1 | module.exports = function(data, http) {
2 | data.http = http;
3 | data.device_group = "light_bulbs";
4 | data.device_id = data.light_bulb_id;
5 | data.power = {
6 | on: function(callback) {
7 | data.
8 | http.
9 | device_group(data.device_group).
10 | device_id(data.device_id).
11 | update({
12 | "desired_state": {
13 | "powered": true
14 | }
15 | }, callback);
16 | },
17 | off: function(callback) {
18 | data.
19 | http.
20 | device_group(data.device_group).
21 | device_id(data.device_id).
22 | update({
23 | "desired_state": {
24 | "powered": false
25 | }
26 | }, callback);
27 | },
28 | toggle: function(callback) {
29 | if ( data.desired_state.powered === true ) {
30 | this.off(callback);
31 | } else {
32 | this.on(callback);
33 | }
34 | }
35 | };
36 | data.brightness = function(value, callback) {
37 | value = Number(value);
38 | if ( value > 1 ) {
39 | value = value / 100;
40 | }
41 | data.
42 | http.
43 | device_group(data.device_group).
44 | device_id(data.device_id).
45 | update({
46 | "desired_state": {
47 | "brightness": value
48 | }
49 | }, callback);
50 | };
51 | return data;
52 | }
53 |
54 |
55 | /*
56 | {
57 | "light_bulb_id": "389264",
58 | "name": "Office",
59 | "locale": "en_us",
60 | "units": {},
61 | "created_at": 1425698691,
62 | "hidden_at": null,
63 | "capabilities": {},
64 | "triggers": [],
65 | "desired_state": {
66 | "powered": true,
67 | "brightness": 1
68 | },
69 | "manufacturer_device_model": "ge_",
70 | "manufacturer_device_id": null,
71 | "device_manufacturer": "ge",
72 | "model_name": "GE light bulb",
73 | "upc_id": "73",
74 | "hub_id": "114516",
75 | "local_id": "1",
76 | "radio_type": "zigbee",
77 | "linked_service_id": null,
78 | "last_reading": {
79 | "connection": true,
80 | "connection_updated_at": 1429354212.3576825,
81 | "firmware_version": "0.1b03 / 0.4b00",
82 | "firmware_version_updated_at": 1429354212.3577092,
83 | "firmware_date_code": "20140812",
84 | "firmware_date_code_updated_at": 1429354212.3576903,
85 | "powered": true,
86 | "powered_updated_at": 1429354212.3576972,
87 | "brightness": 1,
88 | "brightness_updated_at": 1429354212.3577034,
89 | "desired_powered": true,
90 | "desired_powered_updated_at": 1428490204.9604716,
91 | "desired_brightness": 1,
92 | "desired_brightness_updated_at": 1425698897.9915164
93 | },
94 | "lat_lng": [
95 | null,
96 | null
97 | ],
98 | "location": "",
99 | "order": 0
100 | }
101 | */
102 |
--------------------------------------------------------------------------------
/lib/model/eggtray.js:
--------------------------------------------------------------------------------
1 | module.exports = function(data, http) {
2 | data.http = http;
3 | data.device_group = "eggtrays";
4 | data.device_id = data.eggtray_id;
5 | data.quantity = (data.eggs.filter(function(val){ return !!val})).length;
6 |
7 | return data;
8 | }
9 |
10 | /*
11 | {
12 | "last_reading": {
13 | "connection": null,
14 | "connection_updated_at": null,
15 | "battery": 0.18,
16 | "battery_updated_at": 1429541274.5857081,
17 | "inventory": 1,
18 | "inventory_updated_at": 1429541274.631489,
19 | "age": 1429454667,
20 | "age_updated_at": 1429541274.6315,
21 | "freshness_remaining": 1727793,
22 | "freshness_remaining_updated_at": 1429541274.6315074,
23 | "egg_1_timestamp": 0,
24 | "egg_1_timestamp_updated_at": 1429541274.5594687,
25 | "egg_2_timestamp": 0,
26 | "egg_2_timestamp_updated_at": 1429541274.559478,
27 | "egg_3_timestamp": 0,
28 | "egg_3_timestamp_updated_at": 1429541274.5594845,
29 | "egg_4_timestamp": 0,
30 | "egg_4_timestamp_updated_at": 1429541274.5594902,
31 | "egg_5_timestamp": 0,
32 | "egg_5_timestamp_updated_at": 1429541274.5594962,
33 | "egg_6_timestamp": 0,
34 | "egg_6_timestamp_updated_at": 1429541274.5595021,
35 | "egg_7_timestamp": 0,
36 | "egg_7_timestamp_updated_at": 1429541274.559508,
37 | "egg_8_timestamp": 0,
38 | "egg_8_timestamp_updated_at": 1429541274.5595133,
39 | "egg_9_timestamp": 0,
40 | "egg_9_timestamp_updated_at": 1429541274.559519,
41 | "egg_10_timestamp": 0,
42 | "egg_10_timestamp_updated_at": 1429541274.5595248,
43 | "egg_11_timestamp": 0,
44 | "egg_11_timestamp_updated_at": 1429541274.5595305,
45 | "egg_12_timestamp": 1429454667,
46 | "egg_12_timestamp_updated_at": 1429541274.5595367,
47 | "egg_13_timestamp": 0,
48 | "egg_13_timestamp_updated_at": 1429541274.559543,
49 | "egg_14_timestamp": 0,
50 | "egg_14_timestamp_updated_at": 1429541274.5595486
51 | },
52 | "eggs": [
53 | 0,
54 | 0,
55 | 0,
56 | 0,
57 | 0,
58 | 0,
59 | 0,
60 | 0,
61 | 0,
62 | 0,
63 | 0,
64 | 1429454667,
65 | 0,
66 | 0
67 | ],
68 | "freshness_period": xxx,
69 | "eggtray_id": "xxx",
70 | "name": "Egg Minder",
71 | "locale": "en_us",
72 | "units": {},
73 | "created_at": xxx,
74 | "hidden_at": null,
75 | "capabilities": {},
76 | "triggers": [],
77 | "device_manufacturer": "quirky_ge",
78 | "model_name": "Egg Minder",
79 | "upc_id": "23",
80 | "lat_lng": [
81 | 26.496337,
82 | -80.063654
83 | ],
84 | "location": "",
85 | "mac_address": "xxx",
86 | "serial": "xxx"
87 | }
88 | */
89 |
--------------------------------------------------------------------------------
/test/service/robot_id.js:
--------------------------------------------------------------------------------
1 | var expect = require('chai').expect;
2 | var wink = require('../../index');
3 |
4 | describe("Wink robots", function() {
5 |
6 | before(function(done) {
7 | wink.init({
8 | conf: process.env.WINK_CONF || '.wink_auth.json'
9 | }, function(data) {
10 | expect(data).to.be.ok;
11 | done();
12 | });
13 | });
14 |
15 | it("should cache all the robots",function(done) {
16 | wink.user().robots.get(function(data) {
17 | var g = wink.GET
18 | wink.GET = function(data,callback) {
19 | callback(null);
20 | }
21 | for(var i = 0; i< data.data.length; i++) {
22 | wink.robot_id(data.data[i].robot_id).get(function(device) {
23 | expect(device).to.be.an('object');
24 | expect(device == data.data[i]).to.equal(true);
25 | });
26 | }
27 | wink.GET = g;
28 | done();
29 | });
30 | });
31 | it("should return robots", function(done) {
32 | wink.user().robots.get(function(data) {
33 | expect(data).to.be.an('object');
34 | expect(data).to.include.keys('data');
35 | expect(data).to.include.keys('errors');
36 | expect(data).to.include.keys('pagination');
37 | expect(data.data).to.be.an('array');
38 | done();
39 | })
40 | });
41 | it('should fetch the same robot as pulled from robots',function(done) {
42 | wink.user().robots.get(function(data) {
43 | //find robot named test
44 | for(var i = 0; i< data.data.length; i++) {
45 | if(data.data[i].name == "Test") {
46 | wink.robot_id(data.data[i].robot_id).get(function(device) {
47 | expect(device).to.be.an('object');
48 | expect(device).to.include.keys('robot_id');
49 | expect(device.name).to.equal('Test');
50 | done();
51 | });
52 | }
53 | }
54 | });
55 | });
56 | it("should disable robot",function(done) {
57 | wink.user().robots.get(function(data) {
58 | //find robot named test
59 | for(var i = 0; i< data.data.length; i++) {
60 | if(data.data[i].name == "Test") {
61 | device = data.data[i];
62 | expect(device).to.be.an('object');
63 | expect(device).to.include.keys('robot_id');
64 | expect(device.name).to.equal('Test');
65 | device.state.disabled(function(response) {
66 | expect(response).to.be.ok;
67 | done();
68 | });
69 | }
70 | }
71 | });
72 | });
73 | it("should enable robot",function(done) {
74 | wink.user().robots.get(function(data) {
75 | //find robot named test
76 | for(var i = 0; i< data.data.length; i++) {
77 | if(data.data[i].name == "Test") {
78 | device = data.data[i];
79 | expect(device).to.be.an('object');
80 | expect(device).to.include.keys('robot_id');
81 | expect(device.name).to.equal('Test');
82 | device.state.enabled(function(response) {
83 | expect(response).to.be.ok;
84 | done();
85 | });
86 | }
87 | }
88 | });
89 | });
90 | });
91 |
--------------------------------------------------------------------------------
/test/service/device/thermostat.js:
--------------------------------------------------------------------------------
1 | var expect = require('chai').expect;
2 | var wink = require('../../../index');
3 | var device;
4 |
5 | describe("Wink devices", function() {
6 |
7 | before(function(done) {
8 | wink.init({
9 | conf: process.env.WINK_CONF || '.wink_auth.json'
10 | }, function(data) {
11 | expect(data).to.be.ok;
12 | wink.user().device('Home Downstairs Thermostat', function(return_device) {
13 | device = return_device;
14 | console.log("device:",device);
15 | done();
16 | });
17 | });
18 | });
19 |
20 | it("should get thermostat", function() {
21 | expect(device.device_group).to.equal('thermostats');
22 | });
23 |
24 | it("should return thermostat id", function() {
25 | expect(Number(device.device_id)).to.be.a('number');
26 | });
27 |
28 | it("should change temperature", function(done) {
29 | device.temperature(74, function(response) {
30 | console.log("response from change: ", response);
31 | expect(response).to.be.ok;
32 | done();
33 | });
34 | });
35 |
36 | it("should change temperature with min set", function(done) {
37 | device.temperature(74, 73, function(response) {
38 | console.log("response from change: ", response);
39 | expect(response).to.be.ok;
40 | done();
41 | });
42 | });
43 |
44 | it("should change temperature with min set and in celsius", function(done) {
45 | device.temperature(21, 20, 'c', function(response) {
46 | console.log("response from change: ", response);
47 | expect(response).to.be.ok;
48 | done();
49 | });
50 | });
51 |
52 | it("should change temperature in celsius", function(done) {
53 | device.temperature(21, 'c', function(response) {
54 | console.log("response from change: ", response);
55 | expect(response).to.be.ok;
56 | done();
57 | });
58 | });
59 |
60 | it("should change temperature in fahrenheit", function(done) {
61 | device.temperature(72, 'f', function(response) {
62 | console.log("response from change: ", response);
63 | expect(response).to.be.ok;
64 | done();
65 | });
66 | });
67 |
68 | it("should get temperature", function(done) {
69 | device.temperature(function(temp) {
70 | expect(temp).to.equal(22);
71 | done();
72 | });
73 | });
74 |
75 | it("should get temperature in f with callback", function(done) {
76 | device.temperature('f', function(temp) {
77 | expect(temp).to.equal(72);
78 | done();
79 | });
80 | });
81 |
82 | it("should get temperature in f with return", function(done) {
83 | var temp = device.temperature('f');
84 | expect(temp).to.equal(72);
85 | done();
86 | });
87 |
88 | it("should get temperature in c with return", function(done) {
89 | var temp = device.temperature('c');
90 | expect(temp).to.equal(22);
91 | done();
92 | });
93 |
94 | it("should get temperature in c with callback", function(done) {
95 | device.temperature('c', function(temp) {
96 | expect(temp).to.equal(22);
97 | done();
98 | });
99 | });
100 |
101 | });
102 |
--------------------------------------------------------------------------------
/test/service/user.js:
--------------------------------------------------------------------------------
1 | var expect = require('chai').expect;
2 | var wink = require('../../index');
3 |
4 | describe("Wink user", function() {
5 |
6 | before(function(done) {
7 | wink.init({
8 | conf: process.env.WINK_CONF || '.wink_auth.json'
9 | }, function(data) {
10 | expect(data).to.be.ok;
11 | done();
12 | });
13 | });
14 |
15 | it("should retrieve user information", function(done) {
16 | wink.user().get(function(data) {
17 | expect(data).to.be.an('object');
18 | expect(data).to.include.keys('data');
19 | expect(data).to.include.keys('errors');
20 | expect(data).to.include.keys('pagination');
21 | expect(data.data).to.include.keys('user_id');
22 | expect(data.data).to.include.keys('first_name');
23 | expect(data.data).to.include.keys('last_name');
24 | expect(data.data).to.include.keys('locale');
25 | expect(data.data).to.include.keys('email');
26 | done();
27 | });
28 | });
29 | it("should returned linked services", function(done) {
30 | wink.user().linked_services.get(function(data){
31 | /*
32 | { data: [], errors: [], pagination: { count: 0 } }
33 | */
34 | expect(data).to.be.an('object');
35 | expect(data).to.include.keys('data');
36 | expect(data).to.include.keys('errors');
37 | expect(data).to.include.keys('pagination');
38 | done();
39 | });
40 | }),
41 | it("should return all available devices", function(done) {
42 | wink.user().devices(function(data) {
43 | expect(data).to.be.an('object');
44 | expect(data).to.include.keys('data');
45 | expect(data).to.include.keys('errors');
46 | expect(data).to.include.keys('pagination');
47 | expect(data.data).to.be.an('array');
48 | done();
49 | });
50 | });
51 | it("should return all light bulbs", function(done) {
52 | /*
53 | light_bulbs
54 | remotes
55 | */
56 | wink.user().devices('light_bulbs', function(data) {
57 | expect(data).to.be.an('object');
58 | expect(data).to.include.keys('data');
59 | expect(data).to.include.keys('errors');
60 | expect(data).to.include.keys('pagination');
61 | expect(data.data).to.be.an('array');
62 | done();
63 | });
64 | });
65 | it("should return all robots", function(done) {
66 | wink.user().robots.get(function(data) {
67 | expect(data).to.be.an('object');
68 | expect(data).to.include.keys('data');
69 | expect(data).to.include.keys('errors');
70 | expect(data).to.include.keys('pagination');
71 | expect(data.data).to.be.an('array');
72 | done();
73 | });
74 | });
75 | it("should return all groups", function(done) {
76 | wink.user().groups.get(function(data) {
77 | expect(data).to.be.an('object');
78 | expect(data).to.include.keys('data');
79 | expect(data.data).to.be.an('array');
80 | done();
81 | });
82 | });
83 | it.only("should return single group by name", function(done) {
84 | wink.user().group.name("test", function(data) {
85 | expect(data).to.be.an('object');
86 | done();
87 | });
88 | });
89 | it("should return single group by id", function(done) {
90 | wink.user().group.id(3598245, function(data) {
91 | expect(data).to.be.an('object');
92 | done();
93 | });
94 | });
95 | it("should return all scenes", function(done) {
96 | wink.user().scenes.get(function(data) {
97 | expect(data).to.be.an('object');
98 | expect(data).to.include.keys('data');
99 | expect(data).to.include.keys('errors');
100 | expect(data).to.include.keys('pagination');
101 | expect(data.data).to.be.an('array');
102 | done();
103 | });
104 | });
105 | });
106 |
--------------------------------------------------------------------------------
/lib/model/robot.js:
--------------------------------------------------------------------------------
1 | module.exports = function(data, http) {
2 | data.http = http;
3 | data.robot_id=data.robot_id;
4 | data.state = {
5 | enabled: function(callback) {
6 | data.
7 | http.
8 | robot_id(data.robot_id).
9 | update({
10 | "desired_state": {
11 | "enabled": true
12 | }
13 | }, callback);
14 | },
15 | disabled: function(callback) {
16 | data.
17 | http.
18 | robot_id(data.robot_id).
19 | update({
20 | "desired_state": {
21 | "enabled": false
22 | }
23 | }, callback);
24 | }
25 | }
26 | };
27 |
28 |
29 |
30 | /*
31 | {
32 | "data":{
33 | "robot_id":"2692128",
34 | "name":"Auto Close Garage",
35 | "enabled":true,
36 | "creating_actor_type":"user",
37 | "creating_actor_id":"389934",
38 | "automation_mode":null,
39 | "fired_limit":0,
40 | "last_fired":null,
41 | "desired_state":{
42 | "enabled":true,
43 | "fired_limit":0
44 | },
45 | "last_reading":{
46 | "fired_true":"N/A",
47 | "fired_true_updated_at":null,
48 | "enabled":true,
49 | "enabled_updated_at":1455844966.738657,
50 | "fired_limit":0,
51 | "fired_limit_updated_at":null,
52 | "fired_count":0,
53 | "fired_count_updated_at":null,
54 | "fired":false,
55 | "fired_updated_at":null,
56 | "failure_email_sent":null,
57 | "failure_email_sent_updated_at":null,
58 | "desired_enabled_updated_at":1455845101.1988175,
59 | "desired_fired_limit_updated_at":1455845101.1988175,
60 | "desired_enabled_changed_at":1455844966.7460861,
61 | "desired_fired_limit_changed_at":1455845101.1988175
62 | },
63 | "effects":[
64 | {
65 | "effect_id":"4584987",
66 | "robot_id":"2692128",
67 | "notification_type":null,
68 | "recipient_actor_type":null,
69 | "recipient_actor_id":null,
70 | "scene":{
71 | "scene_id":"2631726",
72 | "name":"New Shortcut",
73 | "order":0,
74 | "members":[
75 | {
76 | "object_type":"garage_door",
77 | "object_id":"40637",
78 | "desired_state":{
79 | "position":0.0
80 | },
81 | "local_scene_id":null
82 | }
83 | ],
84 | "icon_id":224,
85 | "automation_mode":null
86 | },
87 | "note":null,
88 | "reference_object_type":null,
89 | "reference_object_id":null
90 | }
91 | ],
92 | "causes":[
93 | {
94 | "next_at":null,
95 | "recurrence":null,
96 | "condition_id":"3882592",
97 | "robot_id":"2692128",
98 | "observed_object_id":"40637",
99 | "observed_object_type":"garage_door",
100 | "observed_field":"position",
101 | "operator":"==",
102 | "value":"1.0",
103 | "delay":1800,
104 | "restricted_object_id":null,
105 | "restricted_object_type":null,
106 | "restriction_join":null,
107 | "restrictions":[
108 |
109 | ]
110 | }
111 | ],
112 | "restrictions":[
113 |
114 | ]
115 | },
116 | "errors":[
117 |
118 | ],
119 | "pagination":{
120 |
121 | }
122 | }
123 | */
124 |
--------------------------------------------------------------------------------
/lib/model/thermostat.js:
--------------------------------------------------------------------------------
1 | module.exports = function(data, http) {
2 | data.http = http;
3 | data.device_group = "thermostats";
4 | data.device_id = data.thermostat_id;
5 | data.temperature = function(temperature, temp_min, unit, callback) {
6 | if ( typeof(temperature) === 'function' ) {
7 | callback = temperature;
8 | callback(data.desired_state.max_set_point);
9 | return;
10 | } else if ( temperature === undefined ) {
11 | return data.desired_state.max_set_point;
12 | } else if ( isNaN(temperature) ) {
13 | // this is a getter with a temp
14 | var temp;
15 | var unit = temperature
16 |
17 | switch(unit) {
18 | case 'c':
19 | case 'C':
20 | temp = data.desired_state.max_set_point;
21 | break;
22 | case 'f':
23 | case 'F':
24 | temp = Math.round((data.desired_state.max_set_point * (9/5)) + 32);
25 | break;
26 | default:
27 | console.log('invalid temp unit');
28 | break;
29 | }
30 |
31 | if ( typeof(temp_min) === 'function' ) {
32 | callback = temp_min;
33 | callback(temp);
34 | } else {
35 | return temp;
36 | }
37 | }
38 |
39 | if ( typeof(temp_min) === 'function' ) {
40 | callback = temp_min;
41 | temp_min = undefined;
42 | } else if ( temp_min !== undefined && isNaN(temp_min)) {
43 | callback = unit;
44 | unit = temp_min;
45 | temp_min = undefined;
46 | }
47 |
48 | if ( typeof(unit) === 'function' ) {
49 | callback = unit;
50 | unit = undefined;
51 | }
52 |
53 | switch(unit) {
54 | case "f":
55 | case "F":
56 | unit = "f";
57 | break;
58 | case "c":
59 | case "C":
60 | unit = "c";
61 | break;
62 | default:
63 | unit = data.units.temperature;
64 | break;
65 | }
66 |
67 | if ( unit === "f" ) {
68 | // convert to celsius
69 | temperature = (temperature - 32) * (5/9);
70 | }
71 |
72 | if ( temp_min === undefined ) {
73 | temp_min = temperature - 2;
74 | }
75 |
76 | data.
77 | http.
78 | device_group(data.device_group).
79 | device_id(data.device_id).
80 | update({
81 | "desired_state": {
82 | "min_set_point": temp_min,
83 | "max_set_point": temperature
84 | }
85 | }, callback);
86 | }
87 | //data.quantity = (data.eggs.filter(function(val){ return !!val})).length;
88 |
89 | return data;
90 | }
91 |
92 | /*
93 | {
94 | "thermostat_id": "54114",
95 | "name": "Home Downstairs Thermostat",
96 | "locale": "en_us",
97 | "units": {
98 | "temperature": "f"
99 | },
100 | "created_at": 1430018697,
101 | "hidden_at": null,
102 | "capabilities": {},
103 | "triggers": [],
104 | "desired_state": {
105 | "mode": "cool_only",
106 | "powered": true,
107 | "min_set_point": 20,
108 | "max_set_point": 22,
109 | "users_away": false,
110 | "fan_timer_active": false
111 | },
112 | "manufacturer_device_model": "nest",
113 | "manufacturer_device_id": "zcx9ETvEqC3IdY6KyWEhbUxx11Qobba_",
114 | "device_manufacturer": "nest",
115 | "model_name": "Learning Thermostat",
116 | "upc_id": "168",
117 | "hub_id": null,
118 | "local_id": null,
119 | "radio_type": null,
120 | "linked_service_id": "102939",
121 | "last_reading": {
122 | "connection": true,
123 | "connection_updated_at": 1430080036.6664212,
124 | "mode": "cool_only",
125 | "mode_updated_at": 1430080036.6664522,
126 | "powered": true,
127 | "powered_updated_at": 1430080036.666473,
128 | "min_set_point": 20,
129 | "min_set_point_updated_at": 1430018767.7561078,
130 | "max_set_point": 22,
131 | "max_set_point_updated_at": 1430080036.6664915,
132 | "users_away": false,
133 | "users_away_updated_at": 1430080036.6665094,
134 | "fan_timer_active": false,
135 | "fan_timer_active_updated_at": 1430080036.666485,
136 | "temperature": 23,
137 | "temperature_updated_at": 1430080036.666439,
138 | "external_temperature": null,
139 | "external_temperature_updated_at": null,
140 | "deadband": 1.5,
141 | "deadband_updated_at": 1430080036.6664457,
142 | "min_min_set_point": null,
143 | "min_min_set_point_updated_at": null,
144 | "max_min_set_point": null,
145 | "max_min_set_point_updated_at": null,
146 | "min_max_set_point": null,
147 | "min_max_set_point_updated_at": null,
148 | "max_max_set_point": null,
149 | "max_max_set_point_updated_at": null,
150 | "modes_allowed": [
151 | "auto",
152 | "heat_only",
153 | "cool_only"
154 | ],
155 | "modes_allowed_updated_at": 1430080036.6664972,
156 | "units": "f",
157 | "units_updated_at": 1430080036.6664321,
158 | "eco_target": false,
159 | "eco_target_updated_at": 1430080036.6664586,
160 | "manufacturer_structure_id": "mNN4pWJ2yWpMfFSjA_drSBU1RSNN0MXjiHypikpG4mwMnXS-pHxfPw",
161 | "manufacturer_structure_id_updated_at": 1430080036.6664662,
162 | "has_fan": true,
163 | "has_fan_updated_at": 1430080036.6664789,
164 | "fan_duration": 0,
165 | "fan_duration_updated_at": 1430080036.6665034,
166 | "last_error": "too_many_requests",
167 | "last_error_updated_at": 1430019684.2469466,
168 | "desired_mode": "cool_only",
169 | "desired_mode_updated_at": 1430018697.5703063,
170 | "desired_powered": true,
171 | "desired_powered_updated_at": 1430018801.7444894,
172 | "desired_min_set_point": 20,
173 | "desired_min_set_point_updated_at": 1430018765.197387,
174 | "desired_max_set_point": 22,
175 | "desired_max_set_point_updated_at": 1430067786.578795,
176 | "desired_users_away": false,
177 | "desired_users_away_updated_at": 1430018697.5703213,
178 | "desired_fan_timer_active": false,
179 | "desired_fan_timer_active_updated_at": 1430018697.5703301
180 | },
181 | "lat_lng": [
182 | 26.266677,
183 | -80.127683
184 | ],
185 | "location": "",
186 | "smart_schedule_enabled": false
187 | }
188 | */
189 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | var debug = require('debug')('wink:http');
2 | var async = require('async');
3 | var http = require('https');
4 | var config = require('config-file');
5 |
6 | var accessToken = undefined;
7 | var winkUri = undefined;
8 | var winkPort = undefined;
9 |
10 | var model = {
11 | light_bulbs: require('./lib/model/light'),
12 | eggtrays: require('./lib/model/eggtray'),
13 | thermostats: require('./lib/model/thermostat'),
14 | robots: require('./lib/model/robot')
15 | };
16 |
17 | var cache = {
18 | device_type: {},
19 | device: {},
20 | robot: {}
21 | };
22 |
23 | /*
24 | {
25 | host: "www.example.com",
26 | path: "/foo",
27 | headers: {},
28 | data: {}
29 | }
30 | */
31 |
32 | function _http(data, callback) {
33 | var options = {
34 | hostname: data.host || winkUri,
35 | port: data.port || winkPort,
36 | path: data.path,
37 | //since we are listening on a custom port, we need to specify it by hand
38 | // port: '1337',
39 | //This is what changes the request to a POST request
40 | method: data.method,
41 | headers: {}
42 |
43 | };
44 |
45 | if ( data.data ) {
46 | data.data = JSON.stringify(data.data);
47 | options.headers['Content-Length'] = Buffer.byteLength(data.data);
48 | options.headers['Content-Type'] = "application/json";
49 | }
50 |
51 | if ( accessToken !== undefined ) {
52 | options.headers['Authorization'] = "Bearer " + accessToken;
53 | }
54 |
55 | debug('http options', options);
56 | debug('http data', data);
57 |
58 | var str = '';
59 | var req = http.request(options, function(response) {
60 | var statusCode = response.statusCode;
61 |
62 | response.on('data', function (chunk) {
63 | str += chunk;
64 | });
65 |
66 | response.on('end', function () {
67 | debug("response code: %d", statusCode);
68 | debug("response in http:", str);
69 | try {
70 | str = JSON.parse(str);
71 | } catch(e) {
72 | console.error(e.stack);
73 | console.error("raw message", str);
74 | str = undefined;
75 | }
76 |
77 | callback(str);
78 | });
79 | });
80 |
81 | if ( data.data ) {
82 | req.write(data.data);
83 | }
84 |
85 | req.end();
86 |
87 | req.on('error', function(e) {
88 | console.error("error at req: " ,e);
89 | });
90 |
91 | }
92 |
93 | function POST(data, callback) {
94 | data.method = "POST";
95 | _http(data, callback);
96 | }
97 |
98 | function PUT(data, callback) {
99 | data.method = "PUT";
100 | _http(data, callback);
101 | }
102 |
103 | function GET(data, callback) {
104 | data.method = "GET";
105 | _http(data, callback);
106 | }
107 |
108 | function DELETE(data, callback) {
109 | data.method = "DELETE";
110 | _http(data, callback);
111 | }
112 |
113 | var wink = {
114 | authenticate: function (auth_data, callback) {
115 | if ( accessToken === undefined ) {
116 | if ( auth_data.grant_type === undefined ) {
117 | auth_data.grant_type = "password";
118 | }
119 | POST({
120 | host: winkUri,
121 | path: '/oauth2/token',
122 | data: auth_data
123 | }, function(response) {
124 | if (response) {
125 | accessToken = response.access_token;
126 | }
127 | callback(response);
128 | });
129 | } else {
130 | callback(accessToken);
131 | }
132 | },
133 | init: function(auth_data, callback) {
134 | if ( auth_data.conf !== undefined ) {
135 | // get data from config
136 | auth_data = config.parse(auth_data.conf);
137 | }
138 |
139 | if ( process.env.WINK_HOST ) {
140 | winkUri = process.env.WINK_HOST;
141 | } else if ( auth_data.hostname ) {
142 | winkUri = auth_data.hostname;
143 | } else {
144 | winkUri = "api.wink.com";
145 | }
146 |
147 | if ( process.env.WINK_PORT ) {
148 | winkPort = Number(process.env.WINK_PORT);
149 | } else if ( auth_data.port ) {
150 | winkPort = Number(auth_data.port);
151 | } else {
152 | winkPort = 443;
153 | }
154 |
155 | this.authenticate(auth_data, function(data) {
156 |
157 | if ( callback !== undefined ) {
158 | callback(data);
159 | }
160 |
161 | });
162 | return this;
163 | },
164 | // prime will preload all devices to cache
165 | prime: function(callback) {
166 | var parent = this;
167 | this.user().devices(function(data) {
168 | for (var index in data.data ) {
169 | parent.user().device(data.data[index].name, function(){});
170 | }
171 | });
172 | this.user().robots(function(data) {});
173 | },
174 | user: function(user_id) {
175 | if ( user_id === undefined ) {
176 | user_id = "me";
177 | }
178 | var parent = this;
179 | return {
180 | cache: {
181 | device_type: {},
182 | device: {},
183 | robot: {}
184 | },
185 | create: function(data, callback) {
186 | throw {name: "NotImplemented", message: "Not implemented yet"};
187 | },
188 | update: function(data, callback) {
189 | throw {name: "NotImplemented", message: "Not implemented yet"};
190 | },
191 | get: function(callback) {
192 | GET({
193 | path: "/users/" + user_id
194 | }, function(data) {
195 | if ( callback ) {
196 | callback(data);
197 | }
198 | });
199 | },
200 | update_password: function(id, password, callback) {
201 | throw {name: "NotImplemented", message: "Not implemented yet"};
202 | },
203 | linked_services: {
204 | get: function(callback) {
205 | GET({
206 | path: "/users/" + user_id + "/linked_services"
207 | }, function(data) {
208 | if ( callback ) {
209 | callback(data);
210 | }
211 | }
212 | );
213 | },
214 | create: function(data, callback) {
215 | throw {name: "NotImplemented", message: "Not implemented yet"};
216 | }
217 | },
218 | devices: function(device_type, callback) {
219 | if ( typeof device_type === 'function' ) {
220 | callback = device_type;
221 | device_type = 'wink_devices';
222 | }
223 |
224 | if ( cache.device_type[device_type] ) {
225 | callback(cache.device_type[device_type]);
226 | } else {
227 | GET({
228 | path: "/users/" + user_id + "/" + device_type
229 | }, function(data) {
230 | if(data && data.data) {
231 | for( var dataIndex in data.data ) {
232 | device = data.data[dataIndex];
233 | if ( device.light_bulb_id !== undefined ) {
234 | model.light_bulbs(device, wink);
235 | } else if ( device.eggtray_id !== undefined ) {
236 | model.eggtrays(device, wink);
237 | } else if ( device.thermostat_id !== undefined ) {
238 | model.thermostats(device, wink);
239 | }
240 | }
241 | }
242 | if (data && ! process.env.WINK_NO_CACHE ) {
243 | cache.device_type[device_type] = data;
244 | }
245 | callback(data);
246 | });
247 | }
248 |
249 | },
250 | device: function(device_name, callback) {
251 | // TODO: cache response from devices
252 | // and if device is not found, retry all
253 | // devices
254 | if ( cache.device[device_name] ) {
255 | callback(cache.device[device_name]);
256 | } else {
257 | wink.user(user_id).devices(function(data) {
258 | var name = new RegExp('^' + device_name + '$', 'i');
259 | var device = undefined;
260 | if( data && data.data) {
261 | for( var dataIndex in data.data ) {
262 | if ( name.test(data.data[dataIndex].name) ) {
263 | device = data.data[dataIndex];
264 | if ( device.light_bulb_id !== undefined ) {
265 | model.light_bulbs(device, wink);
266 | } else if ( device.eggtray_id !== undefined ) {
267 | model.eggtrays(device, wink);
268 | } else if ( device.thermostat_id !== undefined ) {
269 | model.thermostats(device, wink);
270 | }
271 | break;
272 | }
273 | }
274 | }
275 | debug("returning device:", device);
276 | if (! process.env.WINK_NO_CACHE) {
277 | cache.device[device_name] = device;
278 | }
279 | callback(device);
280 | });
281 | }
282 |
283 | },
284 | groups: {
285 | get: function(callback) {
286 | GET({
287 | path: "/users/me/groups"
288 | }, function(data) {
289 | debug(data);
290 | callback(data);
291 | });
292 | },
293 | create: function(callback) {
294 | throw {name: "NotImplemented", message: "Not implemented yet"};
295 | }
296 | },
297 | group: {
298 | name: function(name, callback) {
299 | name = name.toLowerCase();
300 |
301 | async.waterfall([
302 | function(next) {
303 | wink.user(user_id).groups.get(function(data) {
304 | if (data){
305 | next(null, data);
306 | } else {
307 | next("error");
308 | }
309 | });
310 | },
311 | function(data, next) {
312 | var match = null;
313 | data.data.some(function(group, index) {
314 | if(group.name.toLowerCase() == name) {
315 | match = group;
316 | return true;
317 | } else {
318 | return false;
319 | }
320 | });
321 | next(null, match);
322 | }
323 | ], function(err, data) {
324 | callback(data);
325 | });
326 | },
327 | id: function(id, callback) {
328 | GET({
329 | path: "/groups/" + id
330 | }, function(data) {
331 | debug(data);
332 | callback(data);
333 | });
334 | }
335 | },
336 | robots: {
337 | get: function(callback) {
338 | GET({
339 | path: "/users/" + user_id + "/robots"
340 | }, function(data) {
341 | if(data && data.data) {
342 | for( var dataIndex in data.data ) {
343 | device = data.data[dataIndex];
344 | model.robots(device, wink);
345 | if (! process.env.WINK_NO_CACHE) {
346 | cache.robot[device.robot_id] = device;
347 | }
348 | }
349 | callback(data);
350 | }
351 | });
352 | },
353 | create: function(data, callback) {
354 | throw {name: "NotImplemented", message: "Not implemented yet"};
355 | }
356 | },
357 | scenes: {
358 | get: function(callback) {
359 | GET({
360 | path: "/users/" + user_id + "/scenes"
361 | }, function(data) {
362 | callback(data);
363 | });
364 | },
365 | create: function(data, callback) {
366 | throw {name: "NotImplemented", message: "Not implemented yet"};
367 | }
368 | }
369 | }
370 | },
371 | robot_id: function(robot_id) {
372 | return {
373 | get: function(callback) {
374 | if(cache.robot[robot_id]) {
375 | callback(cache.robot[robot_id]);
376 | }
377 | else {
378 | GET({
379 | path: "/robots/"+robot_id
380 | },function(data) {
381 | model.robots(data.data,wink);
382 | if (! process.env.WINK_NO_CACHE) {
383 | cache.robot[data.data.robot_id] = data.data;
384 | }
385 | callback(data.data);
386 | });
387 | }
388 | },
389 | update: function(data,callback) {
390 | PUT({
391 | path: "/robots/"+robot_id,
392 | data: data
393 | },function(data) {
394 | callback(data);
395 | });
396 | }
397 | }
398 | },
399 | device_group: function(device_group) {
400 | return {
401 | device_id: function(device_id) {
402 | return {
403 | get: function(callback) {
404 | GET({
405 | path: "/" + device_group + "/" + device_id
406 | }, function(data) {
407 | // inflate object with available methods
408 | // based on a group
409 | if ( device_group === "light_bulbs" ) {
410 | model.light_bulbs(data, wink);
411 | } else if (device_group === "eggtrays" ) {
412 | model.eggtrays(data, wink);
413 | } else if (device_group === "thermostats" ) {
414 | model.thermostats(data, wink);
415 | }
416 | callback(data);
417 | });
418 | },
419 | update: function(data, callback) {
420 | PUT({
421 | path: "/" + device_group + "/" + device_id,
422 | data: data
423 | }, function(data) {
424 | callback(data);
425 | });
426 | },
427 | refresh: function(callback) {
428 | POST({
429 | path: "/" + device_group + "/" + device_id + "/refresh"
430 | }, function(data) {
431 | callback(data);
432 | });
433 | },
434 | share: {
435 | get: function(callback) {
436 | GET({
437 | path: "/" + device_group + "/" + device_id + "/users"
438 | }, function(data) {
439 | callback(data);
440 | });
441 | },
442 | create: function(user_id, callback) {
443 | throw {name: "NotImplemented", message: "Not implemented yet"};
444 | }
445 | },
446 | unshare: function(email, callback) {
447 | DELETE({
448 | path: "/" + device_group + "/" + device_id + "/users/" + email
449 | }, function(data) {
450 | callback(data);
451 | });
452 | }
453 | }
454 | }
455 | };
456 | }
457 | }
458 |
459 | module.exports = wink;
460 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # wink-js
2 |
3 | **wink-js** is a library that allows one to access [Wink](http://www.wink.com/) API resources from a user perspective. Its target is to simplify integrations with the Wink backend and hopefully allow more people to create fun applications for your Wink connected home.
4 |
5 | **This is not an official library from Wink, please do not contact them for support, however you can always open bugs against this project on GitHub.**
6 |
7 | This library currently uses Wink API v1. Documentation:
8 |
9 |
10 | ## Devices with helpers
11 | - *Lights*
12 | - *Thermostats*
13 | - *Eggminder*
14 |
15 | **Devices can be used via raw getter and setter device_group()**
16 |
17 |
18 | ## Synopsis
19 |
20 | ```javascript
21 | var wink = require('wink-js');
22 |
23 | wink.init({
24 | "client_id": "xxx",
25 | "client_secret": "xxx",
26 | "username": "xxx@example.com",
27 | "password": "Xx*.x!"
28 | }, function(auth_return) {
29 | if ( auth_return === undefined ) {
30 | // error
31 | } else {
32 | // success
33 | wink.user().device('Kitchen lights', function(device) {
34 | device.power.off(function(response) {
35 | if (response === undefined) {
36 | // error
37 | } else {
38 | // success
39 | }
40 | });
41 | });
42 | }
43 | });
44 | ```
45 | ## Methods
46 | # .init()
47 | Initialize wink framework (performs login)
48 |
49 | ```javascript
50 | wink.init(obj, callback);
51 | ```
52 | * **obj**
53 | * **conf:** path to configuraiton file with settings below (*optional*)
54 | * **client_id:** Client id issued by wink support
55 | * **client_secret:** Client secret issued by wink support
56 | * **username:** username(email) used to login to wink app
57 | * **password:** password used to login to wink app
58 |
59 | ```javascript
60 | wink.init({
61 | "client_id": "xxx",
62 | "client_secret": "xxx",
63 | "username": "xxx@example.com",
64 | "password": "Xx*.x!"
65 | });
66 |
67 | wink.init({
68 | conf: "/path/to/config.json"
69 | }, callback);
70 |
71 | /*
72 | # config.json:
73 | {
74 | "client_id": "CLIENT_ID_HERE",
75 | "client_secret": "CLIENT_SECRET_HERE",
76 | "username": "WINK_EMAIL_HERE",
77 | "password": "WINK_PASSWORD_HERE"
78 | }
79 | */
80 | ```
81 |
82 | response:
83 | ```javascript
84 | // callback(data)
85 | {
86 | "data": {
87 | "access_token": "xxx",
88 | "refresh_token": "xxx",
89 | "token_type": "bearer",
90 | "token_endpoint": "https://api.wink.com/oauth2/token"
91 | },
92 | "errors": [],
93 | "pagination": {},
94 | "access_token": "xxx",
95 | "refresh_token": "xxx",
96 | "token_type": "bearer",
97 | "token_endpoint": "https://api.wink.com/oauth2/token"
98 | }
99 | ```
100 |
101 |
102 | ---
103 | # .user()
104 | Perform operations on behalf of a user
105 |
106 | ```javasript
107 | wink.user(userId);
108 | ```
109 |
110 | * **userId:** defaults to "me" (logged in user)
111 |
112 | ## .get(callback)
113 | Retrieve user information
114 |
115 | ```javascript
116 | wink.user().get(callback);
117 | ```
118 |
119 | response:
120 |
121 | ```javascript
122 | // callback(data)
123 | {
124 | "data": {
125 | "user_id": "1234",
126 | "first_name": "John",
127 | "last_name": "Doe",
128 | "email": "myemail@example.com",
129 | "locale": "en_us",
130 | "units": {},
131 | "tos_accepted": true,
132 | "confirmed": true,
133 | "last_reading": {
134 | "units": null,
135 | "units_updated_at": null,
136 | "desired_units": null,
137 | "desired_units_updated_at": null
138 | }
139 | },
140 | "errors": [],
141 | "pagination": {}
142 | }
143 | ```
144 |
145 | ## .linked_services
146 | Linked wink services namespace
147 |
148 | ### .get(callback)
149 | Retrieve list of linked services
150 |
151 | ```javascript
152 | wink.user().linked_services.get(callback);
153 | ```
154 |
155 | response:
156 | ```javascript
157 | // callback(data)
158 | {
159 | "data": [],
160 | "errors": [],
161 | "pagination": {
162 | "count": 0
163 | }
164 | }
165 | ```
166 |
167 | ## .devices(device_type?, callback)
168 | Retrieve list of devices associated with account, and inflates each
169 | device into its respective object with availabe actions, for more
170 | details on available actions, see **Models** section
171 |
172 | ```javascript
173 | wink.user().devices(callback);
174 | wink.user().devices('light_bulbs', callback);
175 | ```
176 |
177 | * **device_type (*optional*):** defaulted to "wink_devices"
178 |
179 | response:
180 |
181 | ```javascript
182 | // callback(data)
183 | {
184 | "data": [
185 | {
186 | "hub_id": "xxx",
187 | "name": "Hub",
188 | "locale": "en_us",
189 | "units": {},
190 | "created_at": 1425689198,
191 | "hidden_at": null,
192 | "capabilities": {
193 | "oauth2_clients": [
194 | "wink_hub"
195 | ]
196 | },
197 | "triggers": [],
198 | "desired_state": {
199 | "pairing_mode": null
200 | },
201 | "manufacturer_device_model": "wink_hub",
202 | "manufacturer_device_id": null,
203 | "device_manufacturer": "wink",
204 | "model_name": "Hub",
205 | "upc_id": "15",
206 | "last_reading": {
207 | "connection": true,
208 | "connection_updated_at": 1429500244.4901872,
209 | "agent_session_id": "xxx",
210 | "agent_session_id_updated_at": 1429500216.915741,
211 | "remote_pairable": true,
212 | "remote_pairable_updated_at": 1428161420.4011638,
213 | "updating_firmware": false,
214 | "updating_firmware_updated_at": 1429500216.2100337,
215 | "app_rootfs_version": "00.86",
216 | "app_rootfs_version_updated_at": 1429500217.4185543,
217 | "firmware_version": "0.86.0",
218 | "firmware_version_updated_at": 1429500217.4185324,
219 | "update_needed": false,
220 | "update_needed_updated_at": 1429500217.4185612,
221 | "mac_address": "xxx",
222 | "mac_address_updated_at": 1429500217.41854,
223 | "ip_address": "10.0.1.7",
224 | "ip_address_updated_at": 1429500217.4185476,
225 | "hub_version": "00.01",
226 | "hub_version_updated_at": 1429500217.418519,
227 | "pairing_mode": null,
228 | "pairing_mode_updated_at": 1427841692.0884776,
229 | "desired_pairing_mode": null,
230 | "desired_pairing_mode_updated_at": 1427841692.088467
231 | },
232 | "lat_lng": [
233 | 26.010181,
234 | -80.146535
235 | ],
236 | "location": "",
237 | "configuration": {
238 | "kidde_radio_code": 0
239 | },
240 | "update_needed": false,
241 | "uuid": "xxx"
242 | },
243 | {
244 | "light_bulb_id": "xxx",
245 | "name": "Office",
246 | "locale": "en_us",
247 | "units": {},
248 | "created_at": 1425698691,
249 | "hidden_at": null,
250 | "capabilities": {},
251 | "triggers": [],
252 | "desired_state": {
253 | "powered": true,
254 | "brightness": 1
255 | },
256 | "manufacturer_device_model": "ge_",
257 | "manufacturer_device_id": null,
258 | "device_manufacturer": "ge",
259 | "model_name": "GE light bulb",
260 | "upc_id": "xxx",
261 | "hub_id": "xxx",
262 | "local_id": "1",
263 | "radio_type": "zigbee",
264 | "linked_service_id": null,
265 | "last_reading": {
266 | "connection": true,
267 | "connection_updated_at": 1429500818.8442252,
268 | "firmware_version": "0.1b03 / 0.4b00",
269 | "firmware_version_updated_at": 1429500818.8442593,
270 | "firmware_date_code": "20140812",
271 | "firmware_date_code_updated_at": 1429500818.8442357,
272 | "powered": true,
273 | "powered_updated_at": 1429500818.844245,
274 | "brightness": 1,
275 | "brightness_updated_at": 1429500818.844252,
276 | "desired_powered": true,
277 | "desired_powered_updated_at": 1428490204.9604716,
278 | "desired_brightness": 1,
279 | "desired_brightness_updated_at": 1425698897.9915164
280 | },
281 | "lat_lng": [
282 | null,
283 | null
284 | ],
285 | "location": "",
286 | "order": 0
287 | },
288 | {
289 | "last_reading": {
290 | "connection": null,
291 | "connection_updated_at": null,
292 | "battery": 0.18,
293 | "battery_updated_at": 1429497969.3582497,
294 | "inventory": 1,
295 | "inventory_updated_at": 1429497969.3756864,
296 | "age": 1429454667,
297 | "age_updated_at": 1429497969.3756976,
298 | "freshness_remaining": 1771098,
299 | "freshness_remaining_updated_at": 1429497969.375706,
300 | "egg_1_timestamp": 0,
301 | "egg_1_timestamp_updated_at": 1429497969.3104246,
302 | "egg_2_timestamp": 0,
303 | "egg_2_timestamp_updated_at": 1429497969.310436,
304 | "egg_3_timestamp": 0,
305 | "egg_3_timestamp_updated_at": 1429497969.3104434,
306 | "egg_4_timestamp": 0,
307 | "egg_4_timestamp_updated_at": 1429497969.310451,
308 | "egg_5_timestamp": 0,
309 | "egg_5_timestamp_updated_at": 1429497969.3104584,
310 | "egg_6_timestamp": 0,
311 | "egg_6_timestamp_updated_at": 1429497969.310465,
312 | "egg_7_timestamp": 0,
313 | "egg_7_timestamp_updated_at": 1429497969.3104732,
314 | "egg_8_timestamp": 0,
315 | "egg_8_timestamp_updated_at": 1429497969.3104823,
316 | "egg_9_timestamp": 0,
317 | "egg_9_timestamp_updated_at": 1429497969.3104892,
318 | "egg_10_timestamp": 0,
319 | "egg_10_timestamp_updated_at": 1429497969.310498,
320 | "egg_11_timestamp": 0,
321 | "egg_11_timestamp_updated_at": 1429497969.3105059,
322 | "egg_12_timestamp": 1429454667,
323 | "egg_12_timestamp_updated_at": 1429497969.3105128,
324 | "egg_13_timestamp": 0,
325 | "egg_13_timestamp_updated_at": 1429497969.3105197,
326 | "egg_14_timestamp": 0,
327 | "egg_14_timestamp_updated_at": 1429497969.3105266
328 | },
329 | "eggs": [
330 | 0,
331 | 0,
332 | 0,
333 | 0,
334 | 0,
335 | 0,
336 | 0,
337 | 0,
338 | 0,
339 | 0,
340 | 0,
341 | 1429454667,
342 | 0,
343 | 0
344 | ],
345 | "freshness_period": 1814400,
346 | "eggtray_id": "147424",
347 | "name": "Egg Minder",
348 | "locale": "en_us",
349 | "units": {},
350 | "created_at": 1425701549,
351 | "hidden_at": null,
352 | "capabilities": {},
353 | "triggers": [],
354 | "device_manufacturer": "quirky_ge",
355 | "model_name": "Egg Minder",
356 | "upc_id": "23",
357 | "lat_lng": [
358 | 26.496337,
359 | -80.063654
360 | ],
361 | "location": "",
362 | "mac_address": "xxx",
363 | "serial": "xxx"
364 | },
365 | {
366 | "light_bulb_id": "xxx",
367 | "name": "Stairs",
368 | "locale": "en_us",
369 | "units": {},
370 | "created_at": 1426846362,
371 | "hidden_at": null,
372 | "capabilities": {},
373 | "triggers": [],
374 | "desired_state": {
375 | "powered": false,
376 | "brightness": 1
377 | },
378 | "manufacturer_device_model": "lutron_p_pkg1_p_wh_d",
379 | "manufacturer_device_id": null,
380 | "device_manufacturer": "lutron",
381 | "model_name": "Caseta Lamp Dimmer & Pico",
382 | "upc_id": "xx",
383 | "hub_id": "xxx",
384 | "local_id": "2",
385 | "radio_type": "lutron",
386 | "linked_service_id": null,
387 | "last_reading": {
388 | "connection": true,
389 | "connection_updated_at": 1429500245.3731902,
390 | "powered": false,
391 | "powered_updated_at": 1429500245.3732066,
392 | "brightness": 1,
393 | "brightness_updated_at": 1429500245.3731997,
394 | "desired_powered": false,
395 | "desired_powered_updated_at": 1429328338.4158955,
396 | "desired_brightness": 1,
397 | "desired_brightness_updated_at": 1427330529.0827518
398 | },
399 | "lat_lng": [
400 | null,
401 | null
402 | ],
403 | "location": "",
404 | "order": 0
405 | },
406 | {
407 | "remote_id": "xxx",
408 | "name": "Stairs up wallmount",
409 | "members": [
410 | {
411 | "object_type": "light_bulb",
412 | "object_id": "xxx",
413 | "desired_state": {
414 | "powered": false,
415 | "powered_updated_at": 1429328338.4158955,
416 | "brightness": 1,
417 | "brightness_updated_at": 1427330529.0827518
418 | }
419 | }
420 | ],
421 | "locale": "en_us",
422 | "units": {},
423 | "created_at": 1426847605,
424 | "hidden_at": null,
425 | "capabilities": {},
426 | "desired_state": {},
427 | "device_manufacturer": "lutron",
428 | "model_name": "Pico",
429 | "upc_id": "xx",
430 | "hub_id": "xxx",
431 | "local_id": "3",
432 | "radio_type": "lutron",
433 | "last_reading": {
434 | "connection": null,
435 | "connection_updated_at": null,
436 | "remote_pairable": true,
437 | "remote_pairable_updated_at": 1428161420.4384034
438 | },
439 | "lat_lng": [
440 | 26.496324,
441 | -80.063659
442 | ],
443 | "location": ""
444 | },
445 | {
446 | "remote_id": "xxx",
447 | "name": "Stairs detached",
448 | "members": [
449 | {
450 | "object_type": "light_bulb",
451 | "object_id": "xxx",
452 | "desired_state": {
453 | "powered": false,
454 | "powered_updated_at": 1429328338.4158955,
455 | "brightness": 1,
456 | "brightness_updated_at": 1427330529.0827518
457 | }
458 | }
459 | ],
460 | "locale": "en_us",
461 | "units": {},
462 | "created_at": 1426896325,
463 | "hidden_at": null,
464 | "capabilities": {},
465 | "desired_state": {},
466 | "device_manufacturer": "lutron",
467 | "model_name": "Pico",
468 | "upc_id": "xx",
469 | "hub_id": "xxx",
470 | "local_id": "4",
471 | "radio_type": "lutron",
472 | "last_reading": {
473 | "connection": null,
474 | "connection_updated_at": null,
475 | "remote_pairable": true,
476 | "remote_pairable_updated_at": 1428161420.4671366
477 | },
478 | "lat_lng": [
479 | 26.481714,
480 | -80.0851
481 | ],
482 | "location": ""
483 | },
484 | {
485 | "light_bulb_id": "111",
486 | "name": "Kitchen",
487 | "locale": "en_us",
488 | "units": {},
489 | "created_at": 1427841678,
490 | "hidden_at": null,
491 | "capabilities": {},
492 | "triggers": [],
493 | "desired_state": {
494 | "powered": false,
495 | "brightness": 0.76
496 | },
497 | "manufacturer_device_model": "lutron_p_pkg1_w_wh_d",
498 | "manufacturer_device_id": null,
499 | "device_manufacturer": "lutron",
500 | "model_name": "Caseta Wireless Dimmer & Pico",
501 | "upc_id": "3",
502 | "hub_id": "xxx",
503 | "local_id": "5",
504 | "radio_type": "lutron",
505 | "linked_service_id": null,
506 | "last_reading": {
507 | "connection": true,
508 | "connection_updated_at": 1429500246.530256,
509 | "powered": false,
510 | "powered_updated_at": 1429500246.5302837,
511 | "brightness": 0.76,
512 | "brightness_updated_at": 1429500246.5302727,
513 | "desired_powered": false,
514 | "desired_powered_updated_at": 1429495229.6978345,
515 | "desired_brightness": 0.76,
516 | "desired_brightness_updated_at": 1429500246.5847015
517 | },
518 | "lat_lng": [
519 | 26.49635,
520 | -80.063667
521 | ],
522 | "location": "",
523 | "order": 0
524 | },
525 | {
526 | "hub_id": "xxx",
527 | "name": "Hub",
528 | "locale": "en_us",
529 | "units": {},
530 | "created_at": 1429049123,
531 | "hidden_at": null,
532 | "capabilities": {},
533 | "triggers": [],
534 | "desired_state": {
535 | "pairing_mode": null
536 | },
537 | "manufacturer_device_model": "philips",
538 | "manufacturer_device_id": "xxx",
539 | "device_manufacturer": null,
540 | "model_name": null,
541 | "upc_id": null,
542 | "last_reading": {
543 | "connection": true,
544 | "connection_updated_at": 1429049123.3954115,
545 | "agent_session_id": null,
546 | "agent_session_id_updated_at": null,
547 | "remote_pairable": null,
548 | "remote_pairable_updated_at": null,
549 | "updating_firmware": null,
550 | "updating_firmware_updated_at": null,
551 | "app_rootfs_version": null,
552 | "app_rootfs_version_updated_at": null,
553 | "firmware_version": null,
554 | "firmware_version_updated_at": null,
555 | "update_needed": false,
556 | "update_needed_updated_at": 1429049123.3314805,
557 | "mac_address": null,
558 | "mac_address_updated_at": null,
559 | "ip_address": null,
560 | "ip_address_updated_at": null,
561 | "hub_version": null,
562 | "hub_version_updated_at": null,
563 | "pairing_mode": null,
564 | "pairing_mode_updated_at": null,
565 | "desired_pairing_mode": null,
566 | "desired_pairing_mode_updated_at": null
567 | },
568 | "lat_lng": [
569 | null,
570 | null
571 | ],
572 | "location": "",
573 | "configuration": null,
574 | "update_needed": false,
575 | "uuid": "xxx"
576 | },
577 | {
578 | "light_bulb_id": "xxx",
579 | "name": "LightStrips 2",
580 | "locale": "en_us",
581 | "units": {},
582 | "created_at": 1429049124,
583 | "hidden_at": 1429203619,
584 | "capabilities": {},
585 | "triggers": [],
586 | "desired_state": {
587 | "powered": true,
588 | "brightness": 1
589 | },
590 | "manufacturer_device_model": "LST001",
591 | "manufacturer_device_id": "xxx",
592 | "device_manufacturer": "philips",
593 | "model_name": "HUE A19 Lighting Kit",
594 | "upc_id": "1",
595 | "hub_id": "137069",
596 | "local_id": "2",
597 | "radio_type": null,
598 | "linked_service_id": null,
599 | "last_reading": {
600 | "connection": true,
601 | "connection_updated_at": 1429049124.3448753,
602 | "powered": null,
603 | "powered_updated_at": null,
604 | "brightness": null,
605 | "brightness_updated_at": null,
606 | "desired_powered": true,
607 | "desired_powered_updated_at": 1429049124.2762687,
608 | "desired_brightness": 1,
609 | "desired_brightness_updated_at": 1429049124.2762783
610 | },
611 | "lat_lng": [
612 | null,
613 | null
614 | ],
615 | "location": "",
616 | "order": 0
617 | },
618 | {
619 | "light_bulb_id": "xxx",
620 | "name": "LightStrips 1",
621 | "locale": "en_us",
622 | "units": {},
623 | "created_at": 1429049124,
624 | "hidden_at": 1429321559,
625 | "capabilities": {},
626 | "triggers": [],
627 | "desired_state": {
628 | "powered": true,
629 | "brightness": 1
630 | },
631 | "manufacturer_device_model": "LST001",
632 | "manufacturer_device_id": "xxx",
633 | "device_manufacturer": "philips",
634 | "model_name": "HUE A19 Lighting Kit",
635 | "upc_id": "1",
636 | "hub_id": "xxx",
637 | "local_id": "1",
638 | "radio_type": null,
639 | "linked_service_id": null,
640 | "last_reading": {
641 | "connection": true,
642 | "connection_updated_at": 1429049124.4880855,
643 | "powered": null,
644 | "powered_updated_at": null,
645 | "brightness": null,
646 | "brightness_updated_at": null,
647 | "desired_powered": true,
648 | "desired_powered_updated_at": 1429049124.393545,
649 | "desired_brightness": 1,
650 | "desired_brightness_updated_at": 1429049124.3935578
651 | },
652 | "lat_lng": [
653 | null,
654 | null
655 | ],
656 | "location": "",
657 | "order": 0
658 | }
659 | ],
660 | "errors": [],
661 | "pagination": {
662 | "count": 10
663 | }
664 | }
665 | ```
666 |
667 | ## .device(device_name, callback)
668 | Retrieve device by its name
669 |
670 | ```javascript
671 | wink.user().device('Office lights', function(light_obj){
672 | // do whatever with light object
673 | });
674 | ```
675 |
676 | ## .device_group(group).device_id(id).get(callback)
677 | Retrieve device by its group and unique id
678 |
679 | ```javascript
680 | wink.user().device_group('light_bulbs').device_id(123).get(
681 | function(light_obj){
682 | // do whatever with light object
683 | }
684 | );
685 | ```
686 | ## .device_group(group).device_id(id).update(data,callback)
687 | Update device
688 |
689 | ```javascript
690 | wink.user().device_group('light_bulbs').device_id(123).update(
691 | {
692 | "desired_state": {
693 | "powered": false
694 | }
695 | }, function(light_obj) {
696 | // do whatever with light object
697 | }
698 | );
699 | ```
700 |
701 | ---
702 |
703 | # Models
704 |
705 | ### device_group
706 | *String* device type id: "light_bulbs"
707 |
708 | ### device_id
709 | *Number* device identifier
710 |
711 | ===
712 |
713 | ## Lights (light_bulbs group)
714 |
715 | ### brightness(level, callback)
716 | Set level of brighntess (0-100);
717 |
718 | ### *power*
719 |
720 | #### on(callback)
721 | turn on lights
722 |
723 | #### off(callback)
724 | turn off lights
725 |
726 | #### toggle(callback)
727 | toggle lights
728 |
729 |
730 | ```javascript
731 | wink.user().device('Stairs', function(device) {
732 | device.power.on(callback);
733 | });
734 | wink.user().device('Stairs', function(device) {
735 | device.power.off(callback);
736 | });
737 | wink.user().device('Stairs', function(device) {
738 | device.power.toggle(callback);
739 | });
740 | wink.user().device('Stairs', function(device) {
741 | device.brightness(50, callback);
742 | });
743 | ```
744 |
745 | raw response from wink:
746 |
747 | ```javascript
748 | {
749 | "light_bulb_id": "xxx",
750 | "name": "Stairs",
751 | "locale": "en_us",
752 | "units": {},
753 | "created_at": 1426846362,
754 | "hidden_at": null,
755 | "capabilities": {},
756 | "triggers": [],
757 | "desired_state": {
758 | "powered": false,
759 | "brightness": 1
760 | },
761 | "manufacturer_device_model": "lutron_p_pkg1_p_wh_d",
762 | "manufacturer_device_id": null,
763 | "device_manufacturer": "lutron",
764 | "model_name": "Caseta Lamp Dimmer & Pico",
765 | "upc_id": "33",
766 | "hub_id": "114516",
767 | "local_id": "2",
768 | "radio_type": "lutron",
769 | "linked_service_id": null,
770 | "last_reading": {
771 | "connection": true,
772 | "connection_updated_at": 1429500245.3731902,
773 | "powered": false,
774 | "powered_updated_at": 1429500245.3732066,
775 | "brightness": 1,
776 | "brightness_updated_at": 1429500245.3731997,
777 | "desired_powered": false,
778 | "desired_powered_updated_at": 1429328338.4158955,
779 | "desired_brightness": 1,
780 | "desired_brightness_updated_at": 1427330529.0827518
781 | },
782 | "lat_lng": [
783 | null,
784 | null
785 | ],
786 | "location": "",
787 | "order": 0
788 | }
789 | ```
790 |
791 | ## Eggtray
792 |
793 | ### quantity
794 | *Number* Returns quantity of eggs
795 |
796 | raw response:
797 |
798 | ```javascript
799 | {
800 | "last_reading": {
801 | "connection": null,
802 | "connection_updated_at": null,
803 | "battery": 0.18,
804 | "battery_updated_at": 1429541274.5857081,
805 | "inventory": 1,
806 | "inventory_updated_at": 1429541274.631489,
807 | "age": 1429454667,
808 | "age_updated_at": 1429541274.6315,
809 | "freshness_remaining": 1727793,
810 | "freshness_remaining_updated_at": 1429541274.6315074,
811 | "egg_1_timestamp": 0,
812 | "egg_1_timestamp_updated_at": 1429541274.5594687,
813 | "egg_2_timestamp": 0,
814 | "egg_2_timestamp_updated_at": 1429541274.559478,
815 | "egg_3_timestamp": 0,
816 | "egg_3_timestamp_updated_at": 1429541274.5594845,
817 | "egg_4_timestamp": 0,
818 | "egg_4_timestamp_updated_at": 1429541274.5594902,
819 | "egg_5_timestamp": 0,
820 | "egg_5_timestamp_updated_at": 1429541274.5594962,
821 | "egg_6_timestamp": 0,
822 | "egg_6_timestamp_updated_at": 1429541274.5595021,
823 | "egg_7_timestamp": 0,
824 | "egg_7_timestamp_updated_at": 1429541274.559508,
825 | "egg_8_timestamp": 0,
826 | "egg_8_timestamp_updated_at": 1429541274.5595133,
827 | "egg_9_timestamp": 0,
828 | "egg_9_timestamp_updated_at": 1429541274.559519,
829 | "egg_10_timestamp": 0,
830 | "egg_10_timestamp_updated_at": 1429541274.5595248,
831 | "egg_11_timestamp": 0,
832 | "egg_11_timestamp_updated_at": 1429541274.5595305,
833 | "egg_12_timestamp": 1429454667,
834 | "egg_12_timestamp_updated_at": 1429541274.5595367,
835 | "egg_13_timestamp": 0,
836 | "egg_13_timestamp_updated_at": 1429541274.559543,
837 | "egg_14_timestamp": 0,
838 | "egg_14_timestamp_updated_at": 1429541274.5595486
839 | },
840 | "eggs": [
841 | 0,
842 | 0,
843 | 0,
844 | 0,
845 | 0,
846 | 0,
847 | 0,
848 | 0,
849 | 0,
850 | 0,
851 | 0,
852 | 1429454667,
853 | 0,
854 | 0
855 | ],
856 | "freshness_period": 1814400,
857 | "eggtray_id": "xxx",
858 | "name": "Egg Minder",
859 | "locale": "en_us",
860 | "units": {},
861 | "created_at": 1425701549,
862 | "hidden_at": null,
863 | "capabilities": {},
864 | "triggers": [],
865 | "device_manufacturer": "quirky_ge",
866 | "model_name": "Egg Minder",
867 | "upc_id": "23",
868 | "lat_lng": [
869 | 26.496337,
870 | -80.063654
871 | ],
872 | "location": "",
873 | "mac_address": "xxx",
874 | "serial": "xxx"
875 | }
876 | ```
877 |
878 | ## Thermostat
879 |
880 | ### temperature(max, min, unit, callback)
881 | Change temperature, where:
882 | - max is maximum temperature is going to reach
883 | - min is minimum temperature can fall
884 | - unit should be 'c' or 'f' (Celsius or Fahrenheit)
885 | - callback(return) results status
886 |
887 | ```javascript
888 | wink.user().device('Downstairs Thermostat', function(device) {
889 | device.temperature(72, 71, 'f', function(return){
890 | if (!return) { console.log('error'); }
891 | });
892 | });
893 | ```
894 |
895 | ### temperature(max, unit?, callback?)
896 | Change temperature, where:
897 | - max is maximum temperature is going to reach
898 | - unit should be 'c' or 'f' (Celsius or Fahrenheit)
899 | - callback(return) results status
900 |
901 | *min temperature is going to default to max - 2 degrees in specified units*
902 |
903 | ```javascript
904 | wink.user().device('Downstairs Thermostat', function(device) {
905 | device.temperature(72, 'f', function(return){
906 | if (!return) { console.log('error'); }
907 | });
908 | });
909 | ```
910 |
911 | ### temperature(max, callback)
912 | Change temperature, where:
913 | - max is maximum temperature is going to reach
914 | - callback(return) results status
915 |
916 | *unit is going to default to setting in the thermostat*
917 |
918 | ```javascript
919 | wink.user().device('Downstairs Thermostat', function(device) {
920 | device.temperature(72, function(return){
921 | if (!return) { console.log('error'); }
922 | });
923 | });
924 | ```
925 |
926 | ### temperature(max, unit, callback)
927 | Change temperature, where:
928 | - max is maximum temperature is going to reach
929 | - unit should be 'c' or 'f' (Celsius or Fahrenheit)
930 | - callback(return) results status
931 |
932 | ```javascript
933 | wink.user().device('Downstairs Thermostat', function(device) {
934 | device.temperature(72, 'f', function(return){
935 | if (!return) { console.log('error'); }
936 | });
937 | });
938 | ```
939 |
940 | ### temperature(max, min, callback)
941 | Change temperature, where:
942 | - max is maximum temperature is going to reach
943 | - min is minimum temperature can fall
944 | - callback(return) results status
945 |
946 | *unit is going to default to setting in the thermostat*
947 |
948 | ```javascript
949 | wink.user().device('Downstairs Thermostat', function(device) {
950 | device.temperature(72, 70, function(return){
951 | if (!return) { console.log('error'); }
952 | });
953 | });
954 | ```
955 |
956 | ### temperature(callback)
957 | Get temperature:
958 | - callback(temp)
959 |
960 | *unit is going to default to setting in the thermostat*
961 |
962 | ```javascript
963 | wink.user().device('Downstairs Thermostat', function(device) {
964 | device.temperature(function(temp){
965 | console.log('temperature in celsius:', temp);
966 | });
967 | });
968 | ```
969 |
970 | ### temperature()
971 | Returns temperature:
972 |
973 | *unit is going to default to setting in the thermostat*
974 |
975 | ```javascript
976 | wink.user().device('Downstairs Thermostat', function(device) {
977 | var temp_in_c = device.temperature();
978 | });
979 | ```
980 |
981 | ### temperature(unit)
982 | Returns temperature in specified unit
983 |
984 | - unit can be 'c' or 'f'
985 |
986 | ```javascript
987 | wink.user().device('Downstairs Thermostat', function(device) {
988 | var temp_in_c = device.temperature('c');
989 | });
990 | ```
991 |
992 | ### temperature(unit, callback)
993 | Returns temperature in specified unit
994 |
995 | - unit can be 'c' or 'f'
996 | - callback(temp)
997 |
998 | * temp is rounded, when unit is set to 'f'
999 |
1000 | ```javascript
1001 | wink.user().device('Downstairs Thermostat', function(device) {
1002 | device.temperature('f', function(temp) {
1003 | console.log("temp in f:", temp);
1004 | });
1005 | });
1006 | ```
1007 |
1008 | complete object dump:
1009 | ```javascript
1010 | {
1011 | "thermostat_id": "54114",
1012 | "name": "Home Downstairs Thermostat",
1013 | "locale": "en_us",
1014 | "units": {
1015 | "temperature": "f"
1016 | },
1017 | "created_at": 1430018697,
1018 | "hidden_at": null,
1019 | "capabilities": {},
1020 | "triggers": [],
1021 | "desired_state": {
1022 | "mode": "cool_only",
1023 | "powered": true,
1024 | "min_set_point": 20,
1025 | "max_set_point": 22,
1026 | "users_away": false,
1027 | "fan_timer_active": false
1028 | },
1029 | "manufacturer_device_model": "nest",
1030 | "manufacturer_device_id": "zcx9ETvEqC3IdY6KyWEhbUxx11Qobba_",
1031 | "device_manufacturer": "nest",
1032 | "model_name": "Learning Thermostat",
1033 | "upc_id": "168",
1034 | "hub_id": null,
1035 | "local_id": null,
1036 | "radio_type": null,
1037 | "linked_service_id": "102939",
1038 | "last_reading": {
1039 | "connection": true,
1040 | "connection_updated_at": 1430080036.6664212,
1041 | "mode": "cool_only",
1042 | "mode_updated_at": 1430080036.6664522,
1043 | "powered": true,
1044 | "powered_updated_at": 1430080036.666473,
1045 | "min_set_point": 20,
1046 | "min_set_point_updated_at": 1430018767.7561078,
1047 | "max_set_point": 22,
1048 | "max_set_point_updated_at": 1430080036.6664915,
1049 | "users_away": false,
1050 | "users_away_updated_at": 1430080036.6665094,
1051 | "fan_timer_active": false,
1052 | "fan_timer_active_updated_at": 1430080036.666485,
1053 | "temperature": 23,
1054 | "temperature_updated_at": 1430080036.666439,
1055 | "external_temperature": null,
1056 | "external_temperature_updated_at": null,
1057 | "deadband": 1.5,
1058 | "deadband_updated_at": 1430080036.6664457,
1059 | "min_min_set_point": null,
1060 | "min_min_set_point_updated_at": null,
1061 | "max_min_set_point": null,
1062 | "max_min_set_point_updated_at": null,
1063 | "min_max_set_point": null,
1064 | "min_max_set_point_updated_at": null,
1065 | "max_max_set_point": null,
1066 | "max_max_set_point_updated_at": null,
1067 | "modes_allowed": [
1068 | "auto",
1069 | "heat_only",
1070 | "cool_only"
1071 | ],
1072 | "modes_allowed_updated_at": 1430080036.6664972,
1073 | "units": "f",
1074 | "units_updated_at": 1430080036.6664321,
1075 | "eco_target": false,
1076 | "eco_target_updated_at": 1430080036.6664586,
1077 | "manufacturer_structure_id": "mNN4pWJ2yWpMfFSjA_drSBU1RSNN0MXjiHypikpG4mwMnXS-pHxfPw",
1078 | "manufacturer_structure_id_updated_at": 1430080036.6664662,
1079 | "has_fan": true,
1080 | "has_fan_updated_at": 1430080036.6664789,
1081 | "fan_duration": 0,
1082 | "fan_duration_updated_at": 1430080036.6665034,
1083 | "last_error": "too_many_requests",
1084 | "last_error_updated_at": 1430019684.2469466,
1085 | "desired_mode": "cool_only",
1086 | "desired_mode_updated_at": 1430018697.5703063,
1087 | "desired_powered": true,
1088 | "desired_powered_updated_at": 1430018801.7444894,
1089 | "desired_min_set_point": 20,
1090 | "desired_min_set_point_updated_at": 1430018765.197387,
1091 | "desired_max_set_point": 22,
1092 | "desired_max_set_point_updated_at": 1430067786.578795,
1093 | "desired_users_away": false,
1094 | "desired_users_away_updated_at": 1430018697.5703213,
1095 | "desired_fan_timer_active": false,
1096 | "desired_fan_timer_active_updated_at": 1430018697.5703301
1097 | },
1098 | "lat_lng": [
1099 | 26.266677,
1100 | -80.127683
1101 | ],
1102 | "location": "",
1103 | "smart_schedule_enabled": false
1104 | }
1105 | ```
1106 |
--------------------------------------------------------------------------------
/mock-server/wink_api.md:
--------------------------------------------------------------------------------
1 | FORMAT: 1A
2 |
3 | HOST: https://api.wink.com
4 |
5 | # Wink API
6 | The Wink API connects Wink devices to users, apps, each other, and the wider web.
7 |
8 |
9 | # Group A RESTful Service
10 | The Wink API is a [RESTful](http://en.wikipedia.org/wiki/Representational_state_transfer) service.
11 |
12 | ## Authentication
13 | Nearly every request to the Wink API requires an OAuth bearer token.
14 |
15 | Exceptions to this rule will be documented.
16 |
17 | ## Content types
18 | Nearly every request to the Wink API should be expressed as JSON.
19 |
20 | Nearly every response from the Wink API will be expressed as JSON.
21 |
22 | Exceptions to this rule will be documented.
23 |
24 | ## HTTP verbs
25 | The Wink API uses HTTP verbs in pretty standard ways:
26 |
27 | - GET for retrieving information without side-effects
28 | - PUT for updating existing resources, with partial-update semantics supported
29 | - POST for creating new resources or blind upserts of existing resources
30 | - DELETE for destructive operations on existing resurces
31 |
32 | ## Identifiers
33 | A resource of type "foo" will typically have a field "foo_id", which is it's identifier. **Identifiers are strings**, even if they contain only numeric characters.
34 |
35 | A foo_id is guaranteed to be unique across all resources of type foo, but **need not be unique** across all resources in the API. If you are caching by id, make sure to include the resource type as well as the resource id as part of your cache key.
36 |
37 | It is possible for the API to re-assign identifiers to resources to rebalance keys; in this case, your resource will still exist but it (and all references to it) will be updated to the new identifier. Your application should be able to handle this case.
38 |
39 | ## Creatable vs. permanent
40 | The term "creatable" will describe a resource which may be created and/or destroyed by the user.
41 |
42 | The term "permanent" will describe a resource which may not be directly created or deleted by a user.
43 |
44 | Note that permanent **does not imply** that the resource will always exist, just that the user may not create or destroy it. Under no circumstances should you assume that a resource will always exist.
45 |
46 | ## Mutable vs. immutable
47 | The term "mutable" will describe a resource or attribute which the user may modify at will, assuming the user has the necessary permissions to do so.
48 |
49 | The term "immutable" will describe a resouce or attribute which may not be modified directly by the user.
50 |
51 | Note that immutable **does not imply** that the resource or attribute will never change, just that the user may not directly change it. Under no circumstances should you assume that a resource or attribute will always remain the same.
52 |
53 | ## Error states
54 | The common [HTTP Response Status Codes](https://github.com/for-GET/know-your-http-well/blob/master/status-codes.md) are used.
55 |
56 | # Group OAuth
57 | Authentication to the API
58 |
59 | ## Obtain access token [/oauth2/token]
60 | ### Sign in as user, or refresh user's expired access token [POST]
61 |
62 | Note that unlike most other calls, this call does not require (and in fact should not use) an OAuth 2.0 bearer token.
63 |
64 | + Request Sign in as user (application/json)
65 |
66 | {
67 | "client_id": "consumer_key_goes_here",
68 | "client_secret": "consumer_secret_goes_here",
69 | "username": "user@example.com",
70 | "password": "password_goes_here",
71 | "grant_type": "password"
72 | }
73 |
74 | + Request Refresh expired access token (application/json)
75 |
76 | {
77 | "client_id": "consumer_key_goes_here",
78 | "client_secret": "consumer_secret_goes_here",
79 | "grant_type": "refresh_token",
80 | "refresh_token": "crazy_token_like_240qhn16hwrnga05euynaoeiyhw52_goes_here"
81 | }
82 |
83 | + Response 201 (application/json)
84 |
85 | {
86 | "data": {
87 | "access_token": "example_access_token_like_135fhn80w35hynainrsg0q824hyn",
88 | "refresh_token": "crazy_token_like_240qhn16hwrnga05euynaoeiyhw52_goes_here",
89 | "token_type": "bearer"
90 | }
91 | }
92 |
93 | # Group User
94 | Resources for Users
95 |
96 | A user has the following specific attributes:
97 |
98 | - user_id (string, assigned, immutable)
99 | - email (string, writable, mutable)
100 | - first_name (string, writable, mutable)
101 | - last_name (string, writable, mutable)
102 |
103 | ## User [/users]
104 |
105 | ### Create user [POST]
106 | + Request (application/json)
107 |
108 | + Body
109 |
110 | {
111 | "client_id": "...",
112 | "client_secret": "...",
113 | "email": "user@example.com",
114 | "first_name": "User",
115 | "last_name": "McUserson",
116 | "locale": "en_us",
117 | "new_password": "********"
118 | }
119 |
120 | + Response 201 (application/json)
121 |
122 | {
123 | "user_id": "27412",
124 | "first_name": "User",
125 | "last_name": "McUserson",
126 | "email": "user@example.com",
127 | "oauth2": {
128 | "access_token": "example_access_token_like_135fhn80w35hynainrsg0q824hyn",
129 | "refresh_token": "...",
130 | "token_type": "bearer",
131 | "token_endpoint": "https://api.wink.com/oauth2/token"
132 | },
133 | "locale": "en_us",
134 | "units": {},
135 | "tos_accepted": false,
136 | "confirmed": false
137 | }
138 |
139 |
140 | ## User [/users/{user_id}]
141 |
142 | + Model (application/json)
143 |
144 | JSON representation of an user
145 |
146 | + Body
147 |
148 | {
149 | "data":{
150 | "user_id":"27105",
151 | "first_name":"User",
152 | "last_name":"McUserson",
153 | "email":"user@example.com",
154 | "oauth2":{
155 | "access_token":"55bb2ce8488d7ff9313be76668a43ea0",
156 | "refresh_token":"d30d2dcf5f33411b7a225e9e63952d84",
157 | "token_type":"bearer",
158 | "token_endpoint":"http://localhost:3000/oauth2/token"
159 | },
160 | "locale":"en_us",
161 | "units":{
162 | },
163 | "tos_accepted":false
164 | },
165 | "errors":[
166 | ],
167 | "pagination":{
168 | }
169 | }
170 |
171 | + Parameters
172 | - user_id (required, string, `21212`) ... String `user_id` of the user to perform action on. Has example value.
173 |
174 | ### Update current user's profile [PUT]
175 | + Request (application/json)
176 |
177 | + Headers
178 |
179 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
180 |
181 | + Body
182 |
183 | {
184 | "email": "user@example.com",
185 | }
186 |
187 | + Response 200 (application/json)
188 |
189 | {
190 | "data": {
191 | "user_id": "abc123def-an15nag",
192 | "email": "user@example.com"
193 | }
194 | }
195 |
196 | ## User password [/users/{user_id}/update_password]
197 |
198 | ### update password [POST]
199 | + Request (application/json)
200 |
201 | + Headers
202 |
203 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
204 |
205 | + Body
206 |
207 | {
208 | "old_password" : '123456'
209 | "new_password" : '654321'
210 | }
211 |
212 | + Response 200 (application/json)
213 |
214 | {}
215 |
216 |
217 |
218 | # Group Linked services
219 |
220 | # Linked services [/users/me/linked_services]
221 |
222 | ## List current user's linked services [GET]
223 | + Request
224 |
225 | + Headers
226 |
227 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
228 |
229 | + Response 200 (application/json)
230 |
231 | [{
232 | "linked_service_id": "aad234fce-oanqtqi1",
233 | "service": "facebook",
234 | "account": "123456789",
235 | }, {
236 | "linked_service_id": "bbe345edd-q2it1ahnh",
237 | "service": "twitter",
238 | "account": "158159-16-91245263-96246",
239 | }]
240 |
241 | ## Create new linked service [POST]
242 | + Request (application/json)
243 |
244 | + Headers
245 |
246 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
247 |
248 | + Body
249 |
250 | {
251 | "service": "google",
252 | "account": "user@example.com"
253 | }
254 |
255 | + Response 201 (application/json)
256 |
257 | {
258 | "linked_service_id": "ccf678dec-aing10fm", "title": "Buy cheese and bread for breakfast."
259 | }
260 |
261 |
262 |
263 | # Group Wink Device
264 |
265 | These resources are shared among multiple wink devices
266 |
267 | ## specific_device [/{device_type}/{device_id}]
268 |
269 | Each Wink Device can have the following attributes, but not all attributes will be populate
270 |
271 | Prepare to receive null for any one of these. For specific implementations, refer to the device documentation of the given device type.
272 |
273 | - name (String, writable)
274 | - locale (String, format LL_CC -- "en_us", "fr_fr")
275 | - units (object, specific to device)
276 | - created_at (long, timestamp, immutable)
277 |
278 | - manufacturer_device_model (String, assigned, pretty, printable string of model of device)
279 | - manufatcurer_device_id (String, assigned, udid of third party device in third party system)
280 | - hub_id (String, id of hub associated with device, only for devices with hub)
281 | - local_id (String, local id of device on hub, only for devices with hub)
282 | - radio_type (String, radio type of device, currently only for devices with hub) ["clearconnect", "zwave"]
283 | - device_manufacturer (String, manufacturer of device) ["lutron", "tcp", "schlage", "kwikset", "somfy", "honeywell", "leviton", "hue"]
284 | - lat_lng (tuple of floats, location of device)
285 | - location (String, pretty printable location of device)
286 | - desired_state(object, values of requested state. Depends on object type)
287 | - last_reading (object, values of last reading from device. Depends on object type)
288 |
289 | + Model (application/json)
290 |
291 | JSON representation of a generic device
292 |
293 | + Body
294 |
295 | {
296 | "name":"My Device",
297 | "locale": "en_us",
298 | "units": {},
299 | "created_at":1234567890,
300 | "subscription":{},
301 | "manufacturer_device_model":"Model of device",
302 | "manufacturer_device_id":"1234",
303 | "hub_id":"5678",
304 | "local_id":"7890",
305 | "radio_type":"zwave",
306 | "device_manufacturer":"leviton",
307 | "lat_lng": [12.34567890, 23.445678901],
308 | "location":"123 Main Street, Anywhere",
309 | "desired_state":{},
310 | "last_reading":{}
311 | }
312 |
313 | + Parameters
314 | - device_type (required, string, `air_conditioner`) ... String `device_type` of the device_type you want. Has example value
315 | - device_id (required, string, `sadffaglieuf291089`) ... String `device_id` of the device you want to retrieve. Has example value.
316 |
317 | ### Retrieve a device [GET]
318 | + Request
319 |
320 | + Headers
321 |
322 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
323 |
324 | + Response 200
325 |
326 | [specific_device][]
327 |
328 | ### Update a device [PUT]
329 | + Request (application/json)
330 |
331 | + Headers
332 |
333 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
334 |
335 | + Body
336 |
337 | {
338 | "name":"My Device",
339 | }
340 |
341 | + Response 200
342 |
343 | [specific_device][]
344 |
345 | ## refresh device [/{device_type}/{device_id}/refresh]
346 |
347 | ### Refresh a device [POST]
348 |
349 | + Request
350 |
351 | + Headers
352 |
353 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
354 |
355 | + Response 200 (application/json)
356 |
357 | + Parameters
358 | - device_type (required, string, `air_conditioner`) ... String `device_type` of the device_type you want. Has example value
359 | - device_id (required, string, `sadffaglieuf291089`) ... String `device_id` of the device you want to retrieve. Has example value.
360 |
361 | ## all devices of user [/users/me/wink_devices]
362 |
363 | ### Retrieve all devices [GET]
364 | + Request
365 |
366 | + Headers
367 |
368 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
369 |
370 | + Response 200 (application/json)
371 |
372 | {
373 | "data": [
374 | {
375 | "hub_id": "xxx",
376 | "name": "Hub",
377 | "locale": "en_us",
378 | "units": {},
379 | "created_at": 1425689198,
380 | "hidden_at": null,
381 | "capabilities": {
382 | "oauth2_clients": [
383 | "wink_hub"
384 | ]
385 | },
386 | "triggers": [],
387 | "desired_state": {
388 | "pairing_mode": null
389 | },
390 | "manufacturer_device_model": "wink_hub",
391 | "manufacturer_device_id": null,
392 | "device_manufacturer": "wink",
393 | "model_name": "Hub",
394 | "upc_id": "15",
395 | "last_reading": {
396 | "connection": true,
397 | "connection_updated_at": 1429500244.4901872,
398 | "agent_session_id": "xxx",
399 | "agent_session_id_updated_at": 1429500216.915741,
400 | "remote_pairable": true,
401 | "remote_pairable_updated_at": 1428161420.4011638,
402 | "updating_firmware": false,
403 | "updating_firmware_updated_at": 1429500216.2100337,
404 | "app_rootfs_version": "00.86",
405 | "app_rootfs_version_updated_at": 1429500217.4185543,
406 | "firmware_version": "0.86.0",
407 | "firmware_version_updated_at": 1429500217.4185324,
408 | "update_needed": false,
409 | "update_needed_updated_at": 1429500217.4185612,
410 | "mac_address": "xxx",
411 | "mac_address_updated_at": 1429500217.41854,
412 | "ip_address": "10.0.1.7",
413 | "ip_address_updated_at": 1429500217.4185476,
414 | "hub_version": "00.01",
415 | "hub_version_updated_at": 1429500217.418519,
416 | "pairing_mode": null,
417 | "pairing_mode_updated_at": 1427841692.0884776,
418 | "desired_pairing_mode": null,
419 | "desired_pairing_mode_updated_at": 1427841692.088467
420 | },
421 | "lat_lng": [
422 | 26.010181,
423 | -80.146535
424 | ],
425 | "location": "",
426 | "configuration": {
427 | "kidde_radio_code": 0
428 | },
429 | "update_needed": false,
430 | "uuid": "xxx"
431 | },
432 | {
433 | "light_bulb_id": "xxx",
434 | "name": "Office",
435 | "locale": "en_us",
436 | "units": {},
437 | "created_at": 1425698691,
438 | "hidden_at": null,
439 | "capabilities": {},
440 | "triggers": [],
441 | "desired_state": {
442 | "powered": true,
443 | "brightness": 1
444 | },
445 | "manufacturer_device_model": "ge_",
446 | "manufacturer_device_id": null,
447 | "device_manufacturer": "ge",
448 | "model_name": "GE light bulb",
449 | "upc_id": "xxx",
450 | "hub_id": "xxx",
451 | "local_id": "1",
452 | "radio_type": "zigbee",
453 | "linked_service_id": null,
454 | "last_reading": {
455 | "connection": true,
456 | "connection_updated_at": 1429500818.8442252,
457 | "firmware_version": "0.1b03 / 0.4b00",
458 | "firmware_version_updated_at": 1429500818.8442593,
459 | "firmware_date_code": "20140812",
460 | "firmware_date_code_updated_at": 1429500818.8442357,
461 | "powered": true,
462 | "powered_updated_at": 1429500818.844245,
463 | "brightness": 1,
464 | "brightness_updated_at": 1429500818.844252,
465 | "desired_powered": true,
466 | "desired_powered_updated_at": 1428490204.9604716,
467 | "desired_brightness": 1,
468 | "desired_brightness_updated_at": 1425698897.9915164
469 | },
470 | "lat_lng": [
471 | null,
472 | null
473 | ],
474 | "location": "",
475 | "order": 0
476 | },
477 | {
478 | "last_reading": {
479 | "connection": null,
480 | "connection_updated_at": null,
481 | "battery": 0.18,
482 | "battery_updated_at": 1429497969.3582497,
483 | "inventory": 1,
484 | "inventory_updated_at": 1429497969.3756864,
485 | "age": 1429454667,
486 | "age_updated_at": 1429497969.3756976,
487 | "freshness_remaining": 1771098,
488 | "freshness_remaining_updated_at": 1429497969.375706,
489 | "egg_1_timestamp": 0,
490 | "egg_1_timestamp_updated_at": 1429497969.3104246,
491 | "egg_2_timestamp": 0,
492 | "egg_2_timestamp_updated_at": 1429497969.310436,
493 | "egg_3_timestamp": 0,
494 | "egg_3_timestamp_updated_at": 1429497969.3104434,
495 | "egg_4_timestamp": 0,
496 | "egg_4_timestamp_updated_at": 1429497969.310451,
497 | "egg_5_timestamp": 0,
498 | "egg_5_timestamp_updated_at": 1429497969.3104584,
499 | "egg_6_timestamp": 0,
500 | "egg_6_timestamp_updated_at": 1429497969.310465,
501 | "egg_7_timestamp": 0,
502 | "egg_7_timestamp_updated_at": 1429497969.3104732,
503 | "egg_8_timestamp": 0,
504 | "egg_8_timestamp_updated_at": 1429497969.3104823,
505 | "egg_9_timestamp": 0,
506 | "egg_9_timestamp_updated_at": 1429497969.3104892,
507 | "egg_10_timestamp": 0,
508 | "egg_10_timestamp_updated_at": 1429497969.310498,
509 | "egg_11_timestamp": 0,
510 | "egg_11_timestamp_updated_at": 1429497969.3105059,
511 | "egg_12_timestamp": 1429454667,
512 | "egg_12_timestamp_updated_at": 1429497969.3105128,
513 | "egg_13_timestamp": 0,
514 | "egg_13_timestamp_updated_at": 1429497969.3105197,
515 | "egg_14_timestamp": 0,
516 | "egg_14_timestamp_updated_at": 1429497969.3105266
517 | },
518 | "eggs": [
519 | 0,
520 | 0,
521 | 0,
522 | 0,
523 | 0,
524 | 0,
525 | 0,
526 | 0,
527 | 0,
528 | 0,
529 | 0,
530 | 1429454667,
531 | 0,
532 | 0
533 | ],
534 | "freshness_period": 1814400,
535 | "eggtray_id": "147424",
536 | "name": "Egg Minder",
537 | "locale": "en_us",
538 | "units": {},
539 | "created_at": 1425701549,
540 | "hidden_at": null,
541 | "capabilities": {},
542 | "triggers": [],
543 | "device_manufacturer": "quirky_ge",
544 | "model_name": "Egg Minder",
545 | "upc_id": "23",
546 | "lat_lng": [
547 | 26.496337,
548 | -80.063654
549 | ],
550 | "location": "",
551 | "mac_address": "xxx",
552 | "serial": "xxx"
553 | },
554 | {
555 | "light_bulb_id": "xxx",
556 | "name": "Stairs",
557 | "locale": "en_us",
558 | "units": {},
559 | "created_at": 1426846362,
560 | "hidden_at": null,
561 | "capabilities": {},
562 | "triggers": [],
563 | "desired_state": {
564 | "powered": false,
565 | "brightness": 1
566 | },
567 | "manufacturer_device_model": "lutron_p_pkg1_p_wh_d",
568 | "manufacturer_device_id": null,
569 | "device_manufacturer": "lutron",
570 | "model_name": "Caseta Lamp Dimmer & Pico",
571 | "upc_id": "xx",
572 | "hub_id": "xxx",
573 | "local_id": "2",
574 | "radio_type": "lutron",
575 | "linked_service_id": null,
576 | "last_reading": {
577 | "connection": true,
578 | "connection_updated_at": 1429500245.3731902,
579 | "powered": false,
580 | "powered_updated_at": 1429500245.3732066,
581 | "brightness": 1,
582 | "brightness_updated_at": 1429500245.3731997,
583 | "desired_powered": false,
584 | "desired_powered_updated_at": 1429328338.4158955,
585 | "desired_brightness": 1,
586 | "desired_brightness_updated_at": 1427330529.0827518
587 | },
588 | "lat_lng": [
589 | null,
590 | null
591 | ],
592 | "location": "",
593 | "order": 0
594 | },
595 | {
596 | "remote_id": "xxx",
597 | "name": "Stairs up wallmount",
598 | "members": [
599 | {
600 | "object_type": "light_bulb",
601 | "object_id": "xxx",
602 | "desired_state": {
603 | "powered": false,
604 | "powered_updated_at": 1429328338.4158955,
605 | "brightness": 1,
606 | "brightness_updated_at": 1427330529.0827518
607 | }
608 | }
609 | ],
610 | "locale": "en_us",
611 | "units": {},
612 | "created_at": 1426847605,
613 | "hidden_at": null,
614 | "capabilities": {},
615 | "desired_state": {},
616 | "device_manufacturer": "lutron",
617 | "model_name": "Pico",
618 | "upc_id": "xx",
619 | "hub_id": "xxx",
620 | "local_id": "3",
621 | "radio_type": "lutron",
622 | "last_reading": {
623 | "connection": null,
624 | "connection_updated_at": null,
625 | "remote_pairable": true,
626 | "remote_pairable_updated_at": 1428161420.4384034
627 | },
628 | "lat_lng": [
629 | 26.496324,
630 | -80.063659
631 | ],
632 | "location": ""
633 | },
634 | {
635 | "remote_id": "xxx",
636 | "name": "Stairs detached",
637 | "members": [
638 | {
639 | "object_type": "light_bulb",
640 | "object_id": "xxx",
641 | "desired_state": {
642 | "powered": false,
643 | "powered_updated_at": 1429328338.4158955,
644 | "brightness": 1,
645 | "brightness_updated_at": 1427330529.0827518
646 | }
647 | }
648 | ],
649 | "locale": "en_us",
650 | "units": {},
651 | "created_at": 1426896325,
652 | "hidden_at": null,
653 | "capabilities": {},
654 | "desired_state": {},
655 | "device_manufacturer": "lutron",
656 | "model_name": "Pico",
657 | "upc_id": "xx",
658 | "hub_id": "xxx",
659 | "local_id": "4",
660 | "radio_type": "lutron",
661 | "last_reading": {
662 | "connection": null,
663 | "connection_updated_at": null,
664 | "remote_pairable": true,
665 | "remote_pairable_updated_at": 1428161420.4671366
666 | },
667 | "lat_lng": [
668 | 26.481714,
669 | -80.0851
670 | ],
671 | "location": ""
672 | },
673 | {
674 | "light_bulb_id": "xxx",
675 | "name": "Kitchen",
676 | "locale": "en_us",
677 | "units": {},
678 | "created_at": 1427841678,
679 | "hidden_at": null,
680 | "capabilities": {},
681 | "triggers": [],
682 | "desired_state": {
683 | "powered": false,
684 | "brightness": 0.76
685 | },
686 | "manufacturer_device_model": "lutron_p_pkg1_w_wh_d",
687 | "manufacturer_device_id": null,
688 | "device_manufacturer": "lutron",
689 | "model_name": "Caseta Wireless Dimmer & Pico",
690 | "upc_id": "3",
691 | "hub_id": "xxx",
692 | "local_id": "5",
693 | "radio_type": "lutron",
694 | "linked_service_id": null,
695 | "last_reading": {
696 | "connection": true,
697 | "connection_updated_at": 1429500246.530256,
698 | "powered": false,
699 | "powered_updated_at": 1429500246.5302837,
700 | "brightness": 0.76,
701 | "brightness_updated_at": 1429500246.5302727,
702 | "desired_powered": false,
703 | "desired_powered_updated_at": 1429495229.6978345,
704 | "desired_brightness": 0.76,
705 | "desired_brightness_updated_at": 1429500246.5847015
706 | },
707 | "lat_lng": [
708 | 26.49635,
709 | -80.063667
710 | ],
711 | "location": "",
712 | "order": 0
713 | },
714 | {
715 | "hub_id": "xxx",
716 | "name": "Hub",
717 | "locale": "en_us",
718 | "units": {},
719 | "created_at": 1429049123,
720 | "hidden_at": null,
721 | "capabilities": {},
722 | "triggers": [],
723 | "desired_state": {
724 | "pairing_mode": null
725 | },
726 | "manufacturer_device_model": "philips",
727 | "manufacturer_device_id": "xxx",
728 | "device_manufacturer": null,
729 | "model_name": null,
730 | "upc_id": null,
731 | "last_reading": {
732 | "connection": true,
733 | "connection_updated_at": 1429049123.3954115,
734 | "agent_session_id": null,
735 | "agent_session_id_updated_at": null,
736 | "remote_pairable": null,
737 | "remote_pairable_updated_at": null,
738 | "updating_firmware": null,
739 | "updating_firmware_updated_at": null,
740 | "app_rootfs_version": null,
741 | "app_rootfs_version_updated_at": null,
742 | "firmware_version": null,
743 | "firmware_version_updated_at": null,
744 | "update_needed": false,
745 | "update_needed_updated_at": 1429049123.3314805,
746 | "mac_address": null,
747 | "mac_address_updated_at": null,
748 | "ip_address": null,
749 | "ip_address_updated_at": null,
750 | "hub_version": null,
751 | "hub_version_updated_at": null,
752 | "pairing_mode": null,
753 | "pairing_mode_updated_at": null,
754 | "desired_pairing_mode": null,
755 | "desired_pairing_mode_updated_at": null
756 | },
757 | "lat_lng": [
758 | null,
759 | null
760 | ],
761 | "location": "",
762 | "configuration": null,
763 | "update_needed": false,
764 | "uuid": "xxx"
765 | },
766 | {
767 | "light_bulb_id": "xxx",
768 | "name": "LightStrips 2",
769 | "locale": "en_us",
770 | "units": {},
771 | "created_at": 1429049124,
772 | "hidden_at": 1429203619,
773 | "capabilities": {},
774 | "triggers": [],
775 | "desired_state": {
776 | "powered": true,
777 | "brightness": 1
778 | },
779 | "manufacturer_device_model": "LST001",
780 | "manufacturer_device_id": "xxx",
781 | "device_manufacturer": "philips",
782 | "model_name": "HUE A19 Lighting Kit",
783 | "upc_id": "1",
784 | "hub_id": "137069",
785 | "local_id": "2",
786 | "radio_type": null,
787 | "linked_service_id": null,
788 | "last_reading": {
789 | "connection": true,
790 | "connection_updated_at": 1429049124.3448753,
791 | "powered": null,
792 | "powered_updated_at": null,
793 | "brightness": null,
794 | "brightness_updated_at": null,
795 | "desired_powered": true,
796 | "desired_powered_updated_at": 1429049124.2762687,
797 | "desired_brightness": 1,
798 | "desired_brightness_updated_at": 1429049124.2762783
799 | },
800 | "lat_lng": [
801 | null,
802 | null
803 | ],
804 | "location": "",
805 | "order": 0
806 | },
807 | {
808 | "light_bulb_id": "xxx",
809 | "name": "LightStrips 1",
810 | "locale": "en_us",
811 | "units": {},
812 | "created_at": 1429049124,
813 | "hidden_at": 1429321559,
814 | "capabilities": {},
815 | "triggers": [],
816 | "desired_state": {
817 | "powered": true,
818 | "brightness": 1
819 | },
820 | "manufacturer_device_model": "LST001",
821 | "manufacturer_device_id": "xxx",
822 | "device_manufacturer": "philips",
823 | "model_name": "HUE A19 Lighting Kit",
824 | "upc_id": "1",
825 | "hub_id": "xxx",
826 | "local_id": "1",
827 | "radio_type": null,
828 | "linked_service_id": null,
829 | "last_reading": {
830 | "connection": true,
831 | "connection_updated_at": 1429049124.4880855,
832 | "powered": null,
833 | "powered_updated_at": null,
834 | "brightness": null,
835 | "brightness_updated_at": null,
836 | "desired_powered": true,
837 | "desired_powered_updated_at": 1429049124.393545,
838 | "desired_brightness": 1,
839 | "desired_brightness_updated_at": 1429049124.3935578
840 | },
841 | "lat_lng": [
842 | null,
843 | null
844 | ],
845 | "location": "",
846 | "order": 0
847 | }
848 | ],
849 | "errors": [],
850 | "pagination": {
851 | "count": 10
852 | }
853 | }
854 |
855 | ## all devices of type for user [/users/me/{device_type}]
856 |
857 | ### Retrieve all devices [GET]
858 | + Request
859 |
860 | + Headers
861 |
862 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
863 |
864 | + Response 200 (application/json)
865 |
866 | [
867 | {
868 | "name":"My Device",
869 | "locale": "en_us",
870 | "units": {},
871 | "created_at":1234567890,
872 | "subscription":{},
873 | "manufacturer_device_model":"Model of device",
874 | "manufacturer_device_id":"1234",
875 | "hub_id":"5678",
876 | "local_id":"7890",
877 | "radio_type":"zwave",
878 | "device_manufacturer":"leviton",
879 | "lat_lng": [12.34567890, 23.445678901],
880 | "location":"123 Main Street, Anywhere"
881 | }
882 | ]
883 |
884 | + Parameters
885 | - device_type (required, string, `air_conditioners`) ... String `device_type` of the device_type you want. Has example value
886 |
887 | ## sharing device [/{device_type}/{device_id}/users]
888 |
889 | + Model (application/json)
890 |
891 | JSON representation of a Pivot Power Genius sharing relationship
892 |
893 | + Body
894 |
895 | {
896 | "device_id": "qs1ga9_1234deadbeef", //NOTE: the field name will vary depending on device
897 | "user_id": "abc123def-an15nag",
898 | "email": "user@example.com",
899 | "permissions": ["read_data", "write_data", "read_triggers", "write_triggers"]
900 | }
901 |
902 | + Parameters
903 | + device_type (required, string, `air_conditioners`) ... String `device_type` of the device_type you want. Has example value
904 | + device_id (required, string, `qs1ga9_1234deadbeef`) ... String `air_conditioner_id` of the air_conditioner to perform action on. Has example value.
905 |
906 | ### List shared device users [GET]
907 | + Request
908 |
909 | + Headers
910 |
911 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
912 |
913 | + Response 200 (application/json)
914 |
915 | [{
916 | "user_id": "abc123def-an15nag",
917 | "email": "user@example.com",
918 | "permissions": ["read_data", "write_data", "read_triggers", "write_triggers", "manage_triggers", "manage_sharing"]
919 | }, {
920 | "user_id": "fed876ccc-95hnh3hj",
921 | "email": "user2@example2.com",
922 | "permissions": ["read_data", "write_data", "read_triggers", "write_triggers"]
923 | }]
924 |
925 | ### Share a device [POST]
926 | + Request (application/json)
927 |
928 | + Headers
929 |
930 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
931 |
932 | + Body
933 |
934 | {
935 | "email": "user2@example2.com",
936 | "permissions": ["read_data", "write_data", "read_triggers", "write_triggers"]
937 | }
938 |
939 | + Response 202 (application/json)
940 |
941 | {}
942 |
943 | ## unsharing a device [/{device_type}/{device_id}/users/{email}]
944 |
945 | + Parameters
946 | + device_type (required, string, `air_conditioners`) ... String `device_type` of the device_type you want. Has example value
947 | + device_id (required, string, `qs1ga9_1234deadbeef`) ... String `air_conditioner_id` of the air_conditioner to perform action on. Has example value.
948 | + email (required, string, `user@example.com`) ... String `email` of the user account to unshare from.
949 |
950 | ### Unshare a device [DELETE]
951 | + Request
952 |
953 | + Headers
954 |
955 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
956 |
957 | + Response 204
958 |
959 |
960 |
961 |
962 |
963 | # Group Channel
964 | Resources for viewing channels, which are used only to set the data source for Nimbus dials and as the outputs of legacy triggers.
965 |
966 | ## channels [/channels]
967 | Each channel resource has the following attributes:
968 |
969 | - channel_id (string, assigned, immutable)
970 | - name (string, assigned, immutable)
971 | - inbound (boolean, assigned, immutable)
972 | - outbound (boolean, assigned, immutable)
973 | - required_parameters (object, assigned, immutable)
974 | - optional_parameters (object, assigned, immutable)
975 |
976 | Inbound channels are used for Nimbus dial displays
977 |
978 | Outbound channels are user for Triggers, used by multiple devices
979 |
980 | When constructing a channel configuration, all required parameters listed in the required_paramaters object for a given channel must be included
981 |
982 | See individual device documentation for acceptable values
983 |
984 | ### List available channels [GET]
985 | + Request
986 |
987 | + Headers
988 |
989 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
990 |
991 | + Response 200 (application/json)
992 |
993 | [{
994 | "channel_id": "qs1ga9_1234deadbeef",
995 | "name": "Weather",
996 | "inbound": true,
997 | "outbound": false,
998 | "required_parameters": {
999 | "lat_lng": true,
1000 | "reading_type": true
1001 | },
1002 | "optional_parameters": {
1003 | "location": true
1004 | }
1005 | }, {
1006 | "channel_id": "qs1ga9_5678deadbeef",
1007 | "name": "Email",
1008 | "inbound": false,
1009 | "outbound":true,
1010 | "required_parameters": {
1011 | "recipient_email": true
1012 | },
1013 | "optional_parameters": {}
1014 | }]
1015 |
1016 |
1017 |
1018 | # Group Group
1019 | Resources for creating and controlling groups of devices
1020 |
1021 | The Wink API defines certain special groups which you cannot fully control. These include, but are not limited to:
1022 |
1023 | - System categories such as .all and .sensors, which will include respectively every product and every product which is contains environment sensors of any kind. You cannot create, delete, or rename system categories. You cannot add or remove objects from system categories. System categories have an automation_mode flag of "system_category".
1024 | - User categories such as @door_sensors and @power. Some devices will appear in these categories by default, based on our best guess of how these devices will be used by most consumers. You cannot create, delete, or rename user categories. You can, however, add and remove objects, if our default classifications are not appropriate. User categories have an an automation_mode flag of "user_category".
1025 |
1026 | ## group [/groups/{group_id}]
1027 | The group resource is a representation of a group of wink devices which may be controlled simultaneously
1028 |
1029 | The group resource has the following attributes:
1030 |
1031 | - group_id (string, assigned, immutable)
1032 | - name (string, mutable with write_data permission)
1033 | - order (integer, mutable with write_data permission )
1034 |
1035 | The group resource has the following objects:
1036 |
1037 | - members (0 to many objects, assignable)
1038 |
1039 | Members have the following attributes
1040 |
1041 | - object_id (string, assignable)
1042 | - object_type (string, assignable) [value will be singular types of wink devices and objects. i.e. air_conditioner, propane_tank, outlet, light_bulb, etc.]
1043 | - desired_state (object) [current desired_state of object at time of request]
1044 |
1045 | + Model (application/json)
1046 |
1047 | JSON representation of an outlet
1048 |
1049 | + Body
1050 |
1051 | {
1052 | "group_id": "agh1ity-876f00",
1053 | "name": "Front windows",
1054 | "order": 3,
1055 | "members": [
1056 | {
1057 | "object_id": "adsjfhasdof",
1058 | "object_type": "light_bulb"
1059 | "desired_state": {
1060 | "powered":true
1061 | }
1062 | },
1063 | {
1064 | "object_id": "adsjfhasdof",
1065 | "object_type": "air_conditioner",
1066 | "desired_state": {
1067 | "powered":true
1068 | }
1069 | }
1070 | ]
1071 | }
1072 |
1073 | + Parameters
1074 | + group_id (required, string, `agh1ity-876f00`) ... String `group_id` of the outlet to perform action on. Has example value.
1075 |
1076 | ### Retrieve a group [GET]
1077 | + Request
1078 |
1079 | + Headers
1080 |
1081 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1082 |
1083 | + Response 200
1084 |
1085 | [group][]
1086 |
1087 | ### Update group settings [PUT]
1088 |
1089 | You can use this endpoint to update the members or name of the group
1090 |
1091 | + Request (application/json)
1092 |
1093 | + Headers
1094 |
1095 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1096 |
1097 | + Body
1098 |
1099 | {
1100 | "name":"Front windows"
1101 | }
1102 |
1103 | + Response 200
1104 |
1105 | [group][]
1106 |
1107 | ### Delete a group [DELETE]
1108 |
1109 | + Request
1110 |
1111 | + Headers
1112 |
1113 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1114 |
1115 | + Response 204
1116 |
1117 | ## group [/groups]
1118 |
1119 | ### Create a group [POST]
1120 |
1121 | + Request
1122 |
1123 | + Headers
1124 |
1125 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1126 |
1127 | + Body
1128 |
1129 | {
1130 | "name": "Front windows",
1131 | "order": 3,
1132 | "members": [
1133 | {
1134 | "object_id": "adsjfhasdof",
1135 | "object_type": "light_bulb"
1136 | },
1137 | {
1138 | "object_id": "adsjfhasdof",
1139 | "object_type": "air_conditioner"
1140 | }
1141 | ]
1142 | }
1143 |
1144 | + Response 200
1145 |
1146 | [group][]
1147 |
1148 |
1149 | ## set state of group [/groups/{group_id}/activate]
1150 |
1151 | When you post up a desired state object, the API will then change all the devices in the group to that desired state. Allowed values for desired_state are dependent on the devices in the group and you should refer to individual device documentation.
1152 |
1153 | If you have multiple types of devices in a group and a field in the desired_state object only applies to some of them, such as "color" for "light_bulb" types, the API will update the appropriate devices and ignore that state for devices that do not have a color state, such as air_conditioners
1154 |
1155 | + Parameters
1156 | + group_id (required, string, `agh1ity-876f00`) ... String `group_id` of the outlet to perform action on. Has example value.
1157 |
1158 | ### Activate state of group [POST]
1159 |
1160 | + Request
1161 |
1162 | + Headers
1163 |
1164 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1165 |
1166 | + Body
1167 |
1168 | {
1169 | "desired_state": {
1170 | "powered":true
1171 | }
1172 | }
1173 |
1174 | + Response 200
1175 |
1176 | [group][]
1177 |
1178 |
1179 |
1180 |
1181 |
1182 |
1183 |
1184 |
1185 |
1186 | # Group Icon
1187 |
1188 | ## icon [/icons/{icon_id}]
1189 |
1190 | Icons are permanent and immutable.
1191 | Each icon resource has the following attributes:
1192 |
1193 | - icon_id (string, immutable)
1194 | - name (string, immutable) which is intended to be a meaningful user-entered label
1195 | - object_type (string reference, immutable)
1196 | - image.medium (url, immutable)
1197 |
1198 | + Model (application/json)
1199 |
1200 | + Body
1201 |
1202 | {
1203 | "data": {
1204 | "icon_id": "1r5u9j-8901feed",
1205 | "name": "A/C",
1206 | "object_type": "outlet",
1207 | "image": {
1208 | "medium": "http://s3.amazonaws.com/wink-production/icons/ac/medium.png"
1209 | }
1210 | }
1211 | }
1212 |
1213 | ## icons [/icons]
1214 | ### List available icons [GET]
1215 | + Request
1216 |
1217 | + Headers
1218 |
1219 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1220 |
1221 | + Response 200 (application/json)
1222 |
1223 | {
1224 | "data": [{
1225 | "icon_id": "1r5u9j-8901feed",
1226 | "name": "A/C",
1227 | "object_type": "outlet",
1228 | "image": {
1229 | "medium": "http://s3.amazonaws.com/wink-production/icons/ac/medium.png"
1230 | }
1231 | }, {
1232 | "icon_id": "116ahi-6719ceda",
1233 | "name": "lamp",
1234 | "object_type": "outlet",
1235 | "image": {
1236 | "medium": "http://s3.amazonaws.com/wink-production/icons/lamp/medium.png"
1237 | }
1238 | }]
1239 | }
1240 |
1241 | # Group Robot
1242 |
1243 | Resources for creating and updating Robots
1244 |
1245 | ## robot [/robots/{robot_id}]
1246 | The robot resources is a representation of a single robot
1247 |
1248 | A robot has the following specific attributes:
1249 |
1250 | - robot_id (string, assigned, immutable)
1251 | - name (string, writable)
1252 | - enabled (boolean, writable)
1253 | - fired_limit (integer, writable)
1254 | - last_fired (timestamp, immutable)
1255 | - creating_actor_type (string, assigned) [type of entity that created the robot]
1256 | - creating_actor_id (string, assigned) [id of entity that created the robot]
1257 | - automation_mode (string, assigned) [mode of robot if generated for smart features, current possible values -- null (not smart), "smart_schedule", "smart_away_arriving", "smart_away_departing"]
1258 |
1259 | The robot resource embeds the following objects:
1260 |
1261 | - causes (array, 1 to many Conditions, see below for format)
1262 | - restrictions (0 to many Conditions, see below for format)
1263 | - effects (1 to many, see below for format)
1264 |
1265 | CAUSES & RESTRICTIONS
1266 |
1267 | The causes array is an array of Conditions that can trigger a robot. The restrictions array is an array of Conditions that can prevent a robot from being fired, even if it is triggered by a cause.
1268 |
1269 | A condition has the following format:
1270 |
1271 | - condition_id (string, assigned, immutable) [id of condition]
1272 | - observed_field (string, writable) [field in last reading]
1273 | - observed_object_id (string, writable) [id of object being observed]
1274 | - observed_object_type (string, writable) [type of object being observed, ex. "garage_door"]
1275 | - operator (string, writable) [comparison operator]
1276 | - value (string, writable) [desired value of observed_field
1277 | - recurrence (text, writeable) [iCal string]
1278 | - restriction_join (string, writable) ["and" or "or"]
1279 | - robot_id (integer, writable) [id of robot]
1280 | - restricted_object_id (integer, writable) [if this condition is restricting something, the id of what is being restricted]
1281 | - restricted_object_type (string, writable) [if this condition is restricting something, the type of what is being restricted, currently "robot" or "condition"]
1282 |
1283 | A condition can have a recurrence OR an observed object + field + operator + value, but should not have both.
1284 |
1285 | A condition embeds the following objects
1286 |
1287 | - restrictions (0 to many)
1288 |
1289 | For causes and restrictions, their truthiness is evaluated in the following order:
1290 |
1291 | recurrence && observed_field && restrictions.
1292 |
1293 | EVALUATION OF RECURRENCE:
1294 |
1295 | Recurrence should be a string in iCal format and is to be used for a condition dependent on a time. If the recurrence is nil, it's evaluation is true. Thus, to omit a time restriction, set the recurrence string to null.
1296 |
1297 | EVALUATION OF OBSERVED_FIELD
1298 |
1299 | The following fields are all required to properly evaluate observed_field
1300 |
1301 | - observed_field
1302 | - operator
1303 | - value
1304 |
1305 | observed_field can be any field in a device's last_reading object
1306 |
1307 | operator can be only of the following, as strings
1308 |
1309 | - ==
1310 | - !=
1311 | - >
1312 | - <
1313 | - >=
1314 | - <=
1315 |
1316 | value is the value that will be used in comparison with the operator.
1317 |
1318 | NOTE: although you can compare multiple types of values, such as boolean, string, int, or float, this value should be put and read as a string. See examples below.
1319 |
1320 | In order to evaluate to true, the observed field's value must be evaluated to true with the given operator
1321 |
1322 | EVALUATION OF RESTRICTIONS
1323 |
1324 | Each condition can have embedded restrictions to create complex logic.
1325 |
1326 | By default, each restriction in the array is joined by "and" so that all the restrictions in the array must evaluate to true in order for restrictions to evaluate to true.
1327 |
1328 | You can join restrictions by "or" by add a
1329 |
1330 | - restriction_join [allowed values "and" "or"]
1331 |
1332 | NOTE ABOUT COMPLEXITY
1333 |
1334 | Because each restriction is of the same class as the top level Condition, each embedded restriction goes through the same evaluation process for truthiness and can similarly have embedded restrictions of its own.
1335 |
1336 | The restrictions defined in the top level "restrictions" array of the robot object are joined by "and". From there, nested restrictions are joined based on the "restriction_join" field of the parent restriction.
1337 |
1338 | The allowed causes are either objects with an observed reading (such as a garage door opening or a geofence being triggered) or they are a time as defined by an iCal recurrence string.
1339 |
1340 | EXAMPLES:
1341 |
1342 | Note: each example could be in the causes or restrictions array on the robot object, causes are conditions that can trigger a robot and restrictions are conditions that can prevent a robot from being triggered.
1343 |
1344 | Example of a condition: a garage door is opened by at least 50%
1345 |
1346 | {
1347 | "observed_object_id":"xyzasdfadsfhkj",
1348 | "observed_object_type":"garage_door",
1349 | "observed_field": "position",
1350 | "operator": ">=",
1351 | "value": "0.5"
1352 | }
1353 |
1354 | Example of a condition: geo fence is entered
1355 |
1356 | {
1357 | "observed_object_id":"defasdfkjha",
1358 | "observed_object_type":"geofence",
1359 | "observed_field": "within",
1360 | "operator": "==",
1361 | "value": "true"
1362 | }
1363 |
1364 | Example of a condition: geo fence is entered
1365 |
1366 | {
1367 | "observed_object_id":"defasdfkjha",
1368 | "observed_object_type":"geofence",
1369 | "observed_field": "within",
1370 | "operator": "==",
1371 | "value": "false"
1372 | }
1373 |
1374 | Example of a condition: It is 5 pm on a Tuesday
1375 |
1376 | {
1377 | "recurrence": "DTSTART;TZID=PDT:20140313T170000RRULE:FREQ=DAILY"
1378 | }
1379 |
1380 | Example of a condition: it is between 8pm and 10pm on Tuesdays
1381 |
1382 | {
1383 | "recurrence": "DTSTART;TZID=PDT:20140313T200000DTEND;TZID=PDT:20140313T220000RRULE:FREQ=DAILY"
1384 | }
1385 |
1386 | Example of a condition: the garage door is closed and I am within my home geofence
1387 |
1388 | {
1389 | "restrictions": [
1390 | {
1391 | "observed_object_id":"xyzasdfadsfhkj",
1392 | "observed_object_type":"garage_door",
1393 | "observed_field": "position",
1394 | "operator": "==",
1395 | "value": "0.0"
1396 | },
1397 | {
1398 | "observed_object_id":"defasdfkjha",
1399 | "observed_object_type":"geofence",
1400 | "observed_field": "within",
1401 | "operator": "==",
1402 | "value": "true"
1403 | }
1404 | ]
1405 | }
1406 |
1407 | Example of a condition: (the garage door is closed and I am within my home geofence) or it is between 8pm and 10pm on Tuesdays
1408 |
1409 | {
1410 | "restriction_join": "or"
1411 | "restrictions": [
1412 | {
1413 | "restrictions": [
1414 | {
1415 | "observed_object_id":"xyzasdfadsfhkj",
1416 | "observed_object_type":"garage_door",
1417 | "observed_field": "position",
1418 | "operator": "==",
1419 | "value": "0.0"
1420 | },
1421 | {
1422 | "observed_object_id":"defasdfkjha",
1423 | "observed_object_type":"geofence",
1424 | "observed_field": "within",
1425 | "operator": "==",
1426 | "value": "true"
1427 | }
1428 | ]
1429 | },
1430 | {
1431 | "recurrence": "DTSTART;TZID=PDT:20140313T200000DTEND;TZID=PDT:20140313T220000RRULE:FREQ=DAILY"
1432 | }
1433 | ]
1434 | }
1435 |
1436 | Example of a restriction: the garage door is closed and (I am within my home geofence or it is between 8pm and 10pm on Tuesdays)
1437 |
1438 | {
1439 | "restrictions": [
1440 | {
1441 | "observed_object_id":"xyzasdfadsfhkj",
1442 | "observed_object_type":"garage_door",
1443 | "observed_field": "position",
1444 | "operator": "==",
1445 | "value": "0.0"
1446 | },
1447 | {
1448 | "join_type": "or",
1449 | "restrictions": [
1450 |
1451 | {
1452 | "observed_object_id":"defasdfkjha",
1453 | "observed_object_type":"geofence",
1454 | "observed_field": "within",
1455 | "operator": "==",
1456 | "value": "true"
1457 | },
1458 | {
1459 | "recurrence": "DTSTART;TZID=PDT:20140313T200000DTEND;TZID=PDT:20140313T220000RRULE:FREQ=DAILY"
1460 | }
1461 | ]
1462 | },
1463 |
1464 | ]
1465 | }
1466 |
1467 | Example of a restriction: the garage door is closed and it is between 8pm and 10pm on Tuesdays
1468 |
1469 | Can be written as two embedded restrictions
1470 |
1471 | {
1472 | "restrictions": [
1473 | {
1474 | "observed_object_id":"xyzasdfadsfhkj",
1475 | "observed_object_type":"garage_door",
1476 | "observed_field": "position",
1477 | "operator": "==",
1478 | "value": "0.0"
1479 | },
1480 | {
1481 | "recurrence": "DTSTART;TZID=PDT:20140313T200000DTEND;TZID=PDT:20140313T220000RRULE:FREQ=DAILY"
1482 | }
1483 |
1484 | ]
1485 | }
1486 |
1487 | EFFECT
1488 |
1489 | An effect is what happens if any of the causes occur outside of the optional restriction.
1490 |
1491 | The effect has the following attributes:
1492 |
1493 | - scene (refers to scene that would be activated)
1494 | - recipient_actor_id (refers to a user that would get a notification of some type)
1495 | - recipient_actor_type (refers to the type of actor, currently just "user")
1496 | - notification_type (notification type to send)
1497 | - note (refers to an associated custom text)
1498 |
1499 | An effect can have a scene OR a user_id and notification_type, but should not have both.
1500 |
1501 | If an effect has a note, it should also have a notification type and recipient actor.
1502 |
1503 | SCENE IN EFFECT
1504 |
1505 | The scene object is saved within the system and has a scene_id, but will come down as a full object for ease of use
1506 |
1507 | USER and NOTIFICATION_TYPE
1508 |
1509 | recipient_actor_id is the user_id of the user who will be receiving the notification
1510 |
1511 | recipient_actor_type should be "user"
1512 |
1513 | Allowed values for notification_type are "email" and "push"
1514 |
1515 | NOTE
1516 |
1517 | The note object is saved as a custom text with a body attribute containing arbitrary text.
1518 |
1519 | + Model (application/json)
1520 |
1521 | JSON representation of a robot
1522 |
1523 | + Body
1524 |
1525 | {
1526 | "robot_id": "qs1ga9_1234deadbeef",
1527 | "name": "Data",
1528 | "enabled": true,
1529 | "creating_actor_type": "user",
1530 | "creating_actor_id": "asdfljafd",
1531 | "fired_limit": 2,
1532 | "automation_mode": null,
1533 | "causes" : [
1534 | {
1535 | "condition_id": "qweryoiu",
1536 | "observed_object_id":"xyzasdfadsfhkj",
1537 | "observed_object_type":"garage_door",
1538 | "observed_field": "position",
1539 | "operator": "==",
1540 | "value": "0.0"
1541 | }
1542 | ],
1543 | "restrictions" : [
1544 | {
1545 | "condition_id": "sadfdsaafsd",
1546 | "recurrence": "DTSTART;TZID=PDT:20140313T200000DTEND;TZID=PDT:20140313T220000RRULE:FREQ=DAILY"
1547 | }
1548 | ],
1549 | "effects": [
1550 | {
1551 | "scene": {
1552 | "scene_id": "asdaioytf",
1553 | "name":"Data Scene",
1554 | "members": [
1555 | "object_id":"asdfoaiye",
1556 | "object_type":"light_bulb",
1557 | "desired_state": {
1558 | "powered":true,
1559 | "brightness": 0.75
1560 | }
1561 | ]
1562 | },
1563 | "note": {
1564 | "custom_text_id",
1565 | "body": "Some text",
1566 | "subject_id": "abc",
1567 | "subject_type": "effect"
1568 | }
1569 | },
1570 | {
1571 | "recipient_actor_id": "adsfhkjasdfy",
1572 | "recipient_actor_type": "user",
1573 | "notification_type": "email
1574 | }
1575 |
1576 | ]
1577 | }
1578 |
1579 | + Parameters
1580 | - robot_id (required, string, `qs1ga9_1234deadbeef`) ... String `robot_id` of the robot to perform action on. Has example value.
1581 |
1582 | ### Retrieve a robot [GET]
1583 | + Request
1584 |
1585 | + Headers
1586 |
1587 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1588 |
1589 | + Response 200 (application/json)
1590 |
1591 | [robot][]
1592 |
1593 | ### Update a robot [PUT]
1594 |
1595 | + Request (application/json)
1596 |
1597 | + Headers
1598 |
1599 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1600 |
1601 | + Body
1602 |
1603 | {
1604 | "robot_id": "qs1ga9_1234deadbeef",
1605 | "name": "Data",
1606 | "enabled": true,
1607 | "causes" : [
1608 | {
1609 | "condition_id": "qweryoiu",
1610 | "observed_object_id":"xyzasdfadsfhkj",
1611 | "observed_object_type":"garage_door",
1612 | "observed_field": "position",
1613 | "operator": "==",
1614 | "value": "0.0"
1615 | }
1616 | ],
1617 | "restrictions" : [
1618 | {
1619 | "condition_id": "sadfdsaafsd",
1620 | "recurrence": "DTSTART;TZID=PDT:20140313T200000DTEND;TZID=PDT:20140313T220000RRULE:FREQ=DAILY"
1621 | }
1622 | ],
1623 | "effects": [
1624 | {
1625 | "scene": {
1626 | "scene_id": "asdaioytf",
1627 | "name":"Data Scene",
1628 | "members": [
1629 | "object_id":"asdfoaiye",
1630 | "object_type":"light_bulb",
1631 | "desired_state": {
1632 | "powered":true,
1633 | "brightness": 0.75
1634 | }
1635 | ]
1636 | },
1637 | "note": {
1638 | "custom_text_id": "abc",
1639 | "body": "Some other text"
1640 | }
1641 | },
1642 | {
1643 | "recipient_actor_id": "adsfhkjasdfy",
1644 | "recipient_actor_type": "user",
1645 | "notification_type": "email
1646 | }
1647 |
1648 | ]
1649 | }
1650 |
1651 | + Response 200 (application/json)
1652 |
1653 | [robot][]
1654 |
1655 | ### Delete a robot [DELETE]
1656 | + Request
1657 |
1658 | + Headers
1659 |
1660 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1661 |
1662 | + Response 204
1663 |
1664 | ## User's Robots [/users/me/robots]
1665 |
1666 | ### create a new robot [POST]
1667 |
1668 | + Request
1669 |
1670 | + Headers
1671 |
1672 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1673 |
1674 | + Body
1675 |
1676 | {
1677 | "name": "Data",
1678 | "enabled": true,
1679 | "causes" : [
1680 | {
1681 | "observed_object_id":"xyzasdfadsfhkj",
1682 | "observed_object_type":"garage_door",
1683 | "observed_field": "position",
1684 | "operator": "==",
1685 | "value": "0.0"
1686 | }
1687 | ],
1688 | "restrictions" : [
1689 | {
1690 | "recurrence": "DTSTART;TZID=PDT:20140313T200000DTEND;TZID=PDT:20140313T220000RRULE:FREQ=DAILY"
1691 | }
1692 | ],
1693 | "effects": [
1694 | {
1695 | "scene": {
1696 | "name":"Data Scene",
1697 | "members": [
1698 | "object_id":"asdfoaiye",
1699 | "object_type":"light_bulb",
1700 | "desired_state": {
1701 | "powered":true,
1702 | "brightness": 0.75
1703 | }
1704 | ]
1705 | }
1706 | },
1707 | {
1708 | "recipient_actor_id": "adsfhkjasdfy",
1709 | "recipient_actor_type": "user",
1710 | "notification_type": "email
1711 | }
1712 |
1713 | ]
1714 | }
1715 |
1716 | + Response 200 (application/json)
1717 |
1718 | [robot][]
1719 |
1720 | ### get all robots belonging to user [GET]
1721 |
1722 | + Request
1723 |
1724 | + Headers
1725 |
1726 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1727 |
1728 | + Response 200 (application/json)
1729 |
1730 | {
1731 | "data": [
1732 | {
1733 | "scene_id": "622328",
1734 | "name": "Dim kitchen",
1735 | "order": 0,
1736 | "members": [
1737 | {
1738 | "object_type": "light_bulb",
1739 | "object_id": "494715",
1740 | "desired_state": {
1741 | "brightness": 0.16,
1742 | "powered": true,
1743 | "powering_mode": "null",
1744 | "timer": 0
1745 | },
1746 | "local_scene_id": null
1747 | }
1748 | ],
1749 | "icon_id": null
1750 | },
1751 | {
1752 | "scene_id": "625749",
1753 | "name": "Lights out",
1754 | "order": 0,
1755 | "members": [
1756 | {
1757 | "object_type": "light_bulb",
1758 | "object_id": "466672",
1759 | "desired_state": {
1760 | "brightness": 1,
1761 | "powered": false,
1762 | "powering_mode": "null",
1763 | "timer": 0
1764 | },
1765 | "local_scene_id": null
1766 | },
1767 | {
1768 | "object_type": "light_bulb",
1769 | "object_id": "494715",
1770 | "desired_state": {
1771 | "brightness": 1,
1772 | "powered": false,
1773 | "powering_mode": "null",
1774 | "timer": 0
1775 | },
1776 | "local_scene_id": null
1777 | }
1778 | ],
1779 | "icon_id": null
1780 | },
1781 | {
1782 | "scene_id": "625752",
1783 | "name": "Lights on",
1784 | "order": 0,
1785 | "members": [
1786 | {
1787 | "object_type": "light_bulb",
1788 | "object_id": "466672",
1789 | "desired_state": {
1790 | "brightness": 1,
1791 | "powered": true,
1792 | "powering_mode": "null",
1793 | "timer": 0
1794 | },
1795 | "local_scene_id": null
1796 | },
1797 | {
1798 | "object_type": "light_bulb",
1799 | "object_id": "494715",
1800 | "desired_state": {
1801 | "brightness": 1,
1802 | "powered": true,
1803 | "powering_mode": "null",
1804 | "timer": 0
1805 | },
1806 | "local_scene_id": null
1807 | }
1808 | ],
1809 | "icon_id": null
1810 | }
1811 | ],
1812 | "errors": [],
1813 | "pagination": {
1814 | "count": 3
1815 | }
1816 | }
1817 |
1818 | # Group Scene
1819 | Resources for creating and activating scenes
1820 |
1821 | ## scene [/scenes/{scene_id}]
1822 | The scene resource is a representation of a specific scene.
1823 |
1824 | A scene is a collection of desired states for any supported Wink device (such as an air conditioner or garage door) or any Wink object (such as the outlet on a powerstrip)
1825 |
1826 | The scene has the following attributes
1827 |
1828 | - scene_id (string, assigned, immutable)
1829 | - name (string, writable, mutable)
1830 |
1831 | The scene resource embeds the following arrays:
1832 |
1833 | - members (1 to many objects with desired states, creatable)
1834 |
1835 | Each object in the objects array is required to have the following:
1836 |
1837 | - object_id (string, ex. "abc")
1838 | - object_type (string, exs. "light_bulb", "garage_door")
1839 | - desired_state (object, mutable) [the values of the desired state are entirely dependent on the allowed desired state of the associated object. Please see the documentation for each object in your scene to see which attributes are allowed]
1840 |
1841 | Example of a light bulb with a desired powered of on
1842 |
1843 | {
1844 | "object_id":"afdjlafd",
1845 | "object_type:"light_bulb",
1846 | "desired_state": {
1847 | "powered": true
1848 | }
1849 | }
1850 |
1851 | + Model (application/json)
1852 |
1853 | JSON representation of an scene
1854 |
1855 | + Body
1856 |
1857 | {
1858 | "scene_id": "qs1ga9_1234deadbeef",
1859 | "name": "Coming home",
1860 | "members": [
1861 | {
1862 | "object_id":"afdjlafd",
1863 | "object_type:"light_bulb",
1864 | "desired_state": {
1865 | "powered": true
1866 | }
1867 | },
1868 | {
1869 | "object_id":"yasdfkha",
1870 | "object_type:"garage_door",
1871 | "desired_state": {
1872 | "position": 1.0
1873 | }
1874 | }
1875 | ]
1876 | }
1877 |
1878 | + Parameters
1879 | + Parameters
1880 | - scene_id (required, string, `qs1ga9_1234deadbeef`) ... String `scene_id` of the scene to perform action on. Has example value.
1881 |
1882 | ### Retrieve a scene [GET]
1883 | + Request
1884 |
1885 | + Headers
1886 |
1887 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1888 |
1889 | + Response 200 (application/json)
1890 |
1891 | [scene][]
1892 |
1893 | ### Update scene settings [PUT]
1894 | + Request (application/json)
1895 |
1896 | + Headers
1897 |
1898 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1899 |
1900 | + Body
1901 |
1902 | {
1903 | "name": "Coming home"
1904 | }
1905 |
1906 | + Response 200 (application/json)
1907 |
1908 | [scene][]
1909 |
1910 | ### Delete a scene [DELETE]
1911 | + Request
1912 |
1913 | + Headers
1914 |
1915 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1916 |
1917 | + Response 204
1918 |
1919 | ## User's Scenes [/users/me/scenes]
1920 |
1921 | ### New Scene [POST]
1922 |
1923 | + Request (application/json)
1924 |
1925 | + Headers
1926 |
1927 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1928 |
1929 | + Body
1930 |
1931 | {
1932 | "name": "Coming home",
1933 | "objects": [
1934 | {
1935 | "object_id":"afdjlafd",
1936 | "object_type:"light_bulb",
1937 | "desired_state": {
1938 | "powered": true
1939 | }
1940 | },
1941 | {
1942 | "object_id":"yasdfkha",
1943 | "object_type:"garage_door",
1944 | "desired_state": {
1945 | "position": 1.0
1946 | }
1947 | }
1948 | ]
1949 | }
1950 |
1951 |
1952 | + Response 200 (application/json)
1953 |
1954 | [scene][]
1955 |
1956 | ### Retrieve all scenes [GET]
1957 | + Request
1958 |
1959 | + Headers
1960 |
1961 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1962 |
1963 | + Response 200 (application/json)
1964 |
1965 | + Body
1966 |
1967 | {"data":[{"scene_id":"622328","name":"Dim kitchen","order":0,"members":[{"object_type":"light_bulb","object_id":"494715","desired_state":{"brightness":0.16,"powered":true,"powering_mode":"null","timer":0},"local_scene_id":null}],"icon_id":null},{"scene_id":"625749","name":"Lights out","order":0,"members":[{"object_type":"light_bulb","object_id":"466672","desired_state":{"brightness":1.0,"powered":false,"powering_mode":"null","timer":0},"local_scene_id":null},{"object_type":"light_bulb","object_id":"494715","desired_state":{"brightness":1.0,"powered":false,"powering_mode":"null","timer":0},"local_scene_id":null}],"icon_id":null},{"scene_id":"625752","name":"Lights on","order":0,"members":[{"object_type":"light_bulb","object_id":"466672","desired_state":{"brightness":1.0,"powered":true,"powering_mode":"null","timer":0},"local_scene_id":null},{"object_type":"light_bulb","object_id":"494715","desired_state":{"brightness":1.0,"powered":true,"powering_mode":"null","timer":0},"local_scene_id":null}],"icon_id":null}],"errors":[],"pagination":{"count":3}}
1968 |
1969 | ## activate a scene [/scenes/{scene_id}/activate]
1970 |
1971 | ### activate [POST]
1972 | + Request
1973 |
1974 | + Headers
1975 |
1976 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
1977 |
1978 | + Response 204
1979 |
1980 | + Parameters
1981 | - scene_id (required, string, `qs1ga9_1234deadbeef`) ... String `scene_id` of the scene to perform action on. Has example value.
1982 |
1983 | # Group Air Conditioner
1984 | Resources for controlling Air Conditioner devices
1985 |
1986 | ## air_conditioner [/air_conditioners/{air_conditioner_id}]
1987 | The air_conditioner resource is a representation of a single Air Conditioner.
1988 |
1989 | The air_conditioner resource has the following specific attributes:
1990 |
1991 | - air_conditioner_id (string, assigned, immutable)
1992 | - electric_rate (float, assigned) [the price per kwh electric rate for the AC given the location]
1993 | - smart_schedule_enabled (boolean, assigned) [whether smart schedule has been enabled for AC]
1994 |
1995 | The air_conditioner resource embeds the following objects
1996 |
1997 | - current_budget (1, readable) [budget object of the current budget that spans the current time. Will be null if no budget is set]
1998 | - desired_state (1, writable)
1999 | - last_reading (1, readable)
2000 | - triggers (0 to many triggers, creatable)
2001 |
2002 | To change the state of an Air Conditioner, write changes in a PUT request to the desired_state object.
2003 |
2004 | To retrieve current state of an Air Conditioner, read values from last_reading object.
2005 |
2006 | Desired State attributes
2007 |
2008 | - fan_speed (float) [0 - 1]
2009 | - mode ["cool_only", "fan_only", "auto_eco"]
2010 | - powered (boolean)
2011 | - max_set_point (float) [in celsius]
2012 |
2013 | {
2014 | "fan_speed": 0.33,
2015 | "mode": "auto_eco",
2016 | "powered": true,
2017 | "max_set_point": 20.0
2018 | },
2019 |
2020 | Last Reading attributes
2021 |
2022 | - connection (Boolean) [whether or not the device is reachable remotely]
2023 | - connection_updated_at (Long)
2024 | - consumption (Long) [power consumption]
2025 | - consumption_updated_at (Long)
2026 | - fan_speed [maps to fan speed last read from device itself]
2027 | - fan_speed_updated_at (Long)
2028 | - mode [maps to mode last read from device itself]
2029 | - mode_updated_at (Long)
2030 | - powered [maps to powered last read from device itself]
2031 | - powered_updated_at (Long)
2032 | - max_set_point [maps to set point last read from device itself]
2033 | - max_set_point_updated_at (Long)
2034 | - temperature [maps to room temperature last read from device itself]
2035 | - temperature_updated_at (Long)
2036 |
2037 | {
2038 | "connection": true,
2039 | "connection_updated_at": 1393104904,
2040 | "consumption": 1236.891237,
2041 | "consumption_updated_at": 1393104904,
2042 | "fan_speed": 0.33,
2043 | "fan_speed_updated_at": 1393104904,
2044 | "mode": "auto_eco",
2045 | "mode_updated_at": 1393104904,
2046 | "powered": true,
2047 | "powered_updated_at": 1393104904,
2048 | "temperature": 23.0,
2049 | "temperature_updated_at": 1393104904,
2050 | "max_set_point": 22.0,
2051 | "max_set_point_updated_at": 1393104904,
2052 | }
2053 |
2054 | Allowed triggers
2055 |
2056 | - Connection: { "reading_type": "connection", "edge": "falling"; "threshold": 1.0}
2057 |
2058 | + Model (application/json)
2059 |
2060 | JSON representation of an air_conditioner
2061 |
2062 | + Body
2063 |
2064 | {
2065 | "air_conditioner_id": "qs1ga9_1234deadbeef",
2066 | "electric_rate": 0.13,
2067 | "smart_schedule_enabled": false,
2068 | "current_budget": {
2069 | "budget_id": "asdfhoiufd",
2070 | "air_conditioner_id": "awefoiuandf",
2071 | "from_time": 1393104904,
2072 | "until_time": 1395104904,
2073 | "name": "My budget",
2074 | "budgetable_reading": "cost",
2075 | "edge": "rising",
2076 | "threshold":45.0,
2077 | "projected_over_budget": false
2078 | },
2079 | "desired_state": {
2080 | "automation_mode": "away",
2081 | "fan_speed": 0.33,
2082 | "mode": "auto_eco",
2083 | "powered": true,
2084 | "temperature": 20.0
2085 | },
2086 | "last_reading": {
2087 | "connection": true,
2088 | "connection_updated_at": 1393104904,
2089 | "consumption": 1236.891237,
2090 | "consumption_updated_at": 1393104904,
2091 | "fan_speed": 0.33,
2092 | "fan_speed_updated_at": 1393104904,
2093 | "mode": "auto_eco",
2094 | "mode_updated_at": 1393104904,
2095 | "powered": true,
2096 | "powered_updated_at": 1393104904,
2097 | "temperature": 23.0,
2098 | "temperature_updated_at": 1393104904,
2099 | "max_set_point": 22.0,
2100 | "max_set_point_updated_at": 1393104904,
2101 | }
2102 | "triggers": []
2103 | }
2104 |
2105 | + Parameters
2106 | + air_conditioner_id (required, string, `qs1ga9_1234deadbeef`) ... String `air_conditioner_id` of the air conditioner to perform action on. Has example value.
2107 |
2108 | ### Retrieve an air_conditioner [GET]
2109 | + Request
2110 |
2111 | + Headers
2112 |
2113 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2114 |
2115 | + Response 200 (application/json)
2116 |
2117 | [air_conditioner][]
2118 |
2119 | ### Update air_conditioner settings [PUT]
2120 | + Request (application/json)
2121 |
2122 | + Headers
2123 |
2124 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2125 |
2126 | + Body
2127 |
2128 | {
2129 | "name": "Living room"
2130 | }
2131 |
2132 | + Response 200 (application/json)
2133 |
2134 | [air_conditioner][]
2135 |
2136 | ## ac reading [/air_conditioners/{air_conditioner_id}/readings/?since={since}&until={until}&keys={keys}&filter_type={filter_type}&timezone={timezone}]
2137 |
2138 | The ac reading resource has the following attributes:
2139 |
2140 | - created_at (integer, assigned, immutable)
2141 | - value (float)
2142 | - key (String) ["desired_fan_speed", "fan_speed", "desired_mode", "mode", "desired_temperature", "temperature", "desired_automation_mode", "automation_mode", "cost"]
2143 |
2144 | Example of consumption
2145 |
2146 | {
2147 | "created_at": 123458000,
2148 | "value": 5.0,
2149 | "key": "consumption"
2150 | }
2151 |
2152 |
2153 | Example of fan_speed
2154 |
2155 | {
2156 | "created_at": 123458000,
2157 | "value": 0.33,
2158 | "key": "fan_speed"
2159 | }
2160 |
2161 | Example of mode
2162 |
2163 | {
2164 | "created_at": 123458000,
2165 | "value": "auto_eco",
2166 | "key": "mode"
2167 | }
2168 |
2169 |
2170 | Example of automation mode
2171 |
2172 | {
2173 | "created_at": 123458000,
2174 | "value": "budget",
2175 | "key": "automation_mode"
2176 | }
2177 |
2178 | Example of temperature
2179 |
2180 | {
2181 | "created_at": 123458000,
2182 | "value": 20.0,
2183 | "key": "temperature"
2184 | }
2185 |
2186 | Example of powered
2187 |
2188 | {
2189 | "created_at": 123458000,
2190 | "value": false,
2191 | "key": "powered"
2192 | }
2193 |
2194 | Example of cost. Note, this is a reading that is calculated on consumption and is best used with a filter_type
2195 |
2196 | {
2197 | "created_at": 123458000,
2198 | "value": 10.5,
2199 | "key": "cost"
2200 | }
2201 |
2202 | + Model
2203 | JSON representation of ac reading
2204 |
2205 | + Body
2206 |
2207 | {
2208 | "created_at": 123458000,
2209 | "value": 5.0,
2210 | "key": "consumption"
2211 | }
2212 |
2213 | + Parameters
2214 | + air_conditioner_id (required, string, `sadjidbbb_201bd`) ... String `air_conditioner_id` of the air_conditioner to perform action on. Has example value.
2215 | + since (optional, integer, `123456789`) ... int Unix `since` of when you want query to start. Has example value.
2216 | + until (optional, integer, `123456789`) ... int Unix `until` of when you want query to end. Has example value.
2217 | + keys (optional, string, `fan_speed,mode`) ... String `keys` of which readings you want to see, Comma separated. Has example value.
2218 | + filter_type (optional, string, `daily`) ... String `filter_type` of aggregation types for readings. Has example value.
2219 | + timezone (optional, string, `America/New_York`) ... String `timezone` of timezone if filter_type is used to make sure aggregation spans expected values
2220 |
2221 | ### List readings of an air conditioner [GET]
2222 | + Request
2223 |
2224 | + Headers
2225 |
2226 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2227 |
2228 | + Response 200 (application/json)
2229 |
2230 | [ac reading][]
2231 |
2232 | ## ac projection [/air_conditioners/{air_conditioner_id}/projections/?since={since}&until={until}&keys={keys}&filter_type={filter_type}&timezone={timezone}]
2233 |
2234 | Projections function very similarly to readings and have the same format in both the query to retrieve them as well as the response object.
2235 |
2236 | They differ in that the responses represent predictions or projections of the future rather than past actual readings.
2237 |
2238 | Like readings, filter_type can be used to aggregate information.
2239 |
2240 | So that a filter_type of "monthly" and keys "cost", will give you the projected monthly cost
2241 |
2242 | Similarly, a filter_type of "daily" and keys "external_temperature", will give you the daily temperature for the given time period
2243 |
2244 | - created_at (integer, assigned, immutable)
2245 | - value (float)
2246 | - key (String) ["cost", "consumption", "external_temperature"]
2247 |
2248 | + Model
2249 | JSON representation of ac reading
2250 |
2251 | + Body
2252 |
2253 | {
2254 | "created_at": 123458000,
2255 | "value": 5.0,
2256 | "key": "cost"
2257 | }
2258 |
2259 | + Parameters
2260 | + air_conditioner_id (required, string, `sadjidbbb_201bd`) ... String `air_conditioner_id` of the air_conditioner to perform action on. Has example value.
2261 | + since (optional, integer, `123456789`) ... int Unix `since` of when you want query to start. Has example value.
2262 | + until (optional, integer, `123456789`) ... int Unix `until` of when you want query to end. Has example value.
2263 | + keys (optional, string, `cost`) ... String `keys` of which projections you want to see, Comma separated. Has example value.
2264 | + filter_type (optional, string, `daily`) ... String `filter_type` of aggregation types for readings. Has example value.
2265 | + timezone (optional, string, `America/New_York`) ... String `timezone` of timezone if filter_type is used to make sure aggregation spans expected values
2266 |
2267 | ### List projections of an air conditioner [GET]
2268 | + Request
2269 |
2270 | + Headers
2271 |
2272 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2273 |
2274 | + Response 200 (application/json)
2275 |
2276 | [ac projection][]
2277 |
2278 | ## ac stat [/air_conditioners/{air_conditioner_id}/stats/?since={since}&until={until}]
2279 |
2280 | The deposit resource has the following attributes:
2281 |
2282 | - total_cost (float) [cumulative cost of given period
2283 | - target_cost (float) [average set target cost for given period]
2284 | - average_daily_cost (float) [average cost for days in the given period]
2285 | - average_monthly_cost (float) [average cost by month for lifetime of readings]
2286 | - national_average_monthly_cost (float) [average cost by month for nation]
2287 |
2288 | + Model
2289 | JSON representation of ac stat
2290 |
2291 | + Body
2292 |
2293 | {
2294 | "total_cost": 12825268642.412,
2295 | "target_cost": 35.0,
2296 | "average_daily_cost": 11521148148.14255,
2297 | "average_monthly_cost": 345634444444.2765,
2298 | "national_average_monthly_cost": 36.26
2299 | }
2300 |
2301 | + Parameters
2302 | + air_conditioner_id (required, string, `sadjidbbb_201bd`) ... String `air_conditioner_id` of the air_conditioner to perform action on. Has example value.
2303 | + since (optional, integer, `123456789`) ... int Unix `since` of when you want query to start. Has example value.
2304 | + until (optional, integer, `123456789`) ... int Unix `until` of when you want query to end. Has example value.
2305 |
2306 | ### List stats of an air conditioner [GET]
2307 | + Request
2308 |
2309 | + Headers
2310 |
2311 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2312 |
2313 | + Response 200 (application/json)
2314 |
2315 | [ac stat][]
2316 |
2317 |
2318 |
2319 |
2320 |
2321 | # Group Cloud Clock
2322 |
2323 | ## cloud_clock [/cloud_clocks/{cloud_clock_id}]
2324 |
2325 | The cloud clock resource has the following attributes
2326 |
2327 | - cloud_clock_id (string, assigned, immuatable)
2328 | - name (string, mutable with write_data permissions)
2329 |
2330 | The cloud clock resource has the following attributes
2331 |
2332 | - dials (4 dials, assigned, permanent)
2333 | - alarms (0 to many, creatable)
2334 |
2335 | + Model (application/json)
2336 |
2337 | + Body
2338 |
2339 | {
2340 | "cloud_clock_id": "fasinfhs_12670s",
2341 | "name": "My Nimbus",
2342 | "dials": [
2343 | {
2344 | "dial_id": "456",
2345 | "dial_index": 0,
2346 | "name": "Facebook",
2347 | "label": "FACEBOOK",
2348 | "labels": ["FACEBOOK", "1 REQUEST"],
2349 | "position": 90.0,
2350 | "brightness": 25,
2351 | "channel_configuration": {
2352 | "channel_id": "6",
2353 | "linked_service_ids": ["123"],
2354 | "linked_service_types": ["facebook.read_messages"],
2355 | "reading_type":"friend_request_count",
2356 | "locale": "en_us"
2357 | },
2358 | "dial_configuration": {}
2359 | },
2360 | {
2361 | "dial_id": "457",
2362 | "dial_index": 1,
2363 | "name": "Twitter",
2364 | "label": "TWITTER",
2365 | "labels": ["TWITTER", "1 TWEET"],
2366 | "position": 270.0,
2367 | "brightness": 25,
2368 | "channel_configuration": {
2369 | "channel_id": "4322",
2370 | "linked_service_ids": ["124"],
2371 | "linked_service_types": ["twitter.read_messages"],
2372 | "reading_type": "latest_retweet_count",
2373 | "locale": "en_us",
2374 | },
2375 | "dial_configuration": {}
2376 | },
2377 | {
2378 | "dial_id": "458",
2379 | "dial_index": 2,
2380 | "labels": ["638.2 HRS", "TO DEST"],
2381 | "name": "Instagram",
2382 | "label": "INSTAGRAM",
2383 | "position": 180.0,
2384 | "brightness": 25,
2385 | "channel_configuration": {
2386 | "channel_id": "4323",
2387 | "linked_service_ids": ["125"],
2388 | "linked_service_types": ["instagram.read_messages"]
2389 | "reading_type": "latest_comment_count",
2390 | "locale": "en_us",
2391 | },
2392 | "dial_configuration": {}
2393 | },
2394 | {
2395 | "dial_id": "459",
2396 | "dial_index": 3,
2397 | "name": "Weather",
2398 | "label": "WEATHER",
2399 | "labels": ["FLURRIES", "TEMP 32"],
2400 | "position": 0.0,
2401 | "brightness": 25,
2402 | "channel_configuration": {
2403 | "lat_lng": [40.7517836, -74.0050807],
2404 | "reading_type": "weather_conditions",
2405 | "locale": "en_us",
2406 | "channel_id": "4324"
2407 | },
2408 | "dial_configuration": {}
2409 | }
2410 | ],
2411 | "alarms": [
2412 | {
2413 | "alarm_id": "555",
2414 | "name": "Wakie wakie",
2415 | "recurrence": "DTSTART:20130821T140000ZnRRULE:FREQ=DAILY",
2416 | "media_id": "666",
2417 | "enabled": true,
2418 | "next_at": 123456789.0
2419 | }
2420 | ]
2421 | }
2422 |
2423 | + Parameters
2424 | + cloud_clock_id (required, string, `fasinfhs_12670s`) ... String `cloud_clock_id` of the cloud clock to perform action on. Has example value.
2425 |
2426 | ### Retrieve a clock [GET]
2427 |
2428 | + Request
2429 |
2430 | + Headers
2431 |
2432 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2433 |
2434 | + Response 200 (application/json)
2435 |
2436 | [cloud_clock][]
2437 |
2438 |
2439 | ### Update a clock [PUT]
2440 |
2441 | + Request
2442 |
2443 | + Headers
2444 |
2445 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2446 |
2447 | + Body
2448 |
2449 | {
2450 | "name": "My Nimbus"
2451 | }
2452 |
2453 | + Response 200 (application/json)
2454 |
2455 | [cloud_clock][]
2456 |
2457 | ## dial_template [/dial_template]
2458 |
2459 | Returns the available channel_configurations and dial_configurations for the dial resource
2460 |
2461 | Explanation of dial_configuration fields and values
2462 |
2463 | - scale_type: log, linear [How the dial should move in response to higher values]
2464 | - rotation: cw, ccw [In which direction the dial should rotate]
2465 | - min_value: any number [The minimum data value the dial should attempt to display at min_position]
2466 | - max_value: any number greater than min_value [The maximum data value the dial should attempt to display at max_position]
2467 | - min_position: degree rotation which corresponds to min_value. Generally [0, 360] but not required to be so. [The position of the needle at min_value]
2468 | - max_postition: degree rotation which corresponds to max_value. Generally [0, 360] but not required to be so. [The position of the needle at max_value]
2469 |
2470 | Read types available for each dial_template channel configuration:
2471 |
2472 | - Time: n/a
2473 | - Weather: temperature, weather_conditions
2474 | - Traffic: travel_time, travel_conditions
2475 | - Calendar: time_until, time_of [refers to next appointment on calendar, currently only Google Calendar is supported]
2476 | - Email: unread_message_count [currently only Gmail is supported]
2477 | - Facebook: friend_request_count, latest_comment_count, latest_like_count, unread_message_count, unread_notification_count
2478 | - Twitter: latest_retweet_count, recent_mention_count, recent_direct_message_count
2479 | - Instagram: latest_like_count, latest_comment_count
2480 | - Fitbit: calorie_out_count, heart_rate, sleep_duration, step_count
2481 | - Eggminder: inventory
2482 | - Porkfolio: balance
2483 |
2484 | Other field values seen in dial_templates
2485 |
2486 | - timezone: any IANA timezone
2487 | - locale: A standard locale string of the ll_cc format, where ll is the two letter ISO language code and cc is the two letter ISO country code
2488 | - lat_lng: tuple of (lat, lng) for the Weather channel
2489 | - location: location string (New York, NY) for display for the Weather channel
2490 | - start_lat_lng: tuple of (lat, lng) for the Traffic channel
2491 | - start_location: location string (New York, NY) for display for the Traffic channel
2492 | - stop_lat_lng: tuple of (lat, lng) for the Traffic channel
2493 | - stop_location: location string (New York, NY) for display for the Traffic channel
2494 | - transit_mode: one of ["car", "ped", "bike", "transit"] representing desired principal mode of transit for the Traffic channel
2495 |
2496 | ### View all dial templates [GET]
2497 | + Request
2498 |
2499 | + Headers
2500 |
2501 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2502 |
2503 |
2504 | + Response 200 (application/json)
2505 |
2506 | {
2507 | "dial_template_id": "4",
2508 | "dial_configuration": {
2509 | "min_value": 0,
2510 | "max_value": 3600,
2511 | "min_position": 0,
2512 | "max_position": 360,
2513 | "scale_type": "linear",
2514 | "rotation": "cw"
2515 | },
2516 | "channel_configuration": {
2517 | "channel_id": "4",
2518 | "reading_type": "time_until",
2519 | },
2520 | "name": "Calendar"
2521 | }
2522 |
2523 | ## dial [/dials/{dial_id}]
2524 |
2525 | Each cloud_clock resources have 4 dial resources. Use dial_template to retrieve possible values for channel_configuration and dial_configuration
2526 |
2527 | The dial resource has the following attributes:
2528 |
2529 | - dial_id (string, assigned, immutable)
2530 | - dial_index (integer, assigned, immutable)
2531 | - name (string, mutable with write_data permissions)
2532 | - label (string, assigned, mutable)
2533 | - labels (array, assigned, immutable) [values determined by channel type and value, for display on clock LCD)
2534 | - position (float, assigned, immutable) [0.0 - 359.0, position of needle on display]
2535 | - brightness (integer, assigned, mutable) [0 - 100, display brightness of LCD, can also be updated on clock by pressing down]
2536 |
2537 | The dial resource has the following resources:
2538 |
2539 | - channel_configuration (see dial_templates for possible values)
2540 | - dial_configuration (see dial_templates for possible values)
2541 |
2542 | + Model (application/json)
2543 |
2544 | + Body
2545 |
2546 | {
2547 | "dial_id": "adsfljk_458",
2548 | "dial_index": 2,
2549 | "name": "Instagram",
2550 | "label": "INSTAGRAM",
2551 | "labels": ["INSTAGRAM", "1 LIKE"],
2552 | "position": 180.0,
2553 | "brightness": 25,
2554 | "channel_configuration": {
2555 | "channel_id": "4323",
2556 | "linked_service_ids": ["125"],
2557 | "linked_service_types": ["instagram.read_messages"]
2558 | "reading_type": "latest_comment_count",
2559 | "locale": "en_us",
2560 | },
2561 | "dial_configuration": {
2562 | "scale_type": "linear",
2563 | "rotation": "cw",
2564 | "min_position": 0.0,
2565 | "min_value": 0.0,
2566 | "max_position": 0.0,
2567 | "max_value": 0.0,
2568 | "num_ticks": 0
2569 | }
2570 | }
2571 |
2572 | ### updating a dial [PUT]
2573 |
2574 | + Request
2575 |
2576 | + Headers
2577 |
2578 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2579 |
2580 | + Body
2581 |
2582 | "channel_configuration": {
2583 | "channel_id": "4323",
2584 | "linked_service_ids": ["125"],
2585 | "linked_service_types": ["instagram.read_messages"]
2586 | "reading_type": "latest_comment_count",
2587 | "locale": "en_us",
2588 | }
2589 |
2590 | + Response 200 (application/json)
2591 |
2592 | [dial][]
2593 |
2594 | ## alarm [/alarms/{alarm_id}]
2595 |
2596 | The alarm resource has the following attributes:
2597 |
2598 | - alarm_id (string, assigned, immutable)
2599 | - cloud_clock_id (string, assigned, immutable) [id of associated cloud_clock]
2600 | - name (string, mutable with write_data permissions)
2601 | - recurrence (string, mutable with write_data permission) [Recurrence string in iCalendar format]
2602 | - enabled (boolean, mutable with write_data)
2603 | - next_at (float, assigned, immutable) [time stamp of next alarm]
2604 |
2605 | + Model
2606 |
2607 | JSON represenation of an alarm resource
2608 |
2609 | + Body
2610 |
2611 | {
2612 | "alarm_id": "fadlkfh_124_hasd",
2613 | "cloud_clock_id": "fasinfhs_12670s",
2614 | "name": "Wakie wakie",
2615 | "recurrence": "DTSTART;TZID=America/New_York:20130826T073000nRRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR",
2616 | "enabled": true,
2617 | "next_at": 123456789.0
2618 | }
2619 |
2620 | + Parameters
2621 | + alarm_id (required, string, `fadlkfh_124_hasd`) ... String `alarm_id` of the alarm to perform action on. Has example value.
2622 |
2623 | ### Update an alarm [PUT]
2624 |
2625 | + Request
2626 |
2627 | + Headers
2628 |
2629 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2630 |
2631 | + Body
2632 |
2633 | {
2634 | "enabled": true
2635 | }
2636 |
2637 | + Response 200 (application/json)
2638 |
2639 | [alarm][]
2640 |
2641 | ### Delete an alarm [DELETE]
2642 | + Request
2643 |
2644 | + Headers
2645 |
2646 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2647 |
2648 | + Response 204
2649 |
2650 | ## alarms of cloud clock [/cloud_clocks/{cloud_clock_id}/alarms]
2651 |
2652 | + Parameters
2653 | + cloud_clock_id (required, string, `fasinfhs_12670s`) ... String `cloud_clock_id` of the cloud clock to perform action on. Has example value.
2654 |
2655 | ### List alarms of clock [GET]
2656 | + Request
2657 |
2658 | + Headers
2659 |
2660 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2661 |
2662 |
2663 | + Response 200 (application/json)
2664 |
2665 |
2666 | [alarm][]
2667 |
2668 | ### create new alarm [POST]
2669 |
2670 | + Request
2671 |
2672 | + Headers
2673 |
2674 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2675 |
2676 |
2677 | + Body
2678 |
2679 | {
2680 | "name": "Wakie wakie",
2681 | "recurrence": "DTSTART;TZID=America/New_York:20130826T073000nRRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR"
2682 | }
2683 |
2684 | + Response 200 (application/json)
2685 |
2686 | [alarm][]
2687 |
2688 | # Group Eggtray
2689 | Resources for controlling Eggminder devices
2690 |
2691 | ## eggtray [/eggtrays/{eggtray_id}]
2692 | The eggtray resource is a representation of a single Eggminder device
2693 |
2694 | The eggtray resource has the following attributes:
2695 |
2696 | - eggtray_id (string, assigned, immutable)
2697 | - name (string, mutable with write_data permission on eggtray device)
2698 | - freshness (integer, mutable with write_data permission on eggtray device) [Period during which eggs are defined as fresh in seconds]
2699 | - eggs (array of 14 integers, assigned, immutable) [Timestamp in seconds of when each egg was added]
2700 |
2701 | + Model (application/json)
2702 |
2703 | JSON representaion of a scheduled outlet states
2704 |
2705 | + Body
2706 |
2707 | {
2708 | "eggtray_id": "adsfljk+109288=",
2709 | "name": "Henrietta",
2710 | "eggs": [
2711 | 1377180085,
2712 | 1377180086,
2713 | 1377180087,
2714 | 1377180088,
2715 | 1377180089,
2716 | 1377180090,
2717 | 1377180091,
2718 | 1377180092,
2719 | 1377180093,
2720 | 1377180094,
2721 | 1377180095,
2722 | 1377180096,
2723 | 1377180097,
2724 | 1377180098
2725 | ],
2726 | "freshness_period": 2419200
2727 | }
2728 |
2729 | ### Retrieve an eggminder [GET]
2730 |
2731 | + Request
2732 |
2733 | + Headers
2734 |
2735 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2736 |
2737 | + Response 200 (application/json)
2738 |
2739 | [eggtray][]
2740 |
2741 |
2742 | ### Update an eggminder [PUT]
2743 |
2744 | + Request
2745 |
2746 | + Headers
2747 |
2748 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2749 |
2750 | + Body
2751 |
2752 | {
2753 | "freshness_period": 2419200
2754 | }
2755 |
2756 | + Response 200 (application/json)
2757 |
2758 | [eggtray][]
2759 |
2760 |
2761 |
2762 |
2763 |
2764 |
2765 |
2766 |
2767 |
2768 | # Group Piggy Bank
2769 |
2770 | ## piggy_bank [/piggy_banks/{piggy_bank_id}]
2771 |
2772 | The piggy_bank resource has the following attributes:
2773 |
2774 | - piggy_bank_id (string, assigned, immutable)
2775 | - name (string, mutable with write_data permissions)
2776 | - balance (integer, assigned, immutable) [the current balance in cents of the piggy bank, determined from deposits]
2777 | - last_deposit_amount (integer, assigned, immutable) [amount in cents of the last deposit]
2778 | - nose_color (string, mutable with write_data permissions) [hex color for the color of the nose]
2779 | - savings_goal (integer, mutable with write_data) [amount in cents of user-set savings goal]
2780 |
2781 | + Model
2782 |
2783 | + Body
2784 |
2785 | {
2786 | "piggy_bank_id": "sadjidbbb_201bd",
2787 | "name": "Beer money",
2788 | "balance": 19217,
2789 | "last_deposit_amount": 25,
2790 | "nose_color": "00ff00",
2791 | "savings_goal": 5000
2792 | }
2793 | + Parameters
2794 | + piggy_bank_id (required, string, `sadjidbbb_201bd`) ... String `piggy_bank_id` of the piggy bank to perform action on. Has example value.
2795 |
2796 | ### Retrieve a piggy_bank [GET]
2797 |
2798 | + Request
2799 |
2800 | + Headers
2801 |
2802 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2803 |
2804 | + Response 200 (application/json)
2805 |
2806 | [piggy_bank][]
2807 |
2808 | ### Update a piggy_bank [PUT]
2809 |
2810 | + Request
2811 |
2812 | + Headers
2813 |
2814 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2815 |
2816 |
2817 | + Body
2818 |
2819 | {
2820 | "savings_goal": 5000
2821 | }
2822 |
2823 | + Response 200 (application/json)
2824 |
2825 | [piggy_bank][]
2826 |
2827 | ## deposit [/piggy_banks/{piggy_bank_id}/deposits/?since={timestamp}]
2828 |
2829 | The deposit resource has the following attributes:
2830 |
2831 | - deposit_id (string, assigned, immutable)
2832 | - created_at (integer, assigned, immutable)
2833 | - amount (integer, mutable with write_data permissions)
2834 |
2835 | + Model
2836 | JSON representation of deposit
2837 |
2838 | + Body
2839 |
2840 | {
2841 | "deposit_id": "303d_d",
2842 | "created_at": 123458000,
2843 | "amount": 5
2844 | }
2845 |
2846 | + Parameters
2847 | + piggy_bank_id (required, string, `sadjidbbb_201bd`) ... String `piggy_bank_id` of the piggy bank to perform action on. Has example value.
2848 | + timestamp (optional, integer, `123456789`) ... int Unix `timestamp` of when you want query to start. Has example value.
2849 |
2850 | ### List deposits of a piggy bank [GET]
2851 | + Request
2852 |
2853 | + Headers
2854 |
2855 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2856 |
2857 | + Response 200 (application/json)
2858 |
2859 | [deposit][]
2860 |
2861 | ### Create a deposit or withdrawal [POST]
2862 |
2863 | Note: to create a withdrawal, set the amount to a negative integer
2864 |
2865 | + Request
2866 |
2867 | + Headers
2868 |
2869 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2870 |
2871 | + Body
2872 |
2873 | {
2874 | "amount": 5
2875 | }
2876 |
2877 | + Response 200 (application/json)
2878 |
2879 | [deposit][]
2880 |
2881 | # Group Powerstrip
2882 | Resources for controlling Pivot Power Genius devices
2883 |
2884 | ## powerstrip [/powerstrips/{powerstrip_id}]
2885 | The powerstrip resource is a representation of a single Pivot Power Genius device.
2886 |
2887 | The powerstrip resource has the following attributes:
2888 |
2889 | - powerstrip_id (string, assigned, immutable)
2890 |
2891 | The powerstrip resource embeds the following resources:
2892 |
2893 | - outlets (2 outlets, assigned, permanent)
2894 |
2895 | + Model (application/json)
2896 |
2897 | JSON representation of a Pivot Power Genius
2898 |
2899 | + Body
2900 |
2901 | {
2902 | "powerstrip_id": "qs1ga9_1234deadbeef",
2903 | "outlets": [
2904 | {
2905 | "outlet_id": "1tq1-654fed_18y5",
2906 | "outlet_index": 0,
2907 | "powered": true
2908 | },
2909 | {
2910 | "outlet_id": "u59h-654fee_ih17afg",
2911 | "outlet_index": 1,
2912 | "powered": false
2913 | }
2914 | ]
2915 | }
2916 |
2917 | + Parameters
2918 | + powerstrip_id (required, string, `qs1ga9_1234deadbeef`) ... String `powerstrip_id` of the powerstrip to perform action on. Has example value.
2919 |
2920 | ### Retrieve a powerstrip [GET]
2921 | + Request
2922 |
2923 | + Headers
2924 |
2925 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2926 |
2927 | + Response 200 (application/json)
2928 |
2929 | [powerstrip][]
2930 |
2931 | ### Update powerstrip settings [PUT]
2932 | + Request (application/json)
2933 |
2934 | + Headers
2935 |
2936 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2937 |
2938 | + Body
2939 |
2940 | {
2941 | "name": "Living room"
2942 | }
2943 |
2944 | + Response 200 (application/json)
2945 |
2946 | [powerstrip][]
2947 |
2948 | ## outlet [/outlets/{outlet_id}]
2949 | The outlet resource is a representation of a single app-controlled outlet of a Pivot Power Genius device.
2950 |
2951 | The outlet resource has the following attributes:
2952 |
2953 | - outlet_id (string, assigned, immutable)
2954 | - outlet_index (numeric, assigned, immutable)
2955 | - name (string, mutable with write_data permission for powerstrip)
2956 | - icon_id (string reference to an icon, mutable with write_data permission for powerstrip)
2957 | - powered (boolean, mutable with write_data permission for powerstrip)
2958 |
2959 | + Model (application/json)
2960 |
2961 | JSON representation of an outlet
2962 |
2963 | + Body
2964 |
2965 | {
2966 | "outlet_id": "1tq1-654fed_18y5",
2967 | "outlet_index": 0,
2968 | "powered": true
2969 | }
2970 |
2971 | ### Retrieve an outlet [GET]
2972 | + Request
2973 |
2974 | + Headers
2975 |
2976 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2977 |
2978 | + Response 200 (application/json)
2979 |
2980 | [outlet][]
2981 |
2982 | ### Update outlet settings [PUT]
2983 | + Request (application/json)
2984 |
2985 | + Headers
2986 |
2987 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
2988 |
2989 | + Body
2990 |
2991 | {
2992 | "powered": false
2993 | }
2994 |
2995 | + Response 200 (application/json)
2996 |
2997 | {
2998 | "outlet_id": "agh1ity-876f00",
2999 | "outlet_index": 0,
3000 | "name": "lamp",
3001 | "icon_id": "w-g9hqng_777ace-lamp",
3002 | "powered": false
3003 | }
3004 |
3005 |
3006 |
3007 | # Group Propane Tank
3008 |
3009 | ## propane_tank [/propane_tanks/{propane_tank_id}]
3010 | The propane_tank resource is a representation of a single Refuel.
3011 |
3012 | The propane_tank resource has the following specific attributes:
3013 |
3014 | - propane_tank_id (string, assigned, immutable)
3015 | - tare (float, mutable) [tare weight of current tank]
3016 | - created_at (long, assigned, immutable)
3017 | - tank_changed_at (long, assigned, immutable) [date last new tank was added]
3018 |
3019 | The propane_tank resource embeds the following objects
3020 |
3021 | - last_reading (1, readable)
3022 | - triggers (0 to many triggers, creatable)
3023 |
3024 | Last Reading attributes
3025 |
3026 | - connection (Boolean) [whether or not the device is reachable remotely]
3027 | - connection_updated_at (Long)
3028 | - battery (Float) [0 - 1 status of battery life]
3029 | - battery_updated_at (Long)
3030 | - remaining (Float) [0 - 1 percent of tank remaining]
3031 | - remaining_updated_at (Long)
3032 |
3033 | Allowed triggers
3034 |
3035 | - Connection: { "reading_type": "connection", "edge": "falling"; "threshold": 1.0}
3036 | - Battery: { "reading_type": "battery", "edge": "falling"; "threshold": 0.2}
3037 | - Low Fuel: { "reading_type": "remaining", "edge": "falling"; "threshold": 0.25}
3038 |
3039 | + Model (application/json)
3040 |
3041 | JSON representation of an air_conditioner
3042 |
3043 | + Body
3044 |
3045 | {
3046 | "propane_tank_id": "qs1ga9_1234deadbeef",
3047 | "tare": 17.25,
3048 | "tank_changed_at" : 1393104904,
3049 | "last_reading": {
3050 | "connection": true,
3051 | "connection_updated_at": 1393104904,
3052 | "battery": 0.8,
3053 | "battery_updated_at": 1393104904,
3054 | "remaining": 0.6,
3055 | "remaining_updated_at" :1393104904
3056 | }
3057 | "triggers": []
3058 | }
3059 |
3060 | + Parameters
3061 | + propane_tank_id (required, string, `qs1ga9_1234deadbeef`) ... String `propane_tank_id` of the air conditioner to perform action on. Has example value.
3062 |
3063 | ### Retrieve an propane_tank [GET]
3064 | + Request
3065 |
3066 | + Headers
3067 |
3068 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
3069 |
3070 | + Response 200 (application/json)
3071 |
3072 | [propane_tank][]
3073 |
3074 | ### Update propane_tank settings [PUT]
3075 | + Request (application/json)
3076 |
3077 | + Headers
3078 |
3079 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
3080 |
3081 | + Body
3082 |
3083 | {
3084 | "tare": 17.25
3085 | }
3086 |
3087 | + Response 200 (application/json)
3088 |
3089 | [propane_tank][]
3090 |
3091 | ## propane reading [/propane_tanks/{propane_tank_id}/readings/?since={since}&until={until}&filter_type={carryover,daily}&keys={keys}&timezone={timezone}]
3092 |
3093 | The reading resource has the following attributes:
3094 |
3095 | - created_at (integer, assigned, immutable)
3096 | - value (float)
3097 | - key (String) ["remaining", "tare", "battery"]
3098 |
3099 | + Model
3100 | JSON representation of reading
3101 |
3102 | + Body
3103 |
3104 | {
3105 | "created_at": 123458000,
3106 | "value": 0.6,
3107 | "key": "remaining"
3108 | }
3109 |
3110 | + Parameters
3111 | + propane_tank_id (required, string, `sadjidbbb_201bd`) ... String `propane_tank_id` of the propane_tank to perform action on. Has example value.
3112 | + since (optional, integer, `123456789`) ... int Unix `since` of when you want query to start. Has example value.
3113 | + until (optional, integer, `123456789`) ... int Unix `until` of when you want query to end. Has example value.
3114 | + filter_type (optional, string, `carryover,daily`) ... String `carryover,daily` filter type to get reading immediately prior to indicated time returned and to filter results by cumulative daily value
3115 | + keys (optional, string, `remaining,tare`) ... String `keys` of which readings you want to see, Comma separated. Has example value.
3116 | + timezone (optional, string, `America/New_York`) ... String `timezone` of timezone if filter_type is used to make sure aggregation spans expected values
3117 |
3118 | ### List readings of an air conditioner [GET]
3119 | + Request
3120 |
3121 | + Headers
3122 |
3123 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
3124 |
3125 | + Response 200 (application/json)
3126 |
3127 | [propane reading][]
3128 |
3129 | ## propane stat [/propane_tanks/{propane_tank_id}/stats/?since={since}&until={until}]
3130 |
3131 | The stats resource has the following attributes:
3132 |
3133 | - average_grill_time [Average grill time in seconds in given time period]
3134 | - average_tank_life_real [Average tank life in seconds of active grilling in given time period]
3135 | - average_tank_life_cumulative: [Average tank life in seconds of days tank was not empty in given time period]
3136 | - average_grills_per_tank [Average grills per tank in given time period]
3137 | - cumulative_tanks_used [Total tanks used in given time period]
3138 | - cumulative_grill_time [Total grill time in seconds in given time period]
3139 |
3140 | + Model
3141 | JSON representation of ac stat
3142 |
3143 | + Body
3144 |
3145 | {
3146 | "average_grill_time": 4341,
3147 | "average_tank_life_real": 4007091,
3148 | "average_tank_life_cumulative": 37111,
3149 | "average_grills_per_tank": 8.548951854411426,
3150 | "cumulative_tanks_used": 1.98,
3151 | "cumulative_grill_time": 60780
3152 | }
3153 |
3154 | + Parameters
3155 | + propane_tank_id (required, string, `sadjidbbb_201bd`) ... String `propane_tank_id` of the propane_tank to perform action on. Has example value.
3156 | + since (optional, integer, `123456789`) ... int Unix `since` of when you want query to start. Has example value.
3157 | + until (optional, integer, `123456789`) ... int Unix `until` of when you want query to end. Has example value.
3158 |
3159 | ### List stats of an propane [GET]
3160 | + Request
3161 |
3162 | + Headers
3163 |
3164 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
3165 |
3166 | + Response 200 (application/json)
3167 |
3168 | [propane stat][]
3169 |
3170 |
3171 |
3172 | # Group Sensor Pod
3173 |
3174 | ## sensor_pod [/sensor_pods/{sensor_pods}]
3175 |
3176 | The sensor_pod resource has the following attributes:
3177 |
3178 | - sensor_pod_id (string, assigned, immutable)
3179 | - name (string, mutable with write_data permissions)
3180 |
3181 | The sensor_pod resource has the following resouces:
3182 | - last_reading (1, see below for fields)
3183 | - last_event (1, see below for fields)
3184 |
3185 | Last reading fields
3186 |
3187 | - battery: level of battery as of last reading
3188 | - battery_updated_at: timestamp of last battery reading
3189 | - brightness: level of brightness as of last reading
3190 | - brightness_updated_at: timestamp of last brightness reading
3191 | - external_power: boolean of powered or in battery mode
3192 | - external_power_updated_at: timestamp of last external power reading
3193 | - humidity: float corresponding to percentage of humidity
3194 | - humidity_updated_at: timestamp of last humidity reading
3195 | - loudness: float value of loudness
3196 | - loudness_updated_at: timestamp of last loudness reading
3197 | - temperature: float temperature in Celsius
3198 | - temperature: timestamp of last temperature reading
3199 | - vibration: boolean reading of movement
3200 | - vibration_updated_at: timestamp of last movement reading
3201 |
3202 | Last event fields
3203 |
3204 | - brightness_occurred_at: timestamp of last measured change from low brightness to high brightness
3205 | - loudness_occurred_at: timstamp of last measured change of low sound to loud sound
3206 | - vibration_occurred_at: timestamp of last measured change of no movement to movement
3207 |
3208 | + Model
3209 |
3210 | JSON Representation of a sensor_pod
3211 |
3212 | + Body
3213 |
3214 | {
3215 | "sensor_pod_id": "1asdf23_snfds",
3216 | "name": "My Spotter",
3217 | "last_reading": {
3218 | "battery": 0.75,
3219 | "battery_updated_at": 123456789,
3220 | "brightness": 12.5,
3221 | "brightness_updated_at": 123456789,
3222 | "external_power": false,
3223 | "external_power_updated_at": 123456789,
3224 | "humidity": 0.45,
3225 | "humidity_updated_at": 123456789,
3226 | "loudness": null,
3227 | "loudness_updated_at": null,
3228 | "pressure": 0.25,
3229 | "pressure_updated_at": 123456789,
3230 | "temperature": 25.23,
3231 | "temperature_updated_at": 123456789,
3232 | "vibration": false,
3233 | "vibration_updated_at": 123456789
3234 | },
3235 | "last_event": {
3236 | "brightness_occurred_at": 123456789,
3237 | "loudness_occurred_at": null,
3238 | "vibration_occurred_at": 123456789
3239 | }
3240 | }
3241 |
3242 | ### Retrieve a sensor pod [GET]
3243 | + Request
3244 |
3245 | + Headers
3246 |
3247 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
3248 |
3249 | + Response 200 (application/json)
3250 |
3251 | [sensor_pod][]
3252 |
3253 | ### Update a piggy_bank [PUT]
3254 |
3255 | + Request
3256 |
3257 | + Headers
3258 |
3259 | Authorization : Bearer example_access_token_like_135fhn80w35hynainrsg0q824hyn
3260 |
3261 |
3262 | + Body
3263 |
3264 | {
3265 | "name": "My spotter"
3266 | }
3267 |
3268 | + Response 200 (application/json)
3269 |
3270 | [sensor_pod][]
3271 |
3272 |
3273 |
3274 |
3275 |
3276 |
3277 |
3278 |
3279 |
3280 |
3281 |
--------------------------------------------------------------------------------