Skip to content

Instantly share code, notes, and snippets.

@joshualyon
Created February 28, 2020 18:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save joshualyon/227050e533b210fb9c3b2860b30622ea to your computer and use it in GitHub Desktop.
Save joshualyon/227050e533b210fb9c3b2860b30622ea to your computer and use it in GitHub Desktop.
/**
* Copyright 2015 SmartThings
*
* 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: "Virtual Momentary Switch", namespace: "sharptools-io", author: "josh") {
capability "Actuator"
capability "Switch"
capability "Momentary"
capability "Sensor"
capability "Contact Sensor"
}
// simulator metadata
simulator {
status "open": "contact:open"
status "closed": "contact:closed"
}
// UI tile definitions
tiles {
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "off", label: 'Push', action: "momentary.push", backgroundColor: "#ffffff", nextState: "on"
state "on", label: 'Push', action: "momentary.push", backgroundColor: "#53a7c0"
}
main "switch"
details "switch"
}
}
def parse(String description) {
}
def push() {
sendEvent(name: "switch", value: "on", isStateChange: true)
sendEvent(name: "contact", value: "closed", isStateChange: true)
sendEvent(name: "momentary", value: "pushed", isStateChange: true)
runIn(1, resetState)
}
def on() {
log.trace('Virtual Momentary Switch: on()')
push()
}
def off() {
log.trace('Virtual Momentary Switch: off()')
push()
}
def resetState(){
log.trace('Virtual Momentary Switch: resetState()')
sendEvent(name: "switch", value: "off", isStateChange: true)
sendEvent(name: "contact", value: "open", isStateChange: true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment