LED Christmas Tree control (resetting toggle patterns to just on/off)

I have an artificial Christmas tree with pre-strung LED lights. The lights are controlled with a switch that toggles the tree between 4 settings: Off, Clear Lights On, Colored Lights On, Alternate between Clear/Color Lights On. The challenge with an an external controller light a SmartThings wall outlet switch is that when power is turned off, the tree “toggles” to the next setting. So, if you have timed routine to turn the tree on everyday, the first time it turns on to Clear lights, the second time to Colored Lights, the third time to Alternating lights and the fourth time is actually off.

To address this problem, I created a Simulated (virtual) Switch called Christmas Tree and am using a ST wall outlet called Sunroom Switch. I then created a simple SmartApp that subscribes to the On and Off event for the Simulated Switch. The SmartApp actually turns on the Sunroom Switch on/off/on/off/on/off/on so the tree always returns to the right “on” setting. For the Off command, the SmartApp simply turns off the physical switch when the virtual switch is turned off.

Don’t know if anyone has had this issue but here’s the SmartApp (my first):

/**

  • Switch Multiple Toggles
  • Copyright 2016 Dave Kleiman
  • 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: “Switch Multiple Toggles”,
namespace: “djkleiman”,
author: “Dave Kleiman”,
description: “Toggles a physical switch multiple times”,
category: “Convenience”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)

preferences {
section(“Which physical switch to toggle multiple times”) {
input “thephysicalswitch”, “capability.switch”, required: true
}
section(“Which virtual switch is the trigger”) {
input “thevirtualswitch”, “capability.switch”, required: true
}
}

def installed() {
log.debug “Installed with settings: ${settings}”

initialize()

}

def updated() {
log.debug “Updated with settings: ${settings}”

unsubscribe()
initialize()

}

def initialize() {
subscribe(thevirtualswitch,“switch.on”,switchToggledHandlerOn)
subscribe(thevirtualswitch,“switch.off”,switchToggledHandlerOff)
}

def switchToggledHandlerOn(evt) {
log.debug "switchToggleHandlerOn called $evt"
pause 2000
thephysicalswitch.on()
log.debug "switchToggleHandlerOn ON #1"
pause 2000
thephysicalswitch.off()
log.debug "switchToggleHandlerOn OFF #1"
pause 2000
thephysicalswitch.on()
log.debug "switchToggleHandlerOn ON #2"
pause 2000
thephysicalswitch.off()
log.debug "switchToggleHandlerOn OFF #2"
pause 2000
thephysicalswitch.on()
log.debug "switchToggleHandlerOn ON #3"
pause 2000
thephysicalswitch.off()
log.debug "switchToggleHandlerOn OFF #3"
pause 2000
thephysicalswitch.on()
log.debug “switchToggleHandlerOn ON #4
}

def switchToggledHandlerOff(evt) {
log.debug "switchToggleHandlerOff called $evt"
thephysicalswitch.off()

}

5 Likes

Man I wish I could use this app, my damn tree just resets to the demo mode every time I turn it back on. Thought it was defective so we packaged it back up and exchanged it but the new one does the same thing. So now I just leave it on all the time :slight_smile: