How to retrieve current state level and switch of a Hue Group?

I have a hueBridgeGroup called Hall, for which I need to determine the current level and switch in an app. When I call currentState or currentValue, I get an error:

java.lang.IllegalArgumentException: Command 'currentState' is not support by device. on line 90 (pushedHandler)

java.lang.IllegalArgumentException: Command 'currentValue' is not support by device. on line 90 (pushedHandler)

What is the correct way to retrieve these values?


What value are you looking for?, that error generally means the requested attribute (value) is not part of the capabilities defined for the device.

I need to know if the Hue group is on or off (switch), and the dim level (level). In the screen print you can see that the device has level and switch, just need to know how to get hold of those values in an app.

Device.currentValue("switch") and device.currentValue("level")
Where device is the name of your single device input element

I did do device.currentValue("switch") and device.currentValue("level") (where device is the hue group from the preferences) and got the error. I am wondering if the Hue Group, as opposed to a Hue Bulb, doesn't support currentValue? Does the device driver implement currentValue? Everything else I do with the Hue Group works fine, I am just unable to extract the switch and level values.

I am not home right now but can post the code tonight, if that would be helpful.

Sure, that would help. When you look at a driver, the items listed under current states are the current values for each of the noted attributes, and in your screen shot this device has produced both switch and level events.
So the data is there, and there's probably a simple error in your app that's preventing this from working.

2 Likes

Here is the app:

