Philips Hue Apps to Change Colors

Are there any SmartApps out there to change or flash the Hue lights? I know I could use IFTTT, but I would like to do it with a smart app if that is possible.

Hello @Morgan,

I was able to use some of the suggestions from other Forum members to create the SmartApp below. Maybe it will help you get started? If you are looking for the HUE values, I found that SmartThings will give them to you in the “Activity” section after using the color selector in the “Things” view.

/**
 *  Office Lights
 *
 *  Author: Various SmartThings Forums
 */
preferences {
    section ("Control these lights…") {
        input "hueLights", "capability.switch", multiple: true
        input "brightness", "number", title: "Brightness: 1-99 (Default 99)", required: false
        input "hue", "number", title: "Hue: 1-99 (Default: 12)", required: false
        input "saturation", "number", title: "Saturation: 1-99 (Default: 15)", required: false
    }
}

def installed()
{
	subscribe(app, appTouch)
}

def updated()
{
	unsubscribe()
	subscribe(app, appTouch)
}

def appTouch(evt) {

    def brightness = brightness ?: 99
    def saturation = saturation ?: 15
    def hue = hue ?: 12
    
	log.debug "appTouch: $evt"
	hueLights.setLevel(brightness)
	hueLights.setSaturation(saturation)
	hueLights.setHue(hue)
	hueLights.on()
}

Hope this helps you!
Ben

I’m afraid I don’t understand how this works. I’ve built an app with it, no prob. I’ve specified which lights it can control, what values for them, etc.

But how do I invoke it?

@differentcomputers,

The SmartApp above works like the “Big Turn ON” app and changes the color of the lights whenever the app is touched in the SmartApps section. If you would like to tie the color change to other actions, you would need to add a sensor in the preferences section and then subscribe to it.

Something like this would work:

preferences {
     section("When mail arrives...") {
     input "contact1", "capability.contactSensor", title: "Where?"
     input "hueLights", "capability.switch", multiple: true
     }
}

def installed() {
	subscribe(contact1, "contact.open", contactOpenHandler)
}

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

def contactOpenHandler(evt) {
	log.trace "$evt.value: $evt, $settings"
	hueLights.setLevel(99)
	hueLights.setSaturation(99)
	hueLights.setHue(40)
	hueLights.on()
}

@urman, thanks for formatting my code above. Sorry I didn’t format it correctly!

Ok, I get it now. Kind of. But this is a completely manual switch as best I can figure–there’s no way to specify it as a thing to turn on or off when a mode changes, for example. Right?

So this doesn’t appear to be an actual virtual switch. Any way to make it so?

@differentcomputers,

Can you give me an idea of what you are trying to accomplish with your hue lights?

The code above calls a contact sensor as an input for “contact1.” Whenever that sensor opens, the contactOpenHandler event (evt) is called which changes the color of the lights.

When installing the app above, you could select any sensor that has the capability of “contactSensor”. In my case, this would be my Multi-Sense I have installed on a door.

If you have an actual switch that you are programming, you could try this:

preferences {
     section("When switch turns on...") {
     input "switch", "capability.switch", title: "Where?"
     input "hueLights", "capability.switch", multiple: true
     }
}

def installed() {
	subscribe(switch, "switch.on", switchOnHandler)
}

def updated() {
	unsubscribe()
	subscribe(switch, "switch.on", switchOnHandler)
}

def switchOnHandler(evt) {
	log.trace "$evt.value: $evt, $settings"
	hueLights.setLevel(99)
	hueLights.setSaturation(99)
	hueLights.setHue(40)
	hueLights.on()
}

Is that what you were asking?

If it was a virtual switch, I could:

  1. Control it via IFTTT
  2. have a mode change turn it on or off
  3. Have any sensor trigger it

So, for example (and the immediate use case I have in mind), when the system goes to Sleep mode, the Hue lights all go very dim and red, a night-vision-preserving state. When the system wakes the house up in the morning, the mode change turns the lights to a normal daytime color.

But also, by having this control available as a virtual switch, I would gain the flexibility to do almost anything with it!

Ahh, I see… I haven’t personally created virtual switches, so I wouldn’t be able to help you with that configuration. Your Hue Lights are switches, though. So, you should be able to accomplish what you want with simple SmartApps.

For instance, you can tell the switch (Hue Lights) to change colors/brightness when a Mode Change is detected. That way you could run a conditional checking for the mode, and then tell the switches to change color/brightness whenever the mode changes (Sleeping).

As far as IFTTT, your Hue Lights are also available in the IFTTT interface as SmartThings switches.

Sorry I couldn’t be more of a help on the virtual side of things!

Right on the IFTTT access to Hue. But there’s limited ability to use IFTTT to directly control the house because IFTTT can’t react to modes. (Though I am using IFTTT to control modes via a Virtual Switch.) Also, using IFTTT to change colors on Hue means that the Hue light comes on, at least for a moment. So if I want to change my lights from their late-night dim red to a normal warm yellow via IFTTT, I have to make them come on for at least a moment, which is kind of weird. I would much rather have the change command triggered normally, whenever some event in the house turns the lights on based on mode.

You say I can change colors/brightness when a mode changes. But how? Mode changes can directly address Things, but I don’t see any way to make a mode trigger an App. Sure, an App can be limited to a given mode, but that doesn’t mean it triggers.

Or maybe when you say “you can tell the switch” you mean “you can code your own smart app”?

Right now I’m stuck manually triggering the SmartApp to set my lights whenever it occurs to me.

Right, you would need to code a SmartApp that would tell the lights to come on and change colors when the mode changes. Check out this thread. It shows how to subscribe to the location/mode change and then have functions or Things react to that change in mode.

http://build.smartthings.com/forums/topic/mode-change-subscription-help/