Changing remote branch to PLRG Git server.
[smartapps.git] / third-party / Lutron-Group-Control.groovy
1 definition(
2     name: "Lutron Group Control",
3     namespace: "sticks18",
4     author: "sgibson18@gmail.com",
5     description: "Add bulbs to a Lutron Remote without using the remote's join process",
6     category: "My Apps",
7     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
8     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png"
9 )
10
11 preferences {
12         page(name: "inputPage")
13 }
14
15 def inputPage() {
16         dynamicPage(name: "inputPage", title: "", install: true, uninstall: true) {
17     
18     section("Remote Setup") {
19                 paragraph "To get the Group Id of your remote, you must open Live Logging then fill in the inputs from this section. The code for the connected bulb selected must have a debug statement in its parse section, so you can see the response containing the group id.",
20             title: "First let's get the Group Id from your Remote by checking an already connected bulb", required: true        
21         input (name: "remote", type: "capability.button", title: "Lutron Remote", multiple: false, required: true, submitOnChange: true)
22                 input (name: "cBulb", type: "capability.switch", title: "Select a bulb connected to the remote", multiple: false, required: true, submitOnChange: true)
23                 input (name: "endpoint", type: "text", title: "Zigbee Endpoint of selected bulb", required: true, submitOnChange: true)
24     }
25     
26     if (remote && cBulb && endpoint) {
27         
28         remote.getGroup(cBulb.deviceNetworkId, endpoint)
29         
30         section("Enter the Group Id") {
31                 input (name: "grpId", type: "text", title: "Group Id for Remote", required: true)
32         }
33         section("Now let's pick some new bulbs"){
34                         input (name: "nBulbs", type: "capability.switch", title: "Select bulbs to add to the remote (all must use same endpoint)", multiple: true, required: true)
35             input (name: "nBulbEp", type: "text", title: "Zigbee Endpoint of selected bulbs", required: true)
36                 }
37     }
38     }
39 }
40
41 def installed() {
42     initialize()
43 }
44
45 def updated() {
46         unsubscribe()
47     removeBulbs()
48     addBulbs()
49     updateGrp()
50 }
51
52
53 def addBulbs() {
54     nBulbs.each {
55         def zigId = it.deviceNetworkId
56         def endpoint = nBulbEp
57         remote.assignGroup(zigId, endpoint, grpId)
58     }
59     
60 }
61
62 def removeBulbs() {
63     nBulbs.each {
64         def zigId = it.deviceNetworkId
65         def endpoint = nBulbEp
66         remote.removeGroup(zigId, endpoint, grpId)
67     }
68     
69 }
70
71 def updateGrp() {
72         remote.updateGroup(grpId)
73 }
74
75 def initialize() {
76         addBulbs()
77     updateGrp()
78 }
79
80 def uninstalled() {
81         removeBulbs()
82 }