/*
     *  Pico color temp bulb controller instance
     *  Button 1 presses:
     *  1: turn bulb(s) on (can have the bulb programmed to set color temp depending on time of day, when it is turned on)
     *  2: set bulb(s) to Nightlight 
     *  3: set bulb(s) to Relax
     *  4: set bulb(s) to Read
     *  5: set bulb(s) to Concentrate
     *  6: set bulb(s) to Energize
     *  7: back to Nightlight, etc
     */
    definition(name: "Pico Color Temp Bulb Controller Instance",
               namespace: "hubitat",
               author: "dagrider",
               description: "Cycle through bulb color temps with button 1, off with button 5, dim with buttons 2 and 4 (instance)",
               category: "Green Living",
               parent: "hubitat:Pico Color Temp Bulb Controller",
               iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo-switch.png",
               iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo-switch@2x.png")

    preferences {
        section {
            input "thePico", "capability.pushableButton", title: "Choose Pico Remote"
            input "theBulb", "capability.colorTemperature", title: "Choose bulb/group to control"
        }
    }

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

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

    def initialize() {
        log.debug "initialize"
        subscribe(thePico, "pushed", pushedHandler)
        state.pressNum = 0
    }

    def pushedHandler(evt) {
        switch(evt.value) { 
            case "1": 
                log.debug "button 1 pushed"
            
                if (state.pressNum == 0) {
                        log.debug "pressNum is 0, On"
                        theBulb.on()
                        state.pressNum = 1
                        sendEvent(name: "on", value: state.pressNum, descriptionText: "Turn bulb on")
                } else if (state.pressNum == 1) {
                        log.debug "pressNum is 1, Nightlight"
                        theBulb.setLevel(1)
                        theBulb.setColorTemperature(2257)
                        state.pressNum = 2
                        sendEvent(name: "on", value: state.pressNum, descriptionText: "Set bulb to Nightlight")
                } else if (state.pressNum == 2) {
                        log.debug "pressNum is 2, Relax"
                        theBulb.setColorTemperature(2237)
                        theBulb.setLevel(57)
                        state.pressNum = 3
                        sendEvent(name: "on", value: state.pressNum, descriptionText: "Set bulb to Relax")
                } else if (state.pressNum == 3) {
                        log.debug "pressNum is 3, Read"
                        theBulb.setColorTemperature(2915)
                        theBulb.setLevel(254)
                        state.pressNum = 4
                        sendEvent(name: "on", value: state.pressNum, descriptionText: "Set bulb to Read")
                } else if (state.pressNum == 4) {
                        log.debug "pressNum is 4, Concentrate"
                        theBulb.setColorTemperature(4348)
                        theBulb.setLevel(254)
                        state.pressNum = 5
                        sendEvent(name: "on", value: state.pressNum, descriptionText: "Set bulb to Concentrate")
                } else if (state.pressNum == 5) {
                        log.debug "pressNum is 5, Energize"
                        theBulb.setColorTemperature(6410)
                        theBulb.setLevel(254)
                        state.pressNum = 1
                        sendEvent(name: "on", value: state.pressNum, descriptionText: "Set bulb to Energize")
                }
            
                break;
            case "2": 
                log.debug "button 2 pushed"
                if (theBulb.currentState("switch") == "off") theBulb.on()
                def lvl = getLevel(1)
                theBulb.setLevel(lvl)
                sendEvent(name: "brighten", value: lvl, descriptionText: "Brighten bulb to $lvl")
                break;
            case "3": 
                // todo: center button
                break;
            case "4": 
                log.debug "button 4 pushed"
                def lvl = getLevel(0)
            
                if (lvl == 0) {
                    theBulb.off()
                    sendEvent(name: "dim", value: lvl, descriptionText: "Dim bulb to off")
                } else {
                    theBulb.setLevel(lvl)
                    sendEvent(name: "dim", value: lvl, descriptionText: "Dim bulb to $lvl")
                }
            
                break;
            case "5": 
                log.debug "button 5 pushed"
                theBulb.off()
                state.pressNum = 0
                sendEvent(name: "off", value: state.pressNum, descriptionText: "Turn bulb off")
                break;
            default:
                return
        }
    }

    private int getLevel(typ) {
        def lvl = theBulb.currentValue("level")
        log.debug "current bulb level: $lvl"
        
        if (typ == 1) lvl = lvl + 20
        else lvl = lvl - 20
            
        if (lvl > 100) lvl = 100
        
        if (lvl < 0) lvl = 0
        
        return lvl
    }

@denise.grider, I also had trouble porting over a few of my apps and made the following adjustments.

theBulb.currentValue("level")
to
theBulb.currentLevel

Using this template, I adjusted my other attributes to currentSwitch, currentLevel, etc
Hope this works for you as well.

1 Like

Thank you @stephack, will give that a try!

We do not support that many of these type convenience methods, your best bet is to stick with currentValue.

I agree...but currentValue does NOT work and currentLevel and currentSwitch do work...

Can you put this in as an issue?

1 Like

For those who might be interested...

This problem was due to the fact that originally in my app, I set theBulb multiple:true. I never did reload the app, so my Hall Hue Group was a list rather than a single device. Not sure why currentLevel and currentSwitch worked on both the list and the single device, but I have confirmed after reloading the apps, that currentValue does work.

Thanks @mike.maxwell for having me run tests to figure this out!

3 Likes

Just checked my code as well. There were still methods that had currentValue and worked fine...the areas that I had to change to currentLevel/currentSwitch were all lists. It's always the simple stuff that eludes me.
Thanks to you and Mike for digging in..I can add this to my ST vs HE spreadsheet :wink:

1 Like

Yeah, so heres the scoop.
CurrentValue("someAttribute") is the base method, the method currentSomeAttribute doesnt exist as a real method, we catch the fact that it doesnt exist, then parse currentSomeAttribute into CurrentValue("someAttribute"), so the short version is slightly more expensive to use.
The short method will work against lists (multiple:true) as well as single items, however it always returns a list as a result. The long version currently does not work against lists and returns an error.
We will update the long version to return a list as required.

3 Likes

And @mike.maxwell said the Pico controller app would not be difficult...he didn't know who he was dealing with! :laughing:

But seriously, it was a great learning experience for me. After reading what @mike.maxwell said, I recall that I had to extract the first value from a map at one point to get the value, but then later seemed like I didn't have to. I'm glad to know the ins and outs now.

1 Like