Hue Bug? (frustrated once again)


(Convinced ST will never be unbroken…) #1

This is either a bug in my code or Hue in general (or something wrong with SmartThings).

Wrote the following app to select a hue randomly from a supplied list. Seems pretty simple, and values ARE updated in the sim. But as soon as I run it without the sim monitoring it, the lamps only come up in red (even if red is not in the random hues list), and subsequent ‘ons’ do nothing.

What have I missed?

definition(
    name: "Random Color Switch",
    namespace: "soletc.com",
    author: "Scottin Pollock",
    description: "When a switch is pressed, turns on Hues to Random color.",
    category: "My Apps",
    iconUrl: "http://solutionsetcetera.com/stuff/STIcons/HueLogo.png",
    iconX2Url: "http://solutionsetcetera.com/stuff/STIcons/HueLogo@2x.png")


preferences {
	section("When the following is turned on and off...") {
		input name: "master", title: "Which Switch?", type: "capability.switch", required: true
	}
    section("Turn on or off all of these Hues") {
			input "hues", "capability.colorControl", title: "Which Hue Bulbs?", required:false, multiple:true
			input "saturation", "number", title: "Saturation (0-255)", required: false, multiple:false
			input "lightLevel", "number", title: "Brightness (0-255)", required: false, multiple:false
   			input "RCVs", "text", title: "Random Hues (0-65535)", required: false, multiple:false
	}
}

def installed() {
	subscribeToEvents()
}

def updated() {
	unsubscribe()
	subscribeToEvents()
}

def subscribeToEvents() {
	subscribe(master, "switch.on", onHandler, [filterEvents: false])
	subscribe(master, "switch.off", offHandler, [filterEvents: false])
}

def onHandler(evt) {
    doHUE()
}

def offHandler(evt) {
    hues.off()
}

def doHUE() {
	def saturationInt = saturation / 255 * 100 as Integer
	def lightLevelInt = lightLevel / 255 * 100 as Integer
    def theHUE = randomHUE() as Integer
    log.debug theHUE
	def colorInt = theHUE / 65535 * 100 as Integer
	log.debug "${colorInt} ${saturationInt} ${lightLevelInt}"
	def hueSETTINGS = [hue: colorInt, saturation: saturationInt, level: lightLevelInt]
	log.debug hueSETTINGS
	hues*.setColor(hueSETTINGS)
}

def randomHUE() {
	def result = RCVs[new Random().nextInt(RCVs.size())]
}

(Tim Slagle) #2

You’ll need to randomize the saturation too. I believe that had a lot to do with the color output.

No hue bug here. I have no problem hard coding hue colors into my apps so I’m guessing it’s your randomization code.


(Convinced ST will never be unbroken…) #3

It’s one line of code. Plus, as I mentioned, it works fine in the sim.


(Tim Slagle) #4

Doesn’t work in the IDE for me. It’s your code. Just tested it in the IDE and the mobile app and you are correct it always turns red. No matter what. Take a look at your code again and you should be good :smile:

This is my results from the IDE logs:

4cd6a69d-96d8-47d8-a226-130d13161ac4 8:58:07 AM: debug [hue:0, saturation:31, level:31]
4cd6a69d-96d8-47d8-a226-130d13161ac4 8:58:07 AM: debug 0 31 31
4cd6a69d-96d8-47d8-a226-130d13161ac4 8:58:07 AM: debug 0
4cd6a69d-96d8-47d8-a226-130d13161ac4 8:58:06 AM: debug [hue:0, saturation:31, level:31]
4cd6a69d-96d8-47d8-a226-130d13161ac4 8:58:06 AM: debug 0 31 31
4cd6a69d-96d8-47d8-a226-130d13161ac4 8:58:06 AM: debug 0
4cd6a69d-96d8-47d8-a226-130d13161ac4 8:58:03 AM: debug [hue:0, saturation:31, level:31]
4cd6a69d-96d8-47d8-a226-130d13161ac4 8:58:03 AM: debug 0 31 31
4cd6a69d-96d8-47d8-a226-130d13161ac4 8:58:03 AM: debug 5
4cd6a69d-96d8-47d8-a226-130d13161ac4 8:57:59 AM: debug [hue:0, saturation:31, level:31]
4cd6a69d-96d8-47d8-a226-130d13161ac4 8:57:59 AM: debug 0 31 31
4cd6a69d-96d8-47d8-a226-130d13161ac4 8:57:59 AM: debug 5

(Convinced ST will never be unbroken…) #5

Still looks like a bug to me:

In the sim, RCVs is returned as [“10000”,“15000”,“30000”]
and RCVs.size() returns 3

But outside the sim RCVs is returned as 10000,15000,30000
and RCVs.size() returns 17

Makes it kinda tough to code this way. Which one is correct? And if it is the latter, how do I return an input in the form of a list (as in the former)?


Web-Based IDE Improvements
(Tim Slagle) #6

Looks like you have a little investigating to do :smile:

Support can be a great resource


(Convinced ST will never be unbroken…) #7

Emailed them right after my first post. (c;


(Tim Slagle) #8

I’d be interested to know what your using this for. :slight_smile: Love to hear people’s uses for things.


(Convinced ST will never be unbroken…) #9

We have a variety of scenes for a given room (hotBath, warmBath, coolBath, etc.). I am currently using HAM Bridge to rotate those scenes via ON presses at wall mounted CA5100s.

It occurred to us that it might be nice to introduce some randomness to this, and I just figured this time around we could enter/change the possible values directly into a SmartApp instead of creating a bunch of scene scripts in HAM Bridge and calling them rotationally/randomly. I really didn’t think it would be this big a PITA.

But now that I’m into it, it seems a fair exercise to discover how to treat user input as a list/array and rotate/randomize through items entered into an input field, thus giving one switch the ability to do many things depending on how many times it is pressed.


(Tim Slagle) #10

thats pretty cool :smile:


(Ben Boggess) #11

@scottinpollock Although I’d expect things to be consistent, you should be able to work around it with something like this, until the issue is resolved:

if (RCVs instanceof String) {
    // sim returns a String for some reason
    RCVs = RCVs.tokenize(',') // splits into a list with comma as delimeter
}

(Convinced ST will never be unbroken…) #12

Thanks @boggess… I’ll give this a try when I revisit this.