Controlling Bulb Color with Remote Buttons


(Jim W) #1

I was surprised at the lack of color support integrated into the ST base software/apps. I have multiple Aeon minimotes to control various functions of the house, but I couldn’t change bulb colors. After various searches I found two threads with people asking about this, but no solutions. So today I took the Hue mood app and tweaked it to be specific for button remotes. It’s working for any button, both pushed and held, plus it works for any color bulbs. I have it working with my LIFX bulbs!

Anyways, here is the code in case anyone else comes along searching for something like this. This is my first app (and first post), so please feel free to critique the code or provide suggestions, this won’t be my last app and I’m happy to learn from the experience of others!

 *  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:
 *  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.
 *  Change Bulb Color With Button Remote
 *  Author: Jim W
 *  *
 *  Date: 2015-08-03
import groovy.json.JsonSlurper
    name: "Change Bulb Color With Button Remote",
    namespace: "noname4444",
    author: "Jim Worley",
    description: "Choose a button and button action (press or hold) to set a number of lights to any color/brightness.",
    category: "My Apps",
    iconUrl: "",
    iconX2Url: ""

preferences {
	section("Select the button/remote...") {
		input "button1", "capability.button", title: "Button Press", required:false, multiple:false
    section("Choose button and press type..."){
      input "buttonNumber","enum",title: "Button Number (defaults to 1)",required:false,
        options: ["1","2","3","4"]
      input "buttonAction","enum",title: "Button Action (defaults to 'Push')",required:false,
        options: [["pushed":"Push"],["held":"Hold"]]
    section("Control these bulbs...") {
			input "hues", "capability.colorControl", title: "Which Color Bulbs?", required:true, multiple:true
    section("Choose light effects...")
        input "color", "enum", title: "Hue Color?", required: false, multiple:false, options: [
            ["Soft White":"Soft White - Default"],
            ["White":"White - Concentrate"],
            ["Daylight":"Daylight - Energize"],
            ["Warm White":"Warm White - Relax"],
        input "lightLevel", "enum", title: "Light Level?", required: false, options: [[10:"10%"],[20:"20%"],[30:"30%"],[40:"40%"],[50:"50%"],[60:"60%"],[70:"70%"],[80:"80%"],[90:"90%"],[100:"100%"]]
    section("More options", hideable: true, hidden: false) {
        input "modes", "mode", title: "Only when mode is", multiple: true, required: false


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

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

def subscribeToEvents() {
    subscribe(app, appTouchHandler)
	subscribe(button1, "button", eventHandler)

def eventHandler(evt) {
	log.trace "Executing Mood Lighting"
    def btnNum = buttonNumber as Integer ?: 1
    def btnAct = buttonAction ?: "pushed"
    def slurper = new JsonSlurper().parseText(
    def inButtonNumber = slurper.buttonNumber
    def inValue = evt.value

    //log.debug "Install button: ${btnNum} and Installed action: ${btnAct}"
    log.debug "Found button: $inButtonNumber and found action: $inValue"
	if (modeOk && inButtonNumber == btnNum && inValue == btnAct) {
		log.trace "ModeOk"
    else {
        log.debug "Not taking action because we are not in an approved mode or wrong button press"

def appTouchHandler(evt) {

private takeAction(evt) {
	def hueColor = 0
	def saturation = 100

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

	state.previous = [:]

	hues.each {
		state.previous[] = [
			"switch": it.currentValue("switch"),
			"level" : it.currentValue("level"),
			"hue": it.currentValue("hue"),
			"saturation": it.currentValue("saturation")

	log.debug "current values = $state.previous"

	def newValue = [hue: hueColor, saturation: saturation, level: lightLevel as Integer ?: 100]
	log.debug "new value = $newValue"


private getModeOk() {
	def result = !modes || modes.contains(location.mode)
	log.trace "modeOk = $result"

(Justin) #2

AWESOME JOB! (20 characters)

(Mark Whipp) #3

That is exactly what I was looking for! It works too, thanks @noname4444 for your work and sharing. This helps make the transition from scenes and Pico world to the Minimote workable.

Glad you made this your first post and look forward to your other SmartApps in the future. BTW- My first post too!


Hi, I have been using this for months and loving it but yesterday, the color of the Phillips Hue lights are wrong. Instead of the warm white I was expecting, it turns with a greenish tint.

Live logging gave me this: Not taking action because we are not in an approved mode or wrong button press

Any idea?

Thank you.


The color bug is tracked here: Phantom Color Ghosts - Hue Just Went Bat Crazy


Thank you!