How To: Set Custom Color and Brightness of Hue Bulbs


(Joseph Fattizzi) #1

Does anyone know how to set and recall custom colors and brightness levels for a hue bulb or set of hue bulbs?


(Justin) #2

I started a thread on this. https://community.smartthings.com/t/random-hue-color-within-a-smart-app/18528/5 Sorry for the crude pasting but I’m on a tablet.

Anyway… there are various methods to control lights (ie. switch.on() or switch.off() ). For Hue bulbs you have to change the capability of your device from a switch to capability.colorcontrol.

Then you can define a color simply by setting hue, sat and level

Continuing the discussion from Random Hue Color within a smart app:

Ok. I made some changes to my overall app which is simple. I will test in real life, but in the simulation it appears not to change color. My concern is that this is device related NOT my program.

I have the OSRAM 73661 Smart Connected Lighting LED Flexible Strip. The device is installed properly and I can change colors directly by using the device within ST.

Here is my code:

/**
 *  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.
 *
 *  Turn It On When It Opens
 *
 *  Author: SmartThings
 */
definition(
    name: "Matthew's Under Bed Light",
    namespace: "JDogg",
    author: "JDogg",
    description: "Turn something on when an open/close sensor opens.",
    category: "Convenience",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet@2x.png"
)

preferences {
	section("When the door opens..."){
		input "contact1", "capability.contactSensor", title: "Where?"
	}
	section("Turn on a light..."){
		input "switches", "capability.colorControl", multiple: false
	}
}


def init()
{
	subscribe(contact1, "contact.open", contactOpenHandler)
    subscribe(contact1, "contact.closed", contactClosedHandler)

}

def updated()
{
	unsubscribe()
	subscribe(contact1, "contact.open", contactOpenHandler)
    subscribe(contact1, "contact.closed", contactClosedHandler)
}

def contactOpenHandler(evt) {
	log.debug "$evt.value: $evt, $settings"
	log.trace "Turning on switches: $switches"
	//Get Random Number
	def ranNum = new Random().nextInt(65000) + 1
    def ranSat = new Random().nextInt(99) + 1
	log.debug "Color is $ranNum and Saturation is $ranSat"
    switches.setLevel(99)
	switches.setSaturation(ranSat)
	switches.setHue(ranNum)
    switches.on()
}

def contactClosedHandler(evt) {
	log.debug "$evt.value: $evt, $settings"
    log.trace "Turning off switches: $switches"
    switches.off([delay: 300 * 1000])
    }