Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
63 lines (48 sloc) 1.74 KB
* Toggles a Smart-Outlet with a Virtual Button
* Copyright 2016 Fabrizio Guerrieri
// General info about the app (name, author, description, icons...)
name: "toggles-smart-outlet-w-virtual-button",
namespace: "fabrguer",
author: "Fabrizio Guerrieri",
description: "Toggles a Smart-Outlet with a Virtual Button",
category: "",
iconUrl: "",
iconX2Url: "",
iconX3Url: "")
// Instantiates two objects used to represents a Trigger device (the virtual push-button that is "pushed"
// by the Flic button) and an Actuator (the real SmartThings smart-outlet switch commanding my floor lamp).
preferences {
section("Trigger") {
input "virtButton", "capability.momentary", title: "Which Virtual Button?", required: true
section("Actuator") {
input "realSwitch", "capability.switch", title: "Which Real Switch?", required: true
// Executed once when the app is installed
def installed() {
// Executed anytime the app is updated
def updated() {
log.debug "Updated with settings: ${settings}"
// When the virtual button is pushed, the callback function virtButtonHandler is called
def initialize() {
subscribe(virtButton, "momentary.pushed", virtButtonHandler)
// Toggles the realSwitch (reads its current state and inverts it)
def virtButtonHandler(evt) {
if (realSwitch.currentState("switch")?.value == "on") {
} else {