LightEffects

Hi all!

I spent the weekend trying to improve @dkkohler's H801 Tasmota driver, since it didn't handle hue conversion properly and had some data type errors.

This code is nearly ready for sharing, but I'd like to add the LightEffects capability.
I got the driver to change the effects, but I can't figure out how to properly add the attributes so that they would populate the device info.

There's pretty much no documentation available, so any help would be appreciated.

https://docs.hubitat.com/index.php?title=Driver_Capability_List#LightEffects

2 Likes

Thanks. I already found the capability description, but fail to grasp how it should be added in the code. There aren't any customisation options in this device's modes, so I feel they should logically be static.

Sure, still need to sent one event with the list of available effects.

Thanks for picking this up and making some improvements! Interested to see your new version.

Can someone point me to this driver? I could use some examples of how to use LightEffects. Thank you!

Did you find a sample or a driver that uses LightEffects ?

Nope. I did not use LightEffects.

1 Like

@mike.maxwell
I have seen the doc on LightEffects but I still can't find any sample code or any code for that matter that shows how it works and how to build the mapping for it.

Can you please post some snippets of it ?

1 Like

for a static set of effects:

import groovy.json.JsonSlurper
import groovy.transform.Field

@Field static Map lightEffects = [1:"Fire Place",2:"Storm",3:"Deep Fade",4:"Lite Fade",5:"Police"]

def installed() {
    def le = new groovy.json.JsonBuilder(lightEffects)
    sendEvent(name:"lightEffects",value:le)
}

def setEffect(String effect){
    def id = lightEffects.find{ it.value == effect }
    if (id) setEffect(id.key)
}

def setEffect(id){
    def descriptionText
    def efSelect = lightEffects."${id}"
    descriptionText = "${device.displayName}, effect was was set to ${efSelect}"
    if (txtEnable) log.info "${descriptionText}"
    sendEvent(name:"effectName", value:efSelect, descriptionText:descriptionText)
    descriptionText = "${device.displayName}, colorMode is EFFECTS"
    if (txtEnable) log.info "${descriptionText}"
    sendEvent(name:"colorMode", value:"EFFECTS", descriptionText:descriptionText)
    state.crntEffectId = id
    //device specific code here
}

def setNextEffect(){
    def currentEffect = state.crntEffectId ?: 0
    currentEffect++
    if (currentEffect >= 6) currentEffect = 1
    setEffect(currentEffect)
}

def setPreviousEffect(){
    def currentEffect = state.crntEffectId ?: 2
    currentEffect--
    if (currentEffect < 1) currentEffect = 6 - 1
    setEffect(currentEffect)
}
1 Like

I needed this inside the code so I tried a few ways to do this but non worked...

def static Map lightEffects = [1:"Fire Place",2:"Storm",3:"Deep Fade",4:"Lite Fade",5:"Police"]
def Map lightEffects = [1:"Fire Place",2:"Storm",3:"Deep Fade",4:"Lite Fade",5:"Police"]
def lightEffects = [1:"Fire Place",2:"Storm",3:"Deep Fade",4:"Lite Fade",5:"Police"]

First 2 wouldn't even save the code and the last one gives me this error

java.lang.NullPointerException: Cannot get property '1' on null object on line 426 (setEffect)
java.lang.NullPointerException: Cannot get property '2' on null object on line 426 (setNextEffect)

I just want to pull all my hair out and eat my keyboard... I even looked and some groovy tutorials and the last define should have worked.

Why not ?

you needed what inside the code?

what is it that you're trying to do that you can't use @Field lightEffects?

I wanted to it use inside a nested if -- I went a different route since I couldn't achieve that