forked from jjhtpc/Photon-RGB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhoton RGB Smartthings Device Type
235 lines (156 loc) · 6.04 KB
/
Photon RGB Smartthings Device Type
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// a maximum of eight servo objects can be created
// Copyright (c) <year>, <copyright holder>
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the <organization> nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
// * Redistribution of this software in source or binary forms shall be free
// of all charges or fees to the recipient of this software.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/**
* Spark Core
*
* Author: Justin Wurth
* Date: 2014-09-19
*/
preferences {
input("deviceId", "text", title: "Device ID")
input("token", "text", title: "Access Token")
}
metadata {
definition (name: "Spark/Photon WS2812b", namespace: "", author: "Justin Wurth")
{capability "Switch Level"
capability "Color Control"
capability "Color Temperature"
capability "Switch"
capability "Refresh"
capability "Polling"
attribute "colorName", "string"
}
}
// tile definitions
command "alerts"
command "moviedim"
command "tvdim"
tiles {
standardTile("switch", "device.switch", width: 1, height: 1, canChangeIcon: false) {
state "off", label: '${name}', action: "switch.on", icon: "st.Lighting.light13", backgroundColor: "#ffffff"
state "on", label: '${name}', action: "switch.off", icon: "st.Lighting.light13", backgroundColor: "#79b821", iconColor: "#ffffff"
}
standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
}
standardTile("alerts", "device.alerts") {
state "alerts", label: '${name}', action: "alerts", icon: "st.Lighting.light13", backgroundColor: "#ff0000", iconColor: "#ff0000"
}
standardTile("tvdim", "device.tvdim") {
state "tvdim", label: '${name}', action: "tvdim", icon: "st.Lighting.light13", backgroundColor: "#d3d3d3", iconColor: "#ffffff"
}
standardTile("moviedim", "device.moviedim") {
state "moviedim", label: '${name}', action: "moviedim", icon: "st.Lighting.light13", backgroundColor: "#d3ffd3", iconColor: "#ffffff"
}
standardTile("color", "device.color") {
state "alerts", label: '${name}', action: "tvdim", icon: "st.Lighting.light13", backgroundColor: "#ff0000", iconColor: "#ffffff"
state "tvdim", label: '${name}', action: "moviedim", icon: "st.Lighting.light13", backgroundColor: "#d3d3d3", iconColor: "#ffffff"
state "moviedim", label: '${name}', action: "alerts", icon: "st.Lighting.light13", backgroundColor: "#ffffff", iconColor: "#ffffff"
}
controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 3, inactiveLabel: false, range:"(0..100)") {
state "level", action:"switch level.setLevel"
}
controlTile("rgbSelector", "device.color", "color", height: 3, width: 3, inactiveLabel: false) {
state "color", action:"setColor"
}
main(["switch"])
details(["switch","color", "refresh", "levelSliderControl", "rgbSelector"])
}
def parse(String description) {
log.debug "This device does not support incoming events"
return null
}
def off(){
put '0'
sendEvent(name: "switch", value: "off" )
log.debug "switch is off"
}
def on() {
put '1'
sendEvent(name: "switch", value: "on" )
log.debug "switch is on"
}
def alerts() {
put '2'
sendEvent(name: "switch", value: "on" )
log.debug "this device is on alert"
}
def tvdim() {
put '3'
sendEvent(name: "switch", value: "on" )
log.debug "this device is on tvdim"
}
def moviedim() {
put '4'
sendEvent(name: "switch", value: "on" )
}
def setColor(value) {
log.debug "setColor: ${value.hue} and setSaturation: ${value.saturation}"
def rgb = rgbToShieldRgb(value.red, value.green, value.blue);
}
def rgbToShieldRgb(r,g,b){
r = r
b = b
g = g
put "$r,$g,$b"
log.debug "Switch set to $r,$g,$b"
}
def setLevel(value){
call "$value"
log.debug "$value"
}
def poll() {
log.debug "Executing 'poll'"
checkStatus ()
}
def refresh() {
log.debug "executing 'refresh'"
checkStatus()
}
def checkStatus(){
httpGet(uri: "https://api.particle.io/v1/devices/${deviceId}/checkStatus1?access_token=${token}",
contentType: 'application/json',)
{resp ->
log.debug "resp data: ${resp.data}"
log.debug "result: ${resp.data.result}"
sendEvent(name: "switch", value: "${resp.data.result}" )
}
}
private put(led) {
//Spark Core API Call
httpPost(
uri: "https://api.particle.io/v1/devices/${deviceId}/led",
body: [access_token: token, command: led],
)
}
private call(dim) {
//Spark Core API Call
httpPost(
uri: "https://api.particle.io/v1/devices/${deviceId}/dim",
body: [access_token: token, command: dim],
)
}