Make it So --> Hue Colors


#1

Hi All:

Been searching, but can’t seem to find an answer to this problem:

I use the “Make It So” smart app to change light dimming settings. I’ve just received two hues and I can’t get that “Make It So” smartapp to save the color state as well as the dimmed state. Does anyone know I could modify the code of the existing “Make It So” app to make this work?

Any thoughts/help would be appreciated!

Thanks


CoRE and Piston Rules Engine, first design steps
CoRE and Piston Rules Engine, first design steps
(Craig) #2

@dschreib - Here’s a snipit from my of my apps that I use to set the colors on my Hue. It might be exactly what you are looking for but it might help you get it done. If you need to I can send you the enum preference code that is used during app install.

    def hueColor = 70
	def saturation = 100

	switch(color) {
			case "White":
				hueColor = 52
				saturation = 19
				break;
			case "Daylight":
				hueColor = 53
				saturation = 91
				break;
			case "Soft White":
				hueColor = 23
				saturation = 56
				break;
			case "Warm White":
				hueColor = 20
				saturation = 80 //83
				break;
	 	 	case "Blue":
				hueColor = 70
				break;
			case "Green":
				hueColor = 39
				break;
			case "Yellow":
				hueColor = 25
				break;
			case "Orange":
				hueColor = 10
				break;
			case "Purple":
				hueColor = 75
				break;
			case "Pink":
				hueColor = 83
				break;
			case "Red":
				hueColor = 100
				break;
	}

	if (color != "On - Custom Color")
    {
        def newValue = [hue: hueColor, saturation: saturation, level: lightLevel as Integer ?: 100]
        hues*.setColor(newValue)
		log.debug "new value = $newValue"
    }
    else
    {
    	hues*.on()
    }

(Michael Langkilde) #3

Hey @craig Can you send me your code for that, please? Thanks


(Craig) #4

Here’s my complete code. This is for a hue night light.

