Skip to content

Instantly share code, notes, and snippets.

@AshMartian
Last active October 27, 2022 02:46
Show Gist options
  • Save AshMartian/ebf4fce7ef1b43e91108d62c24613617 to your computer and use it in GitHub Desktop.
Save AshMartian/ebf4fce7ef1b43e91108d62c24613617 to your computer and use it in GitHub Desktop.
Smartthings OSRAM RGBW Device Handler Smart App (To toggle Color Loop + extras)
/**
* OSRAM RGBW pulse
*
* Install OSRAM RGB Device Handler FIRST! Go into "My Devices", click "Edit" and change the Device Type to "OSRAM RGBW", this seems to work on a wide range on Zigbee bulbs including Sengled.
* https://community.smartthings.com/t/updated-osram-lightify-rgbw-a19-br30-us-version-ha-dth/57774
*
*
* Copyright 2020 Brandon Martin
*
* 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: "OSRAM RGBW pulse",
namespace: "blandman",
author: "Brandon Martin",
description: "Toggle OSRAM RGBW Device Handler commands.",
category: "Mode Magic",
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("Choose hue lights you wish to control?") {
input "hues", "capability.colorControl", title: "Which Color Changing Bulbs? (OSRAM RGBW)", multiple:true, required: true
input "brightnessLevel", "number", title: "Brightness Level (1-100)?", required:false, defaultValue:100 //Select brightness
input "randomHue", "bool", title: "Randomize Starting Hue?", required: true, defaultValue: false
}
section( "Enabled/Disabled" ) {
input "enabled","bool", title: "Enabled?", required: true, defaultValue: true
input "pulseEnabled","bool", title: "Pulse Enabled?", required: true, defaultValue: false
input "blinkEnabled","bool", title: "Blink Enabled?", required: true, defaultValue: false
input "loopEnabled","bool", title: "Loop Enabled?", required: true, defaultValue: true
input "resettowhite", "bool", title: "Reset to white on disable", required: true, defaultValue: false
input "enableswitch", "capability.switch", title: "Optional: Do you have a switch/virtual switch which the application enable/disable functionality should follow? If you do not want this feature leave blank.", multiple:false, required: false
}
}
def hues = []
def installed() {
unsubscribe()
unschedule()
if (settings.enabled == true)
{
initialize()
}
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
unschedule()
if (settings.enabled == true && hues && enabled)
{
initialize()
}
else if(hues)
{
TurnOff()
}
if (enableswitch && hues)
{
subscribe(enableswitch,"switch",EnableSwitchHandler)
}
}
def initialize() {
subscribe(hues, "switch.on", changeHandler)
// TODO: subscribe to attributes, devices, locations, etc.
if(enabledSwitch) {
def switchstatus = enabledSwitch.currentValue("switch")
log.debug "current switch: $switchstatus"
if(switchstatus == "on") {
TurnOn()
}
else
{
turnOff()
}
}
else
{
TurnOn()
}
// do event listening on switch whether enabled or not
}
def changeHandler(evt) {
if(settings.enabled == true && enabled)
{
TurnOn()
}
else
{
TurnOff()
}
}
def TurnOff()
{
log.debug "Turning off osram settings"
if(pulseEnabled)
{
hues.pulseOff()
}
if(loopEnabled)
{
hues.loopOff()
}
if(blinkEnabled)
{
hues.blinkOff()
}
if(resettowhite) {
hues.temp3000()
}
}
def TurnOn()
{
log.debug "turning on osram settings"
hues.on()
hues.setLevel(brightnessLevel)
if(randomHue) {
hues.each { hue ->
hue.setHue360(Math.abs(new Random().nextInt() % 360))
}
} else {
hues.setHue360(0)
}
if(pulseEnabled)
{
hues.pulseOn()
}
else
{
hues.pulseOff()
}
if(loopEnabled)
{
hues.loopOn()
}
else
{
hues.loopOff()
}
if(blinkEnabled)
{
hues.blinkOn()
}
else
{
hues.blinkOff()
}
}
// TODO: implement event handlers
def EnableSwitchHandler(evt)
{
log.debug "In Switch Handler: Switch changed state to: ${evt.value}"
if (evt.value == "on")
{
log.debug "Enabling OSRAM App!"
settings.enabled = true
updated()
// updated turns off so need to turn back on when switch tripped.. but also need to renable scheduling.
TurnOn()
}
else
{
log.debug "Disabling OSRAM App!"
settings.enabled = false
updated()
TurnOff()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment