Help with SmartApp when selecting multiple bulbs

Can anyone see what is wrong with this SmartApp? I’m getting weird results from the IDE. I swear this worked the first time but now I get a real long cryptic error. So I don’t know if my code is bad or there is a problem in the cloud.

Here is the SmartApp’s preference section. I’m trying to control the color of multiple bulbs based on the status of my door. It works if I control one bulb but wont even load if I change multiple to true.

preferences {
section(“When the door opens/closese…”) {
input “doorSensor”, “capability.doorControl”, title: “Select CoopBoss”, required: true, multiple: false
input “bulb”, “capability.colorControl”, title: “pick a bulb”, required: true, multiple: true
}
}

The error occurs with I have the input “bulb” line set to multiple: true instead of false.

Here is the bulb handler. At the end I just set the bulb’s color with the command:

bulb.setHue(hueColor)

Since there are multiple bulbs selected do I need to walk through some type of an array of bulbs? Whats blowing me away is this all worked just fine.

def doorStateHandler(evt) {
log.debug “${evt.descriptionText}, $evt.value”
def color = “White”
def hueColor = 100
def saturation = 100

switch(evt.value) {
case “open”:
color = “Blue”
break;
case “opening”:
color = “Purple”
break;
case “closed”:
color = “Green”
break;
case “closing”:
color = “Pink”
break;
case “jammed”:
color = “Red”
break;
case “forced close”:
color = “Orange”
break;
case “unknown”:
color = “White”
break;
}

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;
}

bulb.on()  // Turn the bulb on when open (this method does not come directly from the colorControl capability)
//bulb.setLevel(100)  // Make sure the light brightness is 100%       
bulb.setHue(hueColor)

bulb.setSaturation(saturation)
}

Your bulb input is a collection in case of multiple:true. So, treat it as such,

bulb.each {
**it.**on()
blah…blah…
}

3 Likes

@smart
Ron, thanks for the quick response! That did the trick working like a champ now.

Hey, thanks for not jumping on me I know I really showed my lack of experience with JAVA on this one! Hanging my head a little low.

bulb.each{
	it.on()  // Turn the bulb on when open (this method does not come directly from the colorControl capability)
	//it.setLevel(100)  // Make sure the light brightness is 100%       
	it.setHue(hueColor)
  it.setSaturation(saturation) 
    }

}

I am not a Java person. :slight_smile: Totally Microsoft background and for the past few years “JavaScript”. :slight_smile:

1 Like

Microsoft C# is where I have done most of my hacking around and a little JavaScript. Thanks again!!

@JohnR don’t suppose you have the exception you got still that you could post?

You certainly can iterate over the collection and issue commands to each device, but you should be able to send commands to the collection of devices.

http://docs.smartthings.com/en/latest/smartapp-developers-guide/devices.html#interacting-with-multiple-devices

If there’s some error happening in your case related to this, we should take a look…

That said - glad you got it working!

2 Likes

Ahh that explains why it worked once or twice. Let me see if I can reproduce it.

Thanks

The spread operator (is it what it is called?) should work as well…

bulb*.on()

Typing without my glasses. The special character is the asterisk sign.

1 Like

Here is the error I was getting

grails.validation.ValidationException: Validation Error(s) occurred during save():

  • Field error in object ‘physicalgraph.device.Device’ on field ‘name’: rejected value [null]; codes > [physicalgraph.device.Device.name.nullable.error.physicalgraph.device.Device.name,physicalgraph.device.Device.name.nullable.error.name,physicalgraph.device.Device.name.nullable.error.java.lang.String,physicalgraph.device.Device.name.nullable.error,device.name.nullable.error.physicalgraph.device.Device.name,device.name.nullable.error.name,device.name.nullable.error.java.lang.String,device.name.nullable.error,physicalgraph.device.Device.name.nullable.physicalgraph.device.Device.name,physicalgraph.device.Device.name.nullable.name,physicalgraph.device.Device.name.nullable.java.lang.String,physicalgraph.device.Device.name.nullable,device.name.nullable.physicalgraph.device.Device.name,device.name.nullable.name,device.name.nullable.java.lang.String,device.name.nullable,nullable.physicalgraph.device.Device.name,nullable.name,nullable.java.lang.String,nullable]; arguments [name,class physicalgraph.device.Device]; default message [{0} cannot be null]

