Hue devices - adding support for effect and alert attributes of bulbs

(John S) #1

Smartthings supports HUE integration by talking to the hue hub, but Hue supports two attributes on the bulb itself that Smartthings doesn’t expose

effect: “none”, “colorloop” - the colorloop effect is sorta a demo mode, but it is pretty. More importantly if your bulb is in colorloop, any other changes you make to it are ignored. You need it set back to effect:none to have other settings take.

alert: “none”, “select”, “lselect” - select flashes a bulb once. lselect flashes a bulb for 30 seconds or less if you set it back to none.

I’ve added support for these to the base ST implementation - you need to change the hue bulb device type, and the hue hub smart app to make it work.

The effect and alert attributes of the bulb reflect the current state of these from Hue, and the setEffect(s) and setAlert(s) commands were added to allow Smart Apps to change them. I added a couple tiles to the bulb device type to fire alert select mode, and toggle the colorloop effect.

If anyone is interested, I can post them up.

(John S) #2

Here are the diffs

Hue (Connect) SmartApp template changes

$ diff stapp.groovy stappnew.groovy 
<     name: "Hue (Connect)",
>     name: "Hue (Connect) with Effects and Alerts",
>                             sendEvent(d.deviceNetworkId, [name: "effect", value: bulb.value?.state?.effect])
>                             sendEvent(d.deviceNetworkId, [name: "alert", value: bulb.value?.state?.alert])
<                             }    
>                             }
>                             sendEvent(d.deviceNetworkId, [name: "effect", value: "none"])
>                             sendEvent(d.deviceNetworkId, [name: "alert", value: "none"])
>         log.debug("put response");
>                             case "effect":
>                                 sendEvent(childDeviceNetworkId, [name: "effect", value: v]) 
>                                 break
>                             case "alert":
>                                 sendEvent(childDeviceNetworkId, [name: "alert", value: v]) 
>                                 break
> def setEffect(childDevice, desired) {
>     log.debug "Executing 'setEffect'"
>     put("lights/${getId(childDevice)}/state", [effect: desired])
> }
> def setAlert(childDevice, desired) {
>     log.debug "Executing 'setAlert'"
>     put("lights/${getId(childDevice)}/state", [alert: desired])
> }
<     put("lights/${getId(childDevice)}/state", [hue: level])
>     // optional - turn off effect if any color change is made
>     put("lights/${getId(childDevice)}/state", [hue: level, effect: 'none'])
<     def value = [sat: sat, hue: hue]
>     // optional - turn off effect if any color change is made
>     def value = [sat: sat, hue: hue, effect: 'none']

Hue Bulb Device Template Changes

$ diff bulb.groovy bulbnew.groovy 
>         command "effect"        
>         command "effectCL" 
>         command "alertToggle"        
>         attribute "effect", "string"
>         attribute "alert", "string"
>     standardTile("effect", "device.effect", inactiveLabel: false, decoration: "flat") {
>         state "default", label:"Reset Effect", action:"effect", icon:""
>     }
>     standardTile("alert", "device.alert", inactiveLabel: false, decoration: "flat") {
>         state "default", label:"Alert!", action:"alertToggle", icon:""
>     }
>     standardTile("effectCL", "device.effect", inactiveLabel: false, decoration: "flat") {
>         state "default", label:"ColorLoop Effect", action:"effectCL", icon:""
>     }
<     details(["switch", "levelSliderControl", "rgbSelector", "refresh", "reset"])
>     details(["switch", "levelSliderControl", "rgbSelector", "refresh", "reset", "effect", "effectCL", "alert"])
> def setEffect(v) {
>     log.debug "setEffect: ${v}, $this"
>     parent.setEffect(this, v)
>     sendEvent(name: "effect", value: v)
> }
> def setAlert(v) {
>     log.debug "setAlert: ${v}, $this"
>     parent.setAlert(this, v)
>     sendEvent(name: "alert", value: v)
> }
> def alertToggle() { 
>     log.debug "Executing 'alert select'"
>     setAlert("select")
> }
> def effectNone() { 
>     log.debug "Executing 'effect none'"
>     setEffect("none")
> }
> def effectCL() { 
>     log.debug "Executing 'effect colorloop'"
>     setEffect("colorloop")
> }

If you want to use these, you need to install a direct copy of the Hue Hub device type (just make a copy from the template and save it) - then you can use your self-published Hue (Connect) App to discover your hub as before…

You’ll be able to see the current values of the effect/alert in the state of the bulb, and you can change them from the tile or from an app. Enjoy. Maybe ST can update their base code to include these, in some form…

Edit: Need to add setEffect and setAlert to the commands section if you want to be able to call them from a SmartApp.

(Tony - SmartThings Unpublished Contributor ) #3

This is great! Thanks for sharing.