-
Notifications
You must be signed in to change notification settings - Fork 8
/
scene-machine.app.groovy
145 lines (122 loc) · 4.47 KB
/
scene-machine.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* App Name: Scene Machine
*
* Author: Todd Wackford
* Date: 2013-06-14
* Version: 1.1
*
* Updated: 2013-07-25
*
* Change #1 Fixed bug where string null was being returned for non-dimmers and
* was trying to assign to variable.
*
* Change #2 Updated setLevel setion to work with bulbs that were not defined as type "Dimmer Switch"
*
*
* This app lets the user select from a list of switches or dimmers and record
* their currents states as a Scene. It is suggested that you name the app
* during install something like "Scene - Romantic Dinner" or
* "Scene - Movie Time". Switches can be added, removed or set at new levels
* by editing and updating the app from the smartphone interface.
*
* Usage Note: GE-Jasco dimmers with ST is real buggy right now. Sometimes the levels
* get correctly, sometimes not.
* On/Off is OK.
* Other dimmers should be OK.
*
* Use License: Non-Profit Open Software License version 3.0 (NPOSL-3.0)
* http://opensource.org/licenses/NPOSL-3.0
*/
// Automatically generated. Make future change here.
definition(
name: "Scene Machine Orig",
namespace: "wackware",
author: "[email protected]",
description: "This app lets the user select from a list of switches or dimmers and record their currents states as a Scene. It is suggested that you name the app during install something like 'Scene - Romantic Dinner' or 'Scene - Movie Time'. Switches can be added removed or set at new levels by editing and updating the app from the smartphone interface.",
category: "My Apps",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png"
)
preferences {
section("Select switches ...") {
input "switches", "capability.switch", multiple: true
}
//Uncomment this section below to test/change on the IDE. Smartphone does
//not need it.
//section("Record New Scene?") {
// input "record", "enum", title: "New Scene...", multiple: false,
// required: true, metadata:[values:['No','Yes']]
//}
}
def installed() {
log.debug "Installed with settings: ${settings}"
subscribe(app, appTouch)
getDeviceSettings()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
subscribe(app, appTouch)
//if(record == "Yes") //uncomment this line to test/change stuff on the IDE
getDeviceSettings()
}
def appTouch(evt) {
log.debug "appTouch: $evt"
setScene()
}
private setScene() {
def i = 0
def switchName = ""
def switchType = ""
def switchState = ""
def dimmerValue = ""
for(myData in state.lastSwitchData) {
switchName = myData.switchName
switchType = myData.switchType
switchState = myData.switchState
if(myData.dimmerValue != "null") //
dimmerValue = myData.dimmerValue.toInteger() //BF #1
else //
dimmerValue = 0 //
log.info "switchName: $switchName"
log.info "switchType: $switchType"
log.info "switchState: $switchState"
log.info "dimmerValue: $dimmerValue"
if(switchState == "on")
switches[i].on()
if(dimmerValue > 0)
switches[i].setLevel(dimmerValue)
if(switchState == "off")
switches[i].off()
i++
log.info "Device setting is Done-------------------"
}
}
private getDeviceSettings() {
def cnt = 0
for(myCounter in switches) {
switches[cnt].refresh() //this was a try to get dimmer values (bug)
//switches[cnt].poll()
cnt++
}
state.lastSwitchData = [cnt]
def i = 0
def switchName = ""
def switchType = ""
def switchState = ""
def dimmerValue = ""
for(mySwitch in switches) {
switchName = mySwitch.device.toString()
switchType = mySwitch.name.toString()
switchState = mySwitch.latestValue("switch").toString()
//dimmerValue below returns null if it is not a dimmer
dimmerValue = mySwitch.latestValue("level").toString()
state.lastSwitchData[i] = [switchName: switchName,
switchType: switchType,
switchState: switchState,
dimmerValue: dimmerValue]
log.debug "SwitchData: ${state.lastSwitchData[i]}"
i++
}
}