/**
 *  Bedroom Night Lights
 *
 *  Copyright 2014 Craig Lyons
 *
 *  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: "Bedroom Night Lights",
    namespace: "",
    author: "Craig Lyons",
    description: "Used to control the bedroom nightlights.",
    category: "My Apps",
    iconUrl: "http://www.philips.co.jp/shared/assets/jp/SmallParagraphImage/ConsumerCare/hue_80x70.jpg",
    iconX2Url: "http://www.philips.co.jp/shared/assets/jp/SmallParagraphImage/ConsumerCare/hue_80x70.jpg",
    iconX3Url: "http://www.philips.co.jp/shared/assets/jp/SmallParagraphImage/ConsumerCare/hue_80x70.jpg")


preferences {
	section("Control these bulbs...") {
			input "hues", "capability.colorControl", title: "Which Hue Bulbs?", required:true, multiple:true
		}
		section("Choose light effects...")
			{
				input "color", "enum", title: "Hue Color?", required: false, multiple:false, options: [
					"On - Custom Color",
                    "Soft White",
					"White",
					"Daylight",
					"Warm White",
					"Red","Green","Blue","Yellow","Orange","Purple","Pink"]
				input "lightLevel", "enum", title: "Light Level?", required: true, options: ["10","20","30","40","50","60","70","80","90","100"]
			}
    
    section("Motion") {
		input "motionDectors", "capability.motionSensor", title: "Motion"
	}
}

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

	initialize()
}

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

	unsubscribe()
	initialize()
}

def initialize() {
	subscribe(motionDectors, "motion", motionHandler)
}

def motionHandler(evt)
{
log.trace "evt: ${evt}"
if (evt.value == "active")
{
	log.trace "active"
    
    def hueColor = 70
	def saturation = 100

	switch(color) {
			case "White":
				hueColor = 52
				saturation = 19
				break;
			case "Daylight":
				hueColor = 53
				saturation = 91
				break;
			case "Soft White":
				hueColor = 23
				saturation = 56
				break;
			case "Warm White":
				hueColor = 20
				saturation = 80 //83
				break;
	 	 	case "Blue":
				hueColor = 70
				break;
			case "Green":
				hueColor = 39
				break;
			case "Yellow":
				hueColor = 25
				break;
			case "Orange":
				hueColor = 10
				break;
			case "Purple":
				hueColor = 75
				break;
			case "Pink":
				hueColor = 83
				break;
			case "Red":
				hueColor = 100
				break;
	}

	if (color != "On - Custom Color")
    {
        def newValue = [hue: hueColor, saturation: saturation, level: lightLevel as Integer ?: 100]
        hues*.setColor(newValue)
		log.debug "new value = $newValue"
    }
    else
    {
    	hues*.on()
    }

	state.motionStoppedAt = -99    
}
else if (evt.value == "inactive")
{
	log.trace "inactive"
    //runIn(60, turnOfflights)
    state.motionStoppedAt = now()
    turnOfflights()
}

}

def turnOfflights() {
	
    def elapsed = now() - state.motionStoppedAt
    def threshold = (60000 * 5) 
    
    log.trace "elapsed: ${elapsed}"
    log.trace "threshold: ${threshold}"
    
    if (elapsed >= threshold && state.motionStoppedAt != -99)
    {
    	hues*.off()
    }
    else 
    {
    	runIn(60, turnOfflights)
    }
}

(Joseph Fattizzi) #5

This is perfect. Is there anyway to have an option to shut the light off after xx minutes of inactivity?


(Craig) #6

@Joseph_Fattizzi - This is a bug, right now it’s 5 minutes since change. My plan is to correct this sometime this week. I’ll post an update here once I do.


(Joseph Fattizzi) #7

It would be good if you had an option to ask how many minutes after inactivity to shut the lights. There is something similar in a SmartApp called Scene Control, but I dont know how to integrate it into your code.


(Craig) #8

@Joseph_Fattizzi

Yeah - Right now it’s hard coded for 5 minutes (because that’s what I needed and I took the lazy way out.) I’m wrestling with a new born baby but I should be able to get an update sometime this week with a variable instead of it being hard coded.


(Joseph Fattizzi) #9

Congrats on the new baby. I have a 16 month old and know the feeling!

Look forward to seeing your new code.

For now I changed it in the code.

Would you be able to add an option to run during certain times as well?


(Craig) #10

Here’s the update with the delay not hard coded. The time is a little harder to implement and I don’t have time to QA that sort of change (since I’m actively using this program through out my house). In the future I can look to do that but you are free to change this code anyway you’d like to add that functionality into it.

/**
 *  Bedroom Night Lights
 *
 *  Copyright 2014 Craig Lyons
 *
 *  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: "Bedroom Night Lights",
    namespace: "",
    author: "Craig Lyons",
    description: "Used to control the bedroom nightlights.",
    category: "My Apps",
    iconUrl: "http://www.philips.co.jp/shared/assets/jp/SmallParagraphImage/ConsumerCare/hue_80x70.jpg",
    iconX2Url: "http://www.philips.co.jp/shared/assets/jp/SmallParagraphImage/ConsumerCare/hue_80x70.jpg",
    iconX3Url: "http://www.philips.co.jp/shared/assets/jp/SmallParagraphImage/ConsumerCare/hue_80x70.jpg")


preferences {
	section("Control these bulbs...") {
			input "hues", "capability.colorControl", title: "Which Hue Bulbs?", required:true, multiple:true
		}
	section("Choose light effects...")
			{
				input "color", "enum", title: "Hue Color?", required: false, multiple:false, options: [
					"On - Custom Color",
                    "Soft White",
					"White",
					"Daylight",
					"Warm White",
					"Red","Green","Blue","Yellow","Orange","Purple","Pink"]
				input "lightLevel", "enum", title: "Light Level?", required: true, options: ["10","20","30","40","50","60","70","80","90","100"]
			}
    
    section("Choose Motion Sensors...") {
		input "motionDectors", "capability.motionSensor", title: "Motion"
	}
    
    section("Delay...") {
		input "offDelay", "number", title: "How many minutes after motion stops until lights turn off"
	}
}

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

	initialize()
}

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

	unsubscribe()
	initialize()
}

def initialize() {
	subscribe(motionDectors, "motion", motionHandler)
}

def motionHandler(evt)
{
log.trace "evt: ${evt}"
if (evt.value == "active")
{
	log.trace "active"
    
    def hueColor = 70
	def saturation = 100

	switch(color) {
			case "White":
				hueColor = 52
				saturation = 19
				break;
			case "Daylight":
				hueColor = 53
				saturation = 91
				break;
			case "Soft White":
				hueColor = 23
				saturation = 56
				break;
			case "Warm White":
				hueColor = 20
				saturation = 80 //83
				break;
	 	 	case "Blue":
				hueColor = 70
				break;
			case "Green":
				hueColor = 39
				break;
			case "Yellow":
				hueColor = 25
				break;
			case "Orange":
				hueColor = 10
				break;
			case "Purple":
				hueColor = 75
				break;
			case "Pink":
				hueColor = 83
				break;
			case "Red":
				hueColor = 100
				break;
	}

	if (color != "On - Custom Color")
    {
        def newValue = [hue: hueColor, saturation: saturation, level: lightLevel as Integer ?: 100]
        hues*.setColor(newValue)
		log.debug "new value = $newValue"
    }
    else
    {
    	hues*.on()
    }

	state.motionStoppedAt = -99    
}
else if (evt.value == "inactive")
{
	log.trace "inactive"
    //runIn(60, turnOfflights)
    state.motionStoppedAt = now()
    turnOfflights()
}

}

def turnOfflights() {
	
    def elapsed = now() - state.motionStoppedAt
    def threshold = (60000 * offDelay) 
    
    log.trace "elapsed: ${elapsed}"
    log.trace "threshold: ${threshold}"
    
    if (elapsed >= threshold && state.motionStoppedAt != -99)
    {
    	hues*.off()
    }
    else 
    {
    	runIn(60, turnOfflights)
    }
}

(Tony - SmartThings Unpublished Contributor ) #11

Here’s another option for setting scenes for groups of Hue lights, dimmers, and/or switches:

My code also allows the user to turn lights off after “X” minutes of no motion.


(Joseph Fattizzi) #12

Thank You. Works Great!

Let me ask one more thing…is there any way to set a specific color of my HUE lights? I can edit your code and instead of it saying Hue Color - Blue or Soft White, can I set my own color by getting the RGB code or #xxxxxx code of the color I want?


(Tony - SmartThings Unpublished Contributor ) #13

Joseph-

Glad to hear it works for you.

I don’t believe that ST has the capability to set colors by RGB codes. As far as I’m aware, the ST hub can control 3 variables for the Hue lights: “hue”, “saturation”, and “level” – each of which can be set from 1 to 100. The color of your lights will be controlled by the value of the “hue” variable (and the value of the “saturation” variable for the various “white” colors, such as soft white, daylight, etc).

My apps use set values of hue & saturation for each color. For example, hue = 70 for Blue, hue = 100 for red, etc.

My advice is just to play around with the color wheel for any particular light until you get the color you want. Then check the activity feed to see the values of hue/sat/level. You can then edit the values in my code to match those.

Hope this helps.

Tony


#14

Thanks so much for posting this code and the tutorial and sorry for the delay in my response – it’s been a busy week!

Unfortunately, I’ve been having some problems getting this set up. I don’t need to turn off the lights after a period of time, so I was messing around with the code to remove that option. I must have screwed something up and now I’m unable to save the “Scene Control” smartapp. Is there an easy way to remove that part of the code so that I can trigger the hue color and light on/off states with a switch?

I feel like this code is getting me so close to how I want to use ST, so I’m super excited. Thanks again!


(Joseph Fattizzi) #15

I too didn’t have a need to turn off the lights after no motion. I just put the time in as 9999 which means it will never go off if no ,option is detected


(Tony - SmartThings Unpublished Contributor ) #16

DSchreib-

Thanks for the positive feedback! And I know how you feel – getting ST to do this made me super excited as well.

If you don’t need to turn the lights off after a period of no motion, just make one small change of the code (around line 58):

FROM: subscribe(motions, “motion”, motionHandler)

TO: subscribe(motions, “motion.active”, motionHandler)

This change will cause the app to completely ignore no motion events, so that part of the code will never get called.

Are you talking about a virtual switch or a physical one? Remember that if you turn off the physical switch, the hue lights will revert back to their default state (and therefore “forget” the color/level settings you want.

-Tony


(Craig) #17

@Joseph_Fattizzi if you are using my program the “custom” setting just turns the light on based on the last color that the light was set to. I use this to allow myself to pick the color via the color wheel and still use the program.


(Joseph Fattizzi) #18

I was able to get the Hue and Saturation of the lights once I set them and then I updated your code to add a “Custom Color” section in the ‘case’ section. Now I just select the custom color and my scenes have custom colors


(Joel) #20

hopefully someone will release a lifx version of this app :slight_smile: nice work!