Switch state not working for me

Is this correct?

if("off" == dimmers.currentSwitch) {
	dimdown = 0
    dimmers.setLevel(5)
    dimmers.on()
}

It doesnt’ seem to be going in the if statement, the switch is off!

What am I doing wrong?

What if dimmers has multiple switches?

I also saw some use thie notation:

state.currentLevel = dimmers[0].currentValue(“level”)

why not just use:

state.currentLevel = dimmers[0].SwitchLevel

?

Thanks :slight_smile:

If dimmers was defined with multiple: true in the input, then getting an attribute value will return a list.

See this for more information: http://docs.smartthings.com/en/latest/smartapp-developers-guide/devices.html#interacting-with-multiple-devices

There are a few different ways to get the value of an attribute:

device.currentValue('level')` // => current value of level attribute
device.currentLevel             // => current value of level attribute

More information here.

Also reference docs of interest below:
currentValue docs
currentAttributeName docs

Thanks for the info. I got things to work… had few other issues.