No signature of method [fixed]

Getting this and can't for the life of me figure it out:

No signature of method... nextFanLevel() is applicable for argument types: (java.lang.Integer, java.lang.String) values: [68, brighten] on line 434 (buttonEvent1)

Line 434 is lvl = nextFanLevel(settings.defaultFanLevel-32,"brighten"):

def toggle(device){
    device.each{
        if (!stateOn(it)){
            if(isFan(it) == true && settings.defaultFanLevel != null){
              lvl = nextFanLevel(settings.defaultFanLevel-32,"brighten") 
                setLevel(it,lvl)
            } else if(isFan(it) != true && settings.defaultLevel != null){
                setLevel(it,settings.defaultLevel)
            } else {
                singleOn(it)
            }
            if(isFan(it) != true && defaultTemp != null){
           
                singleTemp(it,defaultTemp)
            }
        } else {
            singleOff(it)
        }
    }
}

defaultFanLevel:

def nextLevelFan(lvl,action){
    def returnLevel = lvl as int
    if(action == "dim"){
        returnLevel = lvl - 33
        if(returnLevel < 1){
            returnLevel = 1
        } else if(returnLevel < 51){
            returnLevel = 33
        } else if(returnLevel < 83){
            returnLevel = 67
        }
    } else if(action == "brighten"){
        returnLevel = lvl + 33
        if(returnLevel > 100){
            returnLevel = 101
        } else if(returnLevel > 83) {
            returnLevel = 100
        } else if(returnLevel > 51){
            returnLevel = 67
        } else if(returnLevel > 15){
            returnLevel = 33
        }
    }

    return returnLevel
}

Full code:

definition(
    name: "Magic Cube - child",
    namespace: "magicCube",
    author: "roguetech",
    description: "Control MagicCube",
    parent: "magicCube:Magic Cube",
    category: "Convenience",
    iconUrl: "https://raw.githubusercontent.com/ClassicGOD/SmartThingsPublic/master/devicetypes/classicgod/xiaomi-magic-cube-controller.src/images/mi_face_s.png",
    iconX2Url: "https://raw.githubusercontent.com/ClassicGOD/SmartThingsPublic/master/devicetypes/classicgod/xiaomi-magic-cube-controller.src/images/mi_face.png"
)

