-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmartApp
156 lines (149 loc) · 6.67 KB
/
SmartApp
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
/**
* X2-Switch Control: 2-Switch Control for Modded SmartSense Open/Closed Sensor/Switch
* for Multiple Lights
*
* August 16, 2015
*
* SmartApp code and Device Type Template code can be found at
* https://github.com/jgoldwein/X2-Switch
*
* This SmartApp uses a single modified (hacked) SmartSense door open/close sensor wired to both an SPDT (3-way)
* switch and a standard SPST wall switch, each of whicn can toggle on and off a set of GE Link Lights or similar
* lights or switches.
*
* The intent is to have a simple and inexpensive battery operated replacement for a standard wall switch to
* operate multiple, 3-way zigbee or zwave lights or switches as well as a one way light or switch using two
* separate standard switches in an existing gang-box.
*
* The SmartSense (PEQ) sensor has been on sale intermittently at Best Buy for under $20, and a 3-way SPDT plus a
* standard wall switch costs a few dollars at any hardware store, so you can put the whole thing together for
* about $25.00.
*
* Do at your own risk. If you are placing these switches in the existing gang box with hot wires, even if the wires
* are capped off, this may be very dangerous and not up to code!
*
* The SmartSense door open/close sensor can be easily modded and wired to the 3-way wall switch and the standard
* wall switch as follows:
*
* 1. Replace (desolder) the reed relay with 3 wires connected to a 3-way wall switch.
* 2. Replace (desolder) the small push button switch with 2 wires connected to a standard on/off wall switch.
* 3. Provision the "Thing" (make sure you put the standard switch into OFF mode since ON mode at battery installation
* causes it to reset), and replace the device type with:
* "X2-Switch: Modded SmartSense Open/Closed Sensor/Switch: TWO Switch Version"
* 4. In selected gang box, have a certified electrician wire the GE link lights that will be used to remain ON
* by removing the existing switches and tying together the now hanging On-Off wires.
* Cap any "red" wires or otherwise exposed wires.
* 5. Install the new switches and Thing into the gang box or a new gang box (use standard electrical safety measures).
* 6. Use this app to control the lights
*
*
*
*
* Copyright (c) 2015 Joel Goldwein (goldwein at gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
definition(
name: "X2-Switch Control: 2-Switch Control for Modded SmartSense Open/Closed Sensor/Switch for Multiple Lights",
namespace: "JWGthings",
author: "Joel Goldwein (goldwein at gmail.com)",
description: "2-Switch multi-way On/Off controller - This SmartApp uses a single modified SmartSense (PEQ) door open/close sensor wired to a SPDT (3-way) switch AND a SPST (1 way) switch to toggle on/off MULTIPLE GE Link Lights, similar lights or switches. The intent is to have a simple and inexpensive battery operated replacement for TWO standard wall switches to operate at least two 3-way or multi-way zigbee or zwave lights or switchs. See X2-Switch: Modded Smartsense... for matching device type.",
category: "My Apps",
iconUrl: "http://cdn.device-icons.smartthings.com/Home/[email protected]",
iconX2Url: "http://cdn.device-icons.smartthings.com/Home/[email protected]",
iconX3Url: "http://cdn.device-icons.smartthings.com/Home/[email protected]"
)
preferences {
section("Select the control/switch you are using") {
input "contact1", "capability.contactSensor", title: "Which Control?", required: true, multiple: true, submitOnChange: true
}
// What primary light should this app be configured for?
section("Turn on/off which Link Lights with a 3-WAY switch...") {
input "switch1", "capability.switch", title: "Which Lights", required: true, multiple: true, submitOnChange: true
}
// What primary light should this app be configured for?
section("Turn on/off which Link Lights with 2-WAY switch...") {
input "switch2", "capability.switch", title: "Which Lights", required: true, multiple: true, submitOnChange: true
}
}
def installed() {
// log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
// log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
subscribe(contact1, "contact", contactHandler)
}
def contactHandler(evt) {
def cname1 = "${contact1.displayName}"
def lname1 = "${switch1.displayName}"
def lname2 = "${switch2.displayName}"
def sstate = "${switch1.currentSwitch}"
def xcase = "${evt.value}"
// log.debug "xcase: $xcase"
log.debug "Triggered. Sensor was set to $evt.value and $lname1 $lname2 was SW1: $sstate $switch1.currentSwitch SW2: $switch2.currentSwitch"
// The contactSensor capability can be either "open" or "closed"
// The actual sensor state is not relevant. What is only important is the state change,
// Code is triggered any time there is a state change in the door sensor
// Eventually, I'm going to try doing this with a SPST switch instead of a SPDT switch
//
// If the switch is UP (closed)
// log.debug "evt.value: $evt.value"
log.debug "3-way switch lights state: $sstate"
switch (xcase) {
case 'closed On':
log.debug "JWG1: closed On"
if (sstate.contains("off")) {
log.debug "sstate contains off"
switch1?.on()
}
switch2?.on()
break
// and if the switch is DOWN (open)
case 'open On':
// Turn it OFF
log.debug "JWG2: open On"
// if ("[on]" == sstate) {
if (sstate.contains("on")) {
log.debug "sstate contains on"
switch1?.off()
}
switch2?.on()
break
case 'closed Off':
// Turn it ON
log.debug "JWG3: closed Off"
// if ("[off]" == sstate) {
if (sstate.contains("off")) {
log.debug "sstate contains off"
switch1?.on()
}
switch2?.off()
break
case 'open Off':
// Turn it OFF
log.debug "JWG4: open Off"
// if ( "[on]" == sstate ) {
if (sstate.contains("on")) {
log.debug "sstate contains on"
switch1?.off()
}
switch2?.off()
break
default:
log.debug "Uncertain case switch"
log.debug "sstate: $sstate SW1: $switch1.currentSwitch, SW2: $switch2.currentSwitch"
}
}