With this syntax:

bulb*.on()  // Turn the bulb on when open (this method does not come directly from the colorControl capability)      
bulb*.setHue(hueColor)
bulb*.setSaturation(saturation)

Now I get that same error even if I put the code back to what worked before as Ron suggested:

bulb.each{
it.on()
etc…

Seems like the server gets into some type of an error state and it takes awhile to clear. I did the logout close all browsers and log back in and still got the same error on code that was working great!! I bet if I wait a little longer it will work again.

Threw this in pretty quickly and it works… Let me check the other option and i am sure it will work too…(just confirmed that the first way works too and double checked via Hue stock app).

Have you checked what the hueColor and saturation values are in there? May be something funky in there. Never used setHue or setSaturation.

or may be try this syntax:

def newValue = [hue: hueColor, saturation: saturation, level: lightLevel as Integer ?: 100]
hues*.setColor(newValue)

/*
 *  Test Monitor
 *
 *  Copyright 2015 Ron Sarkar
 *
 *  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: "Test Monitor",
    namespace: "rsarkar",
    author: "Ron S",
    description: "Test Monitor.",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")

preferences {
        section("bulbs...") {
        	input "bulbs", "capability.colorControl", title: "Select hues.", required: false, multiple: true
        }
        
         section("Check these doors/locks when Everybody is Away..."){
            input "doors", "capability.contactSensor", title: "Which Doors?", required:false, multiple: true
        }
}

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

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

def initialize() {
    log.debug( "Inializing" )   
    subscribe(doors, "contact", doorEventHandler)
}

def doorEventHandler(evt) {
    def msg = "$evt.displayName is $evt.value"
    	switch(evt.value) {
            case "open":
                bulbs*.on();
                break;
            case "closed":
                bulbs*.off();
                break;
        }   
 }

Ron, I got all working again well in the real world anyway. Both your suggestions work.

No matter what I do I get that error I pasted above in the SmartThings emulator but if I go to the physical device on my iPhone everything works great. I can open and close the door and 6 Hue bulbs all change color as expected. Thanks for the help.

I just spent about 3 hours reproducing that error on request. Hope they do something with it.

Thanks again for your help.

1 Like

Always welcome and please sign up to my “hue integration whiners group”! :wink:

1 Like

I’d happily join the Hue Integration Whiners group. As a non-programmer here, I wish, pray, curse, poke pins in voodoo dolls, sacrifice goats, and yes, whine about this all the time. The one thing I’d change (if given magic powers which only affect SmartThings) would be allowing SmartThings to access/use Hue Scenes. I’ve converted my entire house to Hue lights (except for bulbs sizes/types not provided by Hue yet). I’ve spent a lot of time setting up scenes. Bright turns on all the lights everywhere at their brightest levels in white white. Relax turns off a bunch of lights, warms colors of most of the remaining lights, and sets a few “accent” colors here and there. Good night turns off most lights but leaves a nice dim path to the bedroom. And it goes on and on. I have scenes for holidays, game days, and even an all-pink scene for when my god daughter visits (pink was her choice - I’m not foisting sexists stereotypes on her). I keep adding lights (I’ve just put in strips above the kitchen cabinets). Sometimes I just want a change here and there. That means I’m constantly fiddling with the scenes. That’s okay though because it’s easy to do in Hue. I can’t imagine having to go to the IDE and changing code for multiple SmartApps because I want to change the color of one bulb in a scene that I frequently use.

Wouldn’t it be great if your favorite scene came on when the front door unlocked or you arrived home? How about if the “goodnight” scene came on when you say “Goodnight Home?” Without this integration, my Hue/SmartThings use is limited to THREE bulbs that come on when motion or open/close sensors activate. Three bulbs out of 30.

Where do I sign up for that whiners group again? :blush:

2 Likes

Love that… :slight_smile: I literally bang my head on the wall… but then realize we have already hit against the brick wall but with a tiny hope that we may somehow break down the wall!

1 Like