preferences {
    page(name: "setup", install: true, uninstall: true) {
        section() {
            label title: "Assign a name:", required: true
        }
        section() {
            input "buttonDevice", "capability.pushableButton", title: "The Cube", multiple: false, required: true
        }

        /*
         section(hidden: true, "Combined/cyle multiple") {
            input "combined", "enum", title: "Combined on/off/toggle or cycle through? (Only if multiple lights.) [Currently does not work!]", multiple: false, required: false,
                options: ["Combined","Cycle"]
        }
*/

        section("Instructions") {
            paragraph "For each action, select which lights or fans to turn on, turn off, toggle, dim/slow, and/or brighten/speed up. Do not have an action both turn on and off the same light/fan (use Toggle). Do not have an action both dim/slow and brighten/speed up the same light/fan."
            //           paragraph "Currently does not work: To have mutiple lights cycle on, select Combined/cylce multiple - > Cycle. For instance, if you select three lights for On, the first action would turn on light 1, the second time would turn on light 2, and finally light 3."
        }
        section(hideable: true, hidden: true, "Shake") {
            input "button_1_toggle", "capability.switch", title: "Toggle (if on, turn off; if off, turn on)", multiple: true, required: false
            input "button_1_on", "capability.switch", title: "On", multiple: true, required: false
            input "button_1_off", "capability.switch", title: "Off", multiple: true, required: false
            input "button_1_dim", "capability.switchLevel", title: "Dim", multiple: true, required: false
            input "button_1_brighten", "capability.switchLevel", title: "Brighten", multiple: true, required: false
        }
         section(hideable: true, hidden: true, "Slide") {
            input "button_4_toggle", "capability.switch", title: "Toggle (if on, turn off; if off, turn on)", multiple: true, required: false
            input "button_4_on", "capability.switch", title: "On", multiple: true, required: false
            input "button_4_off", "capability.switch", title: "Off", multiple: true, required: false
            input "button_4_dim", "capability.switchLevel", title: "Dim", multiple: true, required: false
            input "button_4_brighten", "capability.switchLevel", title: "Brighten", multiple: true, required: false
        }
        section(hideable: true, hidden: true, "Rotate clockwise") {
            input "button_6_toggle", "capability.switch", title: "Toggle (if on, turn off; if off, turn on)", multiple: true, required: false
            input "button_6_on", "capability.switch", title: "On", multiple: true, required: false
            input "button_6_off", "capability.switch", title: "Off", multiple: true, required: false
            input "button_6_dim", "capability.switchLevel", title: "Dim", multiple: true, required: false
            input "button_6_brighten", "capability.switchLevel", title: "Brighten", multiple: true, required: false
        }
        section(hideable: true, hidden: true, "Rotate counter clockwise") {
            input "button_7_toggle", "capability.switch", title: "Toggle (if on, turn off; if off, turn on)", multiple: true, required: false
            input "button_7_on", "capability.switch", title: "On", multiple: true, required: false
            input "button_7_off", "capability.switch", title: "Off", multiple: true, required: false
            input "button_7_dim", "capability.switchLevel", title: "Dim", multiple: true, required: false
            input "button_7_brighten", "capability.switchLevel", title: "Brighten", multiple: true, required: false
        }
        section(hideable: true, hidden: true, "90° flip") {
            input "button_2_toggle", "capability.switch", title: "Toggle (if on, turn off; if off, turn on)", multiple: true, required: false
            input "button_2_on", "capability.switch", title: "On", multiple: true, required: false
            input "button_2_off", "capability.switch", title: "Off", multiple: true, required: false
            input "button_2_dim", "capability.switchLevel", title: "Dim", multiple: true, required: false
            input "button_2_brighten", "capability.switchLevel", title: "Brighten", multiple: true, required: false
        }
         section(hideable: true, hidden: true, "180° flip") {
            input "button_3_toggle", "capability.switch", title: "Toggle (if on, turn off; if off, turn on)", multiple: true, required: false
            input "button_3_on", "capability.switch", title: "On", multiple: true, required: false
            input "button_3_off", "capability.switch", title: "Off", multiple: true, required: false
            input "button_3_dim", "capability.switchLevel", title: "Dim", multiple: true, required: false
            input "button_3_brighten", "capability.switchLevel", title: "Brighten", multiple: true, required: false
        }
          section(hideable: true, hidden: true, "Knock") {
            input "button_5_toggle", "capability.switch", title: "Toggle (if on, turn off; if off, turn on)", multiple: true, required: false
            input "button_5_on", "capability.switch", title: "On", multiple: true, required: false
            input "button_5_off", "capability.switch", title: "Off", multiple: true, required: false
            input "button_5_dim", "capability.switchLevel", title: "Dim", multiple: true, required: false
            input "button_5_brighten", "capability.switchLevel", title: "Brighten", multiple: true, required: false
        }
        section("Default Settings When Turned On") {
            input "defaultLevel", "number", title: "Light level (1-100) [optional]", required: false
            input "defaultFanLevel", "number", title: "Fan level (1-100) [optional]", required: false
            input "defaultTemp", "number", title: "Color lights - Temp Color (2200-6500) [optional]", required: false
        }
        section(){
            input "multiplier", "decimal", required: false, title: "Multiplier - Multiplier/divider for dimming and brightening, from 1.01 to 99. For instance, 2.0 doubles the brightness each time (eg from 25% to 50%, then 100%). Default 1.2."
        }
    }
}

def dimSpeed(){
    if(settings.multiplier != null){
        return settings.multiplier
    }else{
        return 1.2
    }
}

def installed() {
    initialize()
}

def updated() {
    unsubscribe()
    initialize()
}

def initialize() {
    log.info "MagicCube initialized"
    subscribe(buttonDevice, "pushed.1", buttonEvent1)
    subscribe(buttonDevice, "pushed.2", buttonEvent2)
    subscribe(buttonDevice, "pushed.3", buttonEvent3)
    subscribe(buttonDevice, "pushed.5", buttonEvent5)
    subscribe(buttonDevice, "pushed.6", buttonEvent6)
    subscribe(buttonDevice, "pushed.7", buttonEvent7)
}

def buttonEvent1(evt){
    log.info "MagicCube: $evt.displayName shaken."
    validateTemp()
    validateLevel()
    validateFanLevel()
    validateMultiplier()
    def buttonNumber = evt.value

    if(button_1_toggle != null){
        toggle(button_1_toggle)
    }
    if(button_1_on != null){
        multiOn(button_1_on)
    }
    if(button_1_off != null){
        multiOff(button_1_off)
    }
    if(button_1_dim != null){
        dim(button_1_dim)
    }
    if(button_1_brighten != null){
        brighten(button_1_brighten)
    }
}

def buttonEvent2(evt){
    log.info "MagicCube: $evt.displayName flipped 90."
    validateTemp()
    validateLevel()
    validateFanLevel()
    validateMultiplier()
    def buttonNumber = evt.value

    if(button_2_toggle != null){
        toggle(button_2_toggle)
    }
    if(button_2_on != null){
        multiOn(button_2_on)
    }
    if(button_2_off != null){
        multiOff(button_2_off)
    }
    if(button_2_dim != null){
        dim(button_2_dim)
    }
    if(button_2_brighten != null){
        brighten(button_2_brighten)
    }
}

def buttonEvent3(evt){
    log.info "MagicCube: $evt.displayName flipped 180."
    validateTemp()
    validateLevel()
    validateFanLevel()
    validateMultiplier()
    def buttonNumber = evt.value
    
    if(button_3_toggle != null){
        toggle(button_3_toggle)
    }
    if(button_3_on != null){
        multiOn(button_3_on)
    }
    if(button_3_off != null){
        multiOff(button_3_off)
    }
    if(button_3_dim != null){
        dim(button_3_dim)
    }
    if(button_3_brighten != null){
        brighten(button_3_brighten)
    }
}

def buttonEvent4(evt){
    log.info "MagicCube: $evt.displayName slid."
    validateTemp()
    validateLevel()
    validateFanLevel()
    validateMultiplier()
    def buttonNumber = evt.value

    if(button_4_toggle != null){
        toggle(button_4_toggle)
    }
    if(button_4_on != null){
        multiOn(button_4_on)
    }
    if(button_4_off != null){
        multiOff(button_4_off)
    }
    if(button_4_dim != null){
        dim(button_4_dim)
    }
    if(button_4_brighten != null){
        brighten(button_4_brighten)
    }
}

def buttonEvent5(evt){
    log.info "MagicCube: $evt.displayName knocked."
    validateTemp()
    validateLevel()
    validateFanLevel()
    validateMultiplier()
    def buttonNumber = evt.value

    if(button_5_toggle != null){
        toggle(button_5_toggle)
    }
    if(button_5_on != null){
        multiOn(button_5_on)
    }
    if(button_5_off != null){
        multiOff(button_5_off)
    }
    if(button_5_dim != null){
        dim(button_5_dim)
    }
    if(button_5_brighten != null){
        brighten(button_5_brighten)
    }
}

def buttonEvent6(evt){
    log.info "MagicCube: $evt.displayName rotated clockwise."
    validateTemp()
    validateLevel()
    validateFanLevel()
    validateMultiplier()
    def buttonNumber = evt.value

    if(button_6_toggle != null){
        toggle(button_6_toggle)
    }
    if(button_6_on != null){
        multiOn(button_6_on)
    }
    if(button_6_off != null){
        multiOff(button_6_off)
    }
    if(button_6_dim != null){
        dim(button_6_dim)
    }
    if(button_6_brighten != null){
        brighten(button_6_brighten)
    }
}

def buttonEvent7(evt){
    log.info "MagicCube: $evt.displayName rotated counter clockwise."
    validateTemp()
    validateLevel()
    validateFanLevel()
    validateMultiplier()
    def buttonNumber = evt.value

    if(button_7_toggle != null){
        toggle(button_7_toggle)
    }
    if(button_7_on != null){
        multiOn(button_7_on)
    }
    if(button_7_off != null){
        multiOff(button_7_off)
    }
    if(button_7_dim != null){
        dim(button_7_dim)
    }
    if(button_7_brighten != null){
        brighten(button_7_brighten)
    }
}

// calculate average level of a group
def getLevel(device){
    def lvl = 0
    def count = 0
    device.each{
        if(isFan(it) != true){
            lvl += it.currentLevel
            count++
        }
    }
    if(lvl>0) lvl = Math.round(lvl/count)
    if (lvl > 100) lvl = 100
    return lvl
}

def setLevel(device,level){
    device.setLevel(level as int)
    // output to log with fan "high", "medium" or "low"
    if(isFan(device) == true){
        if(level == 99 | level == 100){
            log.info "MagicCube: Set level of $device to high."
        } else if (level == 66 || level == 67){
            log.info "MagicCube: Set level of $device to medium."
        } else if (level == 33 || level == 34){
            log.info "MagicCube: Set level of $device to low."
        } else {
            log.info "MagicCube: Set level of $device to $level."
        }
    } else {
        log.info "MagicCube: Set level of $device to $level."
    }
}


def nextLevelFan(lvl,action){
    def returnLevel = lvl as int
    if(action == "dim"){
        returnLevel = lvl - 33
        if(returnLevel < 1){
            returnLevel = 1
        } else if(returnLevel < 51){
            returnLevel = 33
        } else if(returnLevel < 83){
            returnLevel = 67
        }
    } else if(action == "brighten"){
        returnLevel = lvl + 33
        if(returnLevel > 100){
            returnLevel = 101
        } else if(returnLevel > 83) {
            returnLevel = 100
        } else if(returnLevel > 51){
            returnLevel = 67
        } else if(returnLevel > 15){
            returnLevel = 33
        }
    }

    return returnLevel
}

// action = "dim" or "brighten"
def nextLevel(lvl, dimSpeed, action){
    def returnLevel = lvl as int
    if (action != "dim" && action != "brighten"){
        log.debug "MagicCube: Invalid action with nextLevel"
        return false
    }

    if ((action == "dim" && lvl > 1) || (action ==  "brighten" && lvl < 100)){
        if (action == "dim"){
            returnLevel = Math.round(lvl / dimSpeed)
            // make sure it changed by at least 1
            if (returnLevel == lvl){
                returnLevel = returnLevel - 1
            }
        } else if (action == "brighten"){
            returnLevel = Math.round(lvl * dimSpeed)
            // make sure it changed by at least 1
            if (returnLevel == lvl){
                returnLevel = returnLevel + 1
            }
        }
    }
    if (returnLevel <2){
        returnLevel = 1
    } else if(returnLevel > 99){
        returnLevel = 100
    }

    return returnLevel
}

def stateOn(device){
    def stateOn = false 

    if (device.currentValue('switch') == "on"){
        stateOn = true
    }

    return stateOn
}

def singleOn(device){
    device.on()
    log.info "MagicCube: Turned on $device."
}

def singleOff(device){
    device.off()
    log.info "MagicCube: Turned off $device."
}

def multiOn(device){
    device.each{
        if(stateOn(it) == false){
            if(isFan(it) == true && settings.defaultFanLevel != null){
                setLevel(it,nextFanLevel(settings.defaultFanLevel-1))
            } else if(isFan(it) != true && settings.defaultLevel != null){
                setLevel(it,settings.defaultLevel)
            } else {
                singleOn(it)
            }
            if(defaultTemp != null){
                singleTemp(it,defaultTemp)
            }
        }
    }
}

def multiOff(device){
    device.each{
        singleOff(it)
    }
}

def toggle(device){
    device.each{
        if (!stateOn(it)){
            if(isFan(it) == true && settings.defaultFanLevel != null){
              lvl = nextFanLevel(settings.defaultFanLevel-32,"brighten") 
                setLevel(it,lvl)
            } else if(isFan(it) != true && settings.defaultLevel != null){
                setLevel(it,settings.defaultLevel)
            } else {
                singleOn(it)
            }
            if(isFan(it) != true && defaultTemp != null){
           
                singleTemp(it,defaultTemp)
            }
        } else {
            singleOff(it)
        }
    }
}

