Created
January 3, 2017 19:10
-
-
Save desertblade/a6ff4d7af3dee2f42b4a636b28d642c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Broadlink Switch | |
* | |
* Copyright 2016 BeckyR | |
* | |
* 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. | |
* | |
*/ | |
metadata { | |
definition (name: "RM Bridge Switch LAN", namespace: "beckyricha", author: "BeckyR") { | |
capability "Switch" | |
command "steadyBlue" | |
command "fireflyBlue" | |
command "fireflyGreen" | |
command "fireflyRed" | |
command "fireflyMulti" | |
command "twinkleMulti" | |
command "slowMulti" | |
command "slowRed" | |
command "slowGreen" | |
command "slowBlue" | |
command "slowPink" | |
command "slowAmber" | |
} | |
// tile definitions | |
tiles { | |
multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){ | |
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") { | |
attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"turningOff" | |
attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn" | |
} | |
tileAttribute ("device.currentSetting", key: "SECONDARY_CONTROL") { | |
attributeState "default", label:'${currentValue}' | |
} | |
} | |
standardTile("twinkleMulti", "device.switch", width:2, height:2, decoration: "flat") { | |
state("default", action: "twinkleMulti", backgroundColor: "", label:"Twinkle") | |
} | |
standardTile("steadyBlue", "device.switch", width:2, height:2, decoration: "flat") { | |
state("default", action: "steadyBlue", backgroundColor: "blue", label:"Steady") | |
} | |
standardTile("fireflyBlue", "device.switch", width:2, height:2, decoration: "flat") { | |
state("default", action: "fireflyBlue", backgroundColor: "blue", label:"Firefly") | |
} | |
standardTile("fireflyGreen", "device.switch", width:2, height:2, decoration: "flat") { | |
state("default", action: "fireflyGreen", backgroundColor: "green", label:"Firefly") | |
} | |
standardTile("fireflyRed", "device.switch", width:2, height:2, decoration: "flat") { | |
state("default", action: "fireflyRed", backgroundColor: "red", label:"Firefly") | |
} | |
standardTile("fireflyMulti", "device.switch", width:2, height:2, decoration: "flat") { | |
state("default", action: "fireflyMulti", backgroundColor: "", label:"Firefly") | |
} | |
standardTile("slowMulti", "device.switch", width:2, height:2, decoration: "flat") { | |
state("default", action: "slowMulti", backgroundColor: "", label:"Slow Twinkle") | |
} | |
standardTile("slowBlue", "device.switch", width:2, height:2, decoration: "flat") { | |
state("default", action: "slowBlue", backgroundColor: "blue", label:"Slow Twinkle") | |
} | |
standardTile("slowGreen", "device.switch", width:2, height:2, decoration: "flat") { | |
state("default", action: "slowGreen", backgroundColor: "green", label:"Slow Twinkle") | |
} | |
standardTile("slowRed", "device.switch", width:2, height:2, decoration: "flat") { | |
state("default", action: "slowRed", backgroundColor: "red", label:"Slow Twinkle") | |
} | |
standardTile("slowPink", "device.switch", width:2, height:2, decoration: "flat") { | |
state("default", action: "slowPink", backgroundColor: "#FF1493", label:"Slow Twinkle") | |
} | |
standardTile("slowAmber", "device.switch", width:2, height:2, decoration: "flat") { | |
state("default", action: "slowAmber", backgroundColor: "#FFC200", label:"Slow Twinkle") | |
} | |
main "switch" | |
details "switch","twinkleMulti","fireflyMulti", "slowMulti","fireflyBlue" ,"fireflyGreen", "fireflyRed", "slowBlue", "slowGreen", "slowRed", "slowPink", "slowAmber", "steadyBlue" | |
} | |
} | |
def on() { | |
log.debug "Turning On" | |
put(device.currentValue("currentSetting")) | |
} | |
def off() { | |
log.debug "OFF" | |
put('allOff') | |
} | |
def steadyBlue() { | |
log.debug "steadyBlue" | |
put('steadyBlue') | |
} | |
def fireflyBlue() { | |
log.debug "fireflyBlue" | |
put('fireflyBlue') | |
} | |
def fireflyGreen() { | |
log.debug "fireflyGreen" | |
put('fireflyGreen') | |
} | |
def fireflyRed() { | |
log.debug "fireflyRed" | |
put('fireflyRed') | |
} | |
def fireflyMulti() { | |
log.debug "fireflyMulti" | |
put('fireflyMulti') | |
} | |
def twinkleMulti() { | |
log.debug "twinkleMulti" | |
put('twinkleMulti') | |
} | |
def slowBlue() { | |
log.debug "slowBlue" | |
put('slowBlue') | |
} | |
def slowGreen() { | |
log.debug "slowGreen" | |
put('slowGreen') | |
} | |
def slowRed() { | |
log.debug "slowRed" | |
put('slowRed') | |
} | |
def slowMulti() { | |
log.debug "slowMulti" | |
put('slowMulti') | |
} | |
def slowPink() { | |
log.debug "slowPink" | |
put('slowPink') | |
} | |
def slowAmber() { | |
log.debug "slowAmber" | |
put('slowAmber') | |
} | |
def put(command) { | |
if ( command != 'allOff' ) { | |
sendEvent(name:"switch", value: "on", descriptionText: "Turning on" , display: true, displayed: true) | |
sendEvent(name:"currentSetting", value: command, descriptionText: command , display: true, displayed: true) | |
} else { | |
sendEvent(name:"switch", value: "off", descriptionText: "Turning off" , display: true, displayed: true) | |
} | |
def url1="IP GOES HERE" | |
def userpassascii= "" | |
def userpass = "Basic " + userpassascii.encodeAsBase64().toString() | |
def replaced = command.replaceAll(' ', '%20') | |
def hubaction = new physicalgraph.device.HubAction( | |
method: "GET", | |
path: "/code/$replaced", | |
headers: [HOST: "${url1}", AUTHORIZATION: "${userpass}"], | |
) | |
return hubaction | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment