-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathapp.groovy
127 lines (102 loc) · 3.01 KB
/
app.groovy
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
/**
* StatusThing
*
* Author: alexking@me.com
* Date: 2013-11-01
*
* Download the Mac App at https://github.com/alexking/StatusThing
*
*/
definition(
name: "StatusThing",
namespace: "",
author: "alexking@me.com",
description: "Mac app for controlling your SmartThings from your status bar. See the temperature at a glance, it F° or C°.",
category: "Convenience",
iconUrl: "https://alexking.io/StatusThing/SmartApp.png",
iconX2Url: "https://alexking.io/StatusThing/SmartApp@2x.png",
oauth: [displayName: "StatusThing", displayLink: ""]
)
preferences {
section("Settings") {
input "switches", "capability.switch", title : "Switches", multiple : true, required : true
input "temperatures", "capability.temperatureMeasurement", title : "Temperature", multiple : true, required : false
input "thermostats", "capability.thermostat", title : "Thermostats", multiple : true, required : false
}
}
mappings
{
path("/updateItemsAndTemperature")
{
action :
[
GET : "updateItemsAndTemperatures"
]
}
path("/itemChangeToState/:id/:state")
{
action :
[
GET : "itemChangeToState"
]
}
}
def updateItemsAndTemperatures()
{
def items = []
for (item in switches)
{
items << [ 'id' : item.id , 'state' : item.currentValue('switch') ?: '' , 'name' : item.displayName ]
}
def temperatureItems = []
if (temperatures)
{
for (temperature in temperatures)
{
def temperatureState = temperature.currentState('temperature')
temperatureItems << [
'id' : temperature.id,
'name' : temperature.displayName,
'value' : temperature.currentValue("temperature").toInteger(),
'unit' : temperatureState.hasProperty('unit') ? temperatureState.unit : 'F'
]
}
}
if (thermostats)
{
for (temperature in thermostats)
{
def temperatureState = temperature.currentState('temperature')
if (temperatureState != null) {
temperatureItems << [
'id' : temperature.id,
'name' : temperature.displayName,
'value' : temperature.currentValue("temperature").toInteger(),
'unit' : temperatureState.hasProperty('unit') ? temperatureState.unit : 'F'
]
}
}
}
[ 'temperatures' : temperatureItems , 'items' : items ]
}
def itemChangeToState()
{
def item = switches.find { it.id == params.id }
if (params.state == "on")
{
item.on();
} else {
item.off();
}
def data = updateItemsAndTemperatures()
for(dataItem in data['items'])
{
if (dataItem.id == params.id)
{
dataItem.state = params.state;
}
}
data
}
def installed() { }
def updated() { }