def dim(device){
    def lvl = getLevel(device)

    device.each{
        if(isFan(it) == true){
            if(!stateOn(it)){
                singleOn(it)
                setLevel(it,100)
            } else {
                newLevel = nextLevelFan(it.currentLevel, "dim")
                if(newLevel < 33){
                    singleOff(it)
                } else {
                    setLevel(it,newLevel)
                }
            }
        } else if(isFan(it) != true){
            if (!stateOn(it)){
                setLevel(it,1)
            } else if(lvl == 1){
                singleOff(it)
                pause(750)
                singleOn(it)
                log.info "MagicCube: $device is already at 1%; can't dim."
            } else {
                newLevel = nextLevel(lvl, dimSpeed(), "dim")
                setLevel(it,newLevel)
            }
        }
    }
}

def brighten(device){
    def lvl = getLevel(device)

    device.each{
        if(isFan(it) == true){
            if(!stateOn(it)){
                singleOn(it)
                setLevel(it,33)
            } else {
                newLevel = nextLevelFan(it.currentLevel, "brighten")
                if(newLevel > 100){
                    singleOff(it)
                } else {
                    setLevel(it,newLevel)
                }
            }
        } else if(isFan(it) != true){
            if (!stateOn(it)){
                setLevel(it,1)
            } else if(lvl == 100){
                singleOff(it)
                pause(750)
                singleOn(it)
                log.info "MagicCube: $device is already at 100%; can't brighten."
            } else {
                newLevel = nextLevel(lvl, dimSpeed(), "brighten")
                setLevel(it,newLevel)
            }
        }
    }
}

def singleTemp(device, temp){
    if(isTemp(device) == true){
        device.setColorTemperature(temp as int)
        log.info "MagicCube: $device temperature set to $temp."
    }
}

def validateTemp(){
    settings.defaultTemp = settings.defaultTemp as int
    if(defaultTemp != null){
        if(defaultTemp < 2200 || defaultTemp > 6500){
            defaultTemp = null
            log.debug "MagicCube: Default Temp Color is invalid."
        }
    }
}
 
def validateLevel(){
    settings.defaultLevel = settings.defaultLevel as int
    if(defaultLevel != null){
        if(defaultLevel < 1 || defaultLevel > 100){
            defaultLevel = null
            log.debug "MagicCube: Default Level is invalid."
        }
    }
}

def validateFanLevel(){
    settings.defaultFanLevel = settings.defaultFanLevel as int
    if(settings.defaultFanLevel != null){
       
        if(settings.defaultFanLevel < 1 || settings.defaultFanLevel > 100){
            settings.defaultFanLevel = null
            log.debug "MagicCube: Default Fan Level is invalid."
        }
    }

}

def validateMultiplier(){
    if(pushMultiplier != null){
        if(pushMultiplier < 1 || pushMultiplier > 100){
            pushMultiplier = null
            log.debug "MagicCube: Multiplier is invalid."
        }
    }
}

def isDimmable(device){
    def deviceCapability
    device.capabilities.each {
        deviceCapability += it.name
    }
    return deviceCapability.contains("SwitchLevel")
}

def isTemp(device){
   def deviceCapability
    device.capabilities.each {
        deviceCapability += it.name
    }
    return deviceCapability.contains("ColorTemperature")
}

def isColor(device){
    def deviceCapability
    device.capabilities.each {
        deviceCapability += it.name
    }
    return deviceCapability.contains("ColorMode")
}

def isFan(device){
    def deviceCapability
    device.capabilities.each {
        deviceCapability += it.name
    }
    if(deviceCapability.contains("Actuator") == true && device.name.contains("Fan") == true){
        return true
    } else {
        return false
    }
}

nextLevelFan vs. nextFanLevel?

3 Likes

Nice catch

That'd be it. I knew it'd be something stupid, but I've been staring at it for three days and couldn't see it. Thanks!