Server error

Novice here. I've got some hacked together code. Works on ST. I get a 500 error, and I can't figure out what the issue is. It occurs after this:

def selectButton() {
    dynamicPage(name: "selectButton", title: "Select the Cube.", nextPage: "configureButton1", uninstall: configured()) {
        section {
            input "buttonDevice", "capability.pushableButton", title: "Button", multiple: false, required: true
        }
    }
}

And before this:

def createPage(pageNum, title) {
    if ((state.numButton == pageNum) || (pageNum == 8))
    state.installCondition = true
    dynamicPage(name: "configureButton$pageNum", title: title,
                nextPage: "configureButton${pageNum+1}", install: state.installCondition, uninstall: configured(), getButtonSections(pageNum))
}

def configureButton1() {
    def title="Set the first light for 90° flip and rotate."
    createPage(1,title)
}

def getButtonSections(buttonNumber) {
    return {
        section("Lights") {
            input "lights_${buttonNumber}_pushed", "capability.switch", title: "Pushed", multiple: true, required: false
        }
    }
}

Assistance would be appreciated.

Did you define all of the pages in Preferences?

Like this:
page(name: "configureButton1")

etc.

They are configurationButton2 through 8, with the preferences dynamically creating them. I tried having "dynamicPage" for configureButton1 in the preferences section like create Page has it, but still got a server error.

preferences {
    page(name: "selectButton")
    for (def i=1; i<=8; i++) {
        page(name: "configureButton$i")
    }
}

Yet you show configureButton1 above. Every page has to be named in Preferences, even though you are creating them dynamically. If you don't have it declared there, it will throw a 500 error.

There are configureButton2, configureButton3, etc.

Here's the entire app:

[removed as no longer relevant]

edit: Progress, sort of. In preferences, I replaced the loop with "page(name: "configureButton1")", etc., and no Server Error, but doesn't display those pages. Just displays "Done".

@bravenel Thanks! I think I got it working. Just explicitly defined the configureButton pages, and got rid of the loop and the createPage function. Not sure why it didn't work as it was, but I don't care. If it's a Hubitat issue, here's what I had:

preferences {
    page(name: "selectButton")
    for (def i=1; i<=4; i++) {
        page(name: "configureButton$i")
    }
}

def selectButton() {
    dynamicPage(name: "selectButton", title: "Select the Cube.", nextPage: "configureButton1", uninstall: configured()) {
        section {
            input "buttonDevice", "capability.pushableButton", title: "Button", multiple: false, required: true
        }
    }
}

def createPage(pageNum, title) {
    if (pageNum == 4)
    state.installCondition = true
    dynamicPage(name: "configureButton$pageNum", title: title,
                nextPage: "configureButton${pageNum+1}", install: state.installCondition, uninstall: configured(), getButtonSections(pageNum))
}

def configureButton1() {
    state.numButton = buttonDevice.currentState("numberOfButtons")?.longValue ?: 4
    log.debug "state variable numButton: ${state.numButton}"
    state.installCondition = false
    def title="Set the first light for 90° flip and/or rotate."
    createPage(1,title)
}

def configureButton2() {
    def title="Set the second light for 90° flip and/or rotate."
    createPage(2,title)
}

def configureButton3() {
    def title="Set the third light for 90° flip and/or rotate."
    createPage(3,title)
}

def configureButton4() {
    def title="Set the light for 180° flip."
    createPage(4,title)
}

Here's what seems to work:

preferences {
    page(name: "selectButton")
    page(name: "configureButton1")
    page(name: "configureButton2")
    page(name: "configureButton3")
    page(name: "configureButton4")

}

def selectButton() {
    dynamicPage(name: "selectButton", title: "Select the Cube.", nextPage: "configureButton1", uninstall: configured()) {
        section {
            input "buttonDevice", "capability.pushableButton", title: "Button", multiple: false, required: true
        }
    }
}

def createPage(pageNum, title) {
    dynamicPage(name: "configureButton$pageNum", title: title,
                nextPage: "configureButton${pageNum+1}", install: state.installCondition, uninstall: configured(), getButtonSections(pageNum))
}

def configureButton1() {
    dynamicPage(name: "configureButton1", title: "Set the first light for 90° flip and/or rotate.",
                nextPage: "configureButton2", install: false, uninstall: configured(), getButtonSections(pageNum))
}

def configureButton2() {
    dynamicPage(name: "configureButton2", title: "Set the second light for 90° flip and/or rotate.",
                nextPage: "configureButton3", install: false, uninstall: configured(), getButtonSections(pageNum))
}

def configureButton3() {
    dynamicPage(name: "configureButton3", title: "Set the third light for 90° flip and/or rotate.",
                nextPage: "configureButton4", install: false, uninstall: configured(), getButtonSections(pageNum))
}

def configureButton4() {
    dynamicPage(name: "configureButton3", title: "Set the light for 180° flip.",
                install: true, uninstall: configured(), getButtonSections(pageNum))
}

are you able to post the full code with the loop that you could not get working? Also did you have the logging page open when you were getting the error, did you see any error message there? When I attempt to test your code i get an error about the configured() method missing.

Here is the full original code. I've been able to get it to load, but now I'm stuck trying to get it to actually register any button presses. Device log shows them. App log doesn't show anything, app doesn't do anything.

definition(
    name: "MagicCube",
    namespace: "magicCube1",
    author: "roguetech",
    description: "Control MagicCube",
    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: "selectButton")
    for (def i=1; i<=8; i++) {
        page(name: "configureButton$i")
    }
}

def selectButton() {
    dynamicPage(name: "selectButton", title: "Select the controller.", nextPage: "configureButton1", uninstall: configured()) {
        section {
            input "buttonDevice", "capability.pushableButton", title: "Button", multiple: false, required: true
        }
    }
}

def createPage(pageNum, title) {
    if ((state.numButton == pageNum) || (pageNum == 8))
    state.installCondition = true
    dynamicPage(name: "configureButton$pageNum", title: title,
                nextPage: "configureButton${pageNum+1}", install: state.installCondition, uninstall: configured(), getButtonSections(pageNum))
}

def configureButton1() {
    state.numButton = buttonDevice.currentState("numberOfButtons")?.longValue ?: 4
    log.debug "state variable numButton: ${state.numButton}"
    state.installCondition = false
    def title="Set the first light for 90° flip and rotate."
    createPage(1,title)
}
def configureButton2() {
    def title="Set the second light for 90° flip and rotate."
    createPage(2,title)
}

def configureButton3() {
    def title="Set the third light for 90° flip and rotate."
    createPage(3,title)
}

def configureButton4() {
    def title="Set the light for 180° flip."
    createPage(4,title)
}

def configureButton5() {
	def title="Unused."
    createPage(5,title)
}

def configureButton6() {
	def title="Unused."
    createPage(6,title)
}

def configureButton7() {
	def title="Unused."
    createPage(7,title)
}

def configureButton8() {
	def title="Unused."
    createPage(8,title)
}

def getButtonSections(buttonNumber) {
    return {
        section("Lights") {
            input "lights_${buttonNumber}_pushed", "capability.switch", title: "Pushed", multiple: true, required: false
        }
    }
}

def installed() {
    initialize()
}

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

def initialize() {
    subscribe(buttonDevice, "button", buttonEvent)
}

def configured() {
    return buttonDevice || buttonConfigured(1) || buttonConfigured(2) || buttonConfigured(3) || buttonConfigured(4)
}

def buttonConfigured(idx) {
    return settings["lights_$idx_pushed"]
}

def buttonEvent(evt){
    def buttonNumber = evt.data
    def value = evt.value
//    log.debug "buttonEvent: $evt.name = $evt.value ($evt.data)"
    log.debug "button: $buttonNumber, value: $value"

//    def recentEvents = buttonDevice.eventsSince(new Date(now() - 3000)).findAll{it.value == evt.value && it.data == evt.data}
//    log.debug "Found ${recentEvents.size()?:0} events in past 3 seconds"

	// Shake; turn on in sequence
    if(buttonNumber.startsWith("{\"buttonNumber\":1,")){
        if (lights_2_pushed != null){
            if (lights_1_pushed.currentValue('switch').contains('off') && lights_2_pushed.currentValue('switch').contains('off')) {
                lights_1_pushed.on()
                log.info "Turned on $lights_1_pushed."
            }else if(lights_1_pushed.currentValue('switch').contains('on') && lights_2_pushed.currentValue('switch').contains('off')) {
                lights_2_pushed.on()
                log.info "Turned on $lights_2_pushed."
            }else if(lights_1_pushed.currentValue('switch').contains('on') && lights_2_pushed.currentValue('switch').contains('on')) {
                lights_1_pushed.off()
                log.info "Turned off $lights_1_pushed."
            }else if(lights_1_pushed.currentValue('switch').contains('off') && lights_2_pushed.currentValue('switch').contains('on')) {
                lights_2_pushed.off()
                log.info "Turned off $lights_2_pushed."
            }
        }
        // 90 flip; turn off
    } else if(buttonNumber.startsWith("{\"buttonNumber\":2,")){ //90 flip
        if (lights_2_pushed == null){
            if (lights_1_pushed.currentValue('switch').contains('on')){
                lights_1_pushed.off()
                log.info "Turned off $lights_1_pushed."
            }else{
                lights_1_pushed.on()
                log.info "Turned on $lights_1_pushed."
            }
        } else {
            if (lights_1_pushed.currentValue('switch').contains('on') && lights_2_pushed.currentValue('switch').contains('off')) {
                lights_1_pushed.off()
                lights_3_pushed.off()
                log.info "Turned off $lights_1_pushed and $lights_3_pushed."
            }else if(lights_2_pushed.currentValue('switch').contains('on') && lights_2_pushed.currentValue('switch').contains('on')) {
                lights_2_pushed.off()
                log.info "Turned off $lights_2_pushed."
            }
        }
   	// 180 flip; turn off each other's
    } else if(buttonNumber.startsWith("{\"buttonNumber\":3,")){
        if (lights_4_pushed.currentValue('switch').contains('on')){
            lights_4_pushed.off()
            log.info "Turned off $lights_4_pushed."
        } else if (lights_4_pushed.currentValue('switch').contains('off')){
            lights_4_pushed.on()
            log.info "Turned on $lights_4_pushed."
        }
    // Rotate right; increase level
    } else if(buttonNumber.startsWith("{\"buttonNumber\":6,")){
        def $lvl

        if (lights_1_pushed.currentValue('switch').contains('on')){
            $lvl = lights_1_pushed.currentValue("level")
        } else {
            if (lights_2_pushed != null){
                if(lights_2_pushed.currentValue('switch').contains('on')){
                    $lvl = lights_2_pushed.currentValue("level")
                } else if(lights_3_pushed.currentValue('switch').contains('on')){
                    $lvl = lights_3_pushed.currentValue("level")
                }
            }
        }

        $lvl[0] = Math.min(Math.round($lvl[0]*1.33+1),100)

        if(lights_1_pushed.currentValue('switch').contains('on')) {
            lights_1_pushed.setLevel($lvl[0])
            log.info "Set $lights_1_pushed to " + $lvl[0] + "%."
        }
        if (lights_2_pushed != null){
        if(lights_2_pushed.currentValue('switch').contains('on')) {
            lights_2_pushed.setLevel($lvl[0])
            log.info "Set $lights_2_pushed to " + $lvl[0] + "%."
        }
        if(lights_3_pushed.currentValue('switch').contains('on')) {
            lights_3_pushed.setLevel($lvl[0])
            log.info "Set $lights_3_pushed to " + $lvl[0] + "%."
        }
        }
    // Rotate left; decrease level
    } else if(buttonNumber.startsWith("{\"buttonNumber\":7,")){
        def $lvl

        if (lights_1_pushed.currentValue('switch').contains('on')){
            $lvl = lights_1_pushed.currentValue("level")
        } else {
            if (lights_2_pushed != null){
                if(lights_1_pushed.currentValue('switch').contains('on')){
                    $lvl = lights_2_pushed.currentValue("level")
                } else if(lights_3_pushed.currentValue('switch').contains('on')){
                    $lvl = lights_3_pushed.currentValue("level")
                }
            }
        }

        $lvl[0] = Math.max(Math.round($lvl[0]*0.66),1)

        if(lights_1_pushed.currentValue('switch').contains('on'))  {
            lights_1_pushed.setLevel($lvl[0])
            log.info "Set $lights_1_pushed to " + $lvl[0] + "%."
        }
        if (lights_2_pushed != null){
            if(lights_2_pushed.currentValue('switch').contains('on'))  {
                lights_2_pushed.setLevel($lvl[0])
                log.info "Set $lights_2_pushed to " + $lvl[0] + "%."
            }
            if(lights_3_pushed.currentValue('switch').contains('on'))  {
                lights_3_pushed.setLevel($lvl[0])
                log.info "Set $lights_3_pushed to " + $lvl[0] + "%."
            }
        }
    }
}

Here is the code that loads, but doesn't actually do anything:

definition(
    name: "MagicCube",
    namespace: "magicCube1",
    author: "roguetech",
    description: "Control MagicCube",
    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: "selectButton")
    page(name: "configureButton1")
    page(name: "configureButton2")
    page(name: "configureButton3")
    page(name: "configureButton4")

}

def selectButton() {
    dynamicPage(name: "selectButton", title: "Select the Cube.", nextPage: "configureButton1", uninstall: true) {
        section {
            input "buttonDevice", "capability.pushableButton", title: "Button", multiple: false, required: true
        }
    }
}

def configureButton1() {
    dynamicPage(name: "configureButton1", title: "Set the first light for 90° flip and/or rotate.", nextPage: "configureButton2", install: false){
            section("Lights") {
                input "lights_1_pushed", "capability.switch", title: "Pushed", multiple: true, required: false
            }
    }
}

def configureButton2() {
    dynamicPage(name: "configureButton2", title: "Set the second light for 90° flip and/or rotate.", nextPage: "configureButton3", install: false){
            section("Lights") {
                input "lights_2_pushed", "capability.switch", title: "Pushed", multiple: true, required: false
            }
    }
}

def configureButton3() {
    dynamicPage(name: "configureButton3", title: "Set the third light for 90° flip and/or rotate.", nextPage: "configureButton4", install: false){
            section("Lights") {
                input "lights_3_pushed", "capability.switch", title: "Pushed", multiple: true, required: false
            }
    }
}

def configureButton4() {
    dynamicPage(name: "configureButton3", title: "Set the light for 180° flip.", install: true){
            section("Lights") {
                input "lights_4_pushed", "capability.switch", title: "Pushed", multiple: true, required: false
            }
    }
}

def installed() {
    initialize()
}

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

def initialize() {
    log.debug "INITIALIZED"
    subscribe(buttonDevice, "pushed", buttonEvent)
}

def configured() {
    return buttonDevice || buttonConfigured(1) || buttonConfigured(2) || buttonConfigured(3) || buttonConfigured(4)
}

def buttonConfigured(idx) {
    return settings["lights_$idx_pushed"]
}

def buttonEvent(evt){
    def buttonNumber = evt.value
 //   def value = evt.value
//    log.debug "buttonEvent: $evt.name = $evt.value ($evt.data)"
    log.debug "button: $buttonNumber, value: $value"

    def recentEvents = buttonDevice.eventsSince(new Date(now() - 3000)).findAll{it.value == evt.value && it.data == evt.data}
    log.debug "Found ${recentEvents.size()?:0} events in past 3 seconds"

	// Shake; turn on in sequence [fixed #]
    if(buttonNumber.startsWith("{\"buttonNumber\":1,")){
        if (lights_2_pushed != null){
            if (lights_1_pushed.currentValue('switch').contains('off') && lights_2_pushed.currentValue('switch').contains('off')) {
                lights_1_pushed.on()
                log.info "Turned on $lights_1_pushed."
            }else if(lights_1_pushed.currentValue('switch').contains('on') && lights_2_pushed.currentValue('switch').contains('off')) {
                lights_2_pushed.on()
                log.info "Turned on $lights_2_pushed."
            }else if(lights_1_pushed.currentValue('switch').contains('on') && lights_2_pushed.currentValue('switch').contains('on')) {
                lights_1_pushed.off()
                log.info "Turned off $lights_1_pushed."
            }else if(lights_1_pushed.currentValue('switch').contains('off') && lights_2_pushed.currentValue('switch').contains('on')) {
                lights_2_pushed.off()
                log.info "Turned off $lights_2_pushed."
            }
        }
        // 90 flip; turn off
    } else if(buttonNumber.startsWith("{\"buttonNumber\":2,")){ //90 flip
        if (lights_2_pushed == null){
            if (lights_1_pushed.currentValue('switch').contains('on')){
                lights_1_pushed.off()
                log.info "Turned off $lights_1_pushed."
            }else{
                lights_1_pushed.on()
                log.info "Turned on $lights_1_pushed."
            }
        } else {
            if (lights_1_pushed.currentValue('switch').contains('on') && lights_2_pushed.currentValue('switch').contains('off')) {
                lights_1_pushed.off()
                lights_3_pushed.off()
                log.info "Turned off $lights_1_pushed and $lights_3_pushed."
            }else if(lights_2_pushed.currentValue('switch').contains('on') && lights_2_pushed.currentValue('switch').contains('on')) {
                lights_2_pushed.off()
                log.info "Turned off $lights_2_pushed."
            }
        }
   	// 180 flip; turn off each other's
    } else if(buttonNumber.startsWith("{\"buttonNumber\":3,")){
        if (lights_4_pushed.currentValue('switch').contains('on')){
            lights_4_pushed.off()
            log.info "Turned off $lights_4_pushed."
        } else if (lights_4_pushed.currentValue('switch').contains('off')){
            lights_4_pushed.on()
            log.info "Turned on $lights_4_pushed."
        }
    // Rotate right; increase level
    } else if(buttonNumber.startsWith("{\"buttonNumber\":6,")){
        def $lvl

        if (lights_1_pushed.currentValue('switch').contains('on')){
            $lvl = lights_1_pushed.currentValue("level")
        } else {
            if (lights_2_pushed != null){
                if(lights_2_pushed.currentValue('switch').contains('on')){
                    $lvl = lights_2_pushed.currentValue("level")
                } else if(lights_3_pushed.currentValue('switch').contains('on')){
                    $lvl = lights_3_pushed.currentValue("level")
                }
            }
        }

        $lvl[0] = Math.min(Math.round($lvl[0]*1.33+1),100)

        if(lights_1_pushed.currentValue('switch').contains('on')) {
            lights_1_pushed.setLevel($lvl[0])
            log.info "Set $lights_1_pushed to " + $lvl[0] + "%."
        }
        if (lights_2_pushed != null){
        if(lights_2_pushed.currentValue('switch').contains('on')) {
            lights_2_pushed.setLevel($lvl[0])
            log.info "Set $lights_2_pushed to " + $lvl[0] + "%."
        }
        if(lights_3_pushed.currentValue('switch').contains('on')) {
            lights_3_pushed.setLevel($lvl[0])
            log.info "Set $lights_3_pushed to " + $lvl[0] + "%."
        }
        }
    // Rotate left; decrease level
    } else if(buttonNumber.startsWith("{\"buttonNumber\":7,")){
        def $lvl

        if (lights_1_pushed.currentValue('switch').contains('on')){
            $lvl = lights_1_pushed.currentValue("level")
        } else {
            if (lights_2_pushed != null){
                if(lights_1_pushed.currentValue('switch').contains('on')){
                    $lvl = lights_2_pushed.currentValue("level")
                } else if(lights_3_pushed.currentValue('switch').contains('on')){
                    $lvl = lights_3_pushed.currentValue("level")
                }
            }
        }

        $lvl[0] = Math.max(Math.round($lvl[0]*0.66),1)

        if(lights_1_pushed.currentValue('switch').contains('on'))  {
            lights_1_pushed.setLevel($lvl[0])
            log.info "Set $lights_1_pushed to " + $lvl[0] + "%."
        }
        if (lights_2_pushed != null){
            if(lights_2_pushed.currentValue('switch').contains('on'))  {
                lights_2_pushed.setLevel($lvl[0])
                log.info "Set $lights_2_pushed to " + $lvl[0] + "%."
            }
            if(lights_3_pushed.currentValue('switch').contains('on'))  {
                lights_3_pushed.setLevel($lvl[0])
                log.info "Set $lights_3_pushed to " + $lvl[0] + "%."
            }
        }
    }
}

This is code from st, we don't use their button implementation. The value property for our button events is the button number. In your event handler you have if button number starts with, which won't ever match our button value.

You should see the button number from the event in live logging when you press the button.
If you don't then the button isnt actually sending what it should be. Which button device and driver are you using?

Thanks, but I'm missing something. Does something in the button event capture need to change?:

def buttonEvent(evt){
def buttonNumber = evt.value

...

if(buttonNumber.startsWith("{"buttonNumber":2,")){
if(buttonNumber == 2){

Looking at the live log, it says "button: {"face":1}, value: 2" (for instance). From what you said, I tried variations of "if(buttonNumber == 2)..." where buttonNumber is evt.value. So "value" is 2, but is it "evt.value"?? I read through the forum post like three times, but if it gives me the answer, it's not explaining like I'm five.

It's a Xiaomi Magic Cube, using veeceeoh's driver, but it's showing in the logs as working.

I'm not familure with the driver you mention. The live logs do not necessarily reflect the actual event that the device produces, these are shown in the events link in the driver details.
Also the value may be a string, though it is specified as a number so 2 (as an integer) does not = "2" (as a string), since you're using a custom driver I would recommend pinging the author on how to use it.

I'm now getting "Command 'currentValue' is not support by device" for:

if (lights_1_pushed.currentValue('switch').contains('on')){

How do I test the state of a light?

I can't figure out how to test the state of the switches. With the following code, I get:

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

I've tried = instead of contains. ABC uses the same code.

definition(
    name: "MagicCube2",
    namespace: "magicCube1",
    author: "roguetech",
    description: "Control MagicCube",
    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("The Cube") {
            input "buttonDevice", "capability.pushableButton", title: "Button", multiple: false, required: true
        }
        section("90° flip") {
            input "switch_1", "capability.switch", title: "Pushed", multiple: true, required: false
            input "switch_2", "capability.switch", title: "Pushed", multiple: true, required: false
            input "switch_3", "capability.switch", title: "Pushed", multiple: true, required: false
        }
        section("180° flip") {
            input "switch_4", "capability.switch", title: "Pushed", multiple: true, required: false
        }
    }
}

def installed() {
    initialize()
}

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

def initialize() {
    log.debug "INITIALIZED"
    subscribe(buttonDevice, "pushed.1", buttonEvent1)
    subscribe(buttonDevice, "pushed.2", buttonEvent2)
    subscribe(buttonDevice, "pushed.3", buttonEvent3)
    subscribe(buttonDevice, "pushed.6", buttonEvent6)
    subscribe(buttonDevice, "pushed.7", buttonEvent7)
}

def buttonEvent1(evt){
    log.debug "Button 1..."
    def buttonNumber = evt.value

    if (switch_2 != null){
        if (switch_1.currentValue('switch').contains('off') && switch_2.currentValue('switch').contains('off')) {
            switch_1.on()
            log.info "Turned on $switch_1."
        } else if(switch_1.currentValue('switch').contains('on') && switch_2.currentValue('switch').contains('off')) {
            switch_2.on()
            log.info "Turned on $switch_2."
        } else if(switch_1.currentValue('switch').contains('on') && switch_2.currentValue('switch').contains('on')) {
            switch_1.off()
            log.info "Turned off $switch_1."
        } else if(switch_1.currentValue('switch').contains('off') && switch_2.currentValue('switch').contains('on')) {
            switch_2.off()
            log.info "Turned off $switch_2."
        }
    }
}

def buttonEvent2(evt){
    log.debug "Button 2..."
    def buttonNumber = evt.value

    if (switch_2 == null){
        if (switch_1.currentValue('switch').contains('on')){
            switch_1.off()
            log.info "Turned off $switch_1."
        }else{
            switch_1.on()
            log.info "Turned on $switch_1."
        }
    } else {
        if (switch_1.currentValue('switch').contains('on') && switch_2.currentValue('switch').contains('off')) {
            switch_1.off()
            switch_3.off()
            log.info "Turned off $switch_1 and $switch_3."
        }else if(switch_2.currentValue('switch').contains('on') && switch_2.currentValue('switch').contains('on')) {
            switch_2.off()
            log.info "Turned off $switch_2."
        }
    }
}

def buttonEvent3(evt){
    log.debug "Button 3..."
    def buttonNumber = evt.value

    if (switch_4.currentValue('switch').contains('on')){
        switch_4.off()
        log.info "Turned off $switch_4."
    } else if (switch_4.currentValue('switch').contains('off')){
        switch_4.on()
        log.info "Turned on $switch_4."
    }
}

def buttonEvent6(evt){
    log.debug "Button 6..."
    def buttonNumber = evt.value

    def $lvl

    if (switch_1.currentValue('switch').contains('on')){
        $lvl = switch_1.currentValue("level")
    } else {
        if (switch_2 != null){
            if(switch_2.currentValue('switch').contains('on')){
                $lvl = switch_2.currentValue("level")
            } else if(switch_3.currentValue('switch').contains('on')){
                $lvl = switch_3.currentValue("level")
            }
        }
    }

    $lvl[0] = Math.min(Math.round($lvl[0]*1.33+1),100)

    if(switch_1.currentValue('switch').contains('on')) {
        switch_1.setLevel($lvl[0])
        log.info "Set $switch_1 to " + $lvl[0] + "%."
    }
    if (switch_2 != null){
        if(switch_2.currentValue('switch').contains('on')) {
            switch_2.setLevel($lvl[0])
            log.info "Set $switch_2 to " + $lvl[0] + "%."
        }
        if(switch_3.currentValue('switch').contains('on')) {
            switch_3.setLevel($lvl[0])
            log.info "Set $switch_3 to " + $lvl[0] + "%."
        }
    }
}

def buttonEvent7(evt){
    log.debug "Button 7..."
    def buttonNumber = evt.value

    def $lvl

    if (switch_1.currentValue('switch').contains('on')){
        $lvl = switch_1.currentValue("level")
    } else {
        if (switch_2 != null){
            if(switch_1.currentValue('switch').contains('on')){
                $lvl = switch_2.currentValue("level")
            } else if(switch_3.currentValue('switch').contains('on')){
                $lvl = switch_3.currentValue("level")
            }
        }
    }

    $lvl[0] = Math.max(Math.round($lvl[0]*0.66),1)

    if(switch_1.currentValue('switch').contains('on'))  {
        switch_1.setLevel($lvl[0])
        log.info "Set $switch_1 to " + $lvl[0] + "%."
    }
    if (switch_2 != null){
        if(switch_2.currentValue('switch').contains('on'))  {
            switch_2.setLevel($lvl[0])
            log.info "Set $switch_2 to " + $lvl[0] + "%."
        }
        if(switch_3.currentValue('switch').contains('on'))  {
            switch_3.setLevel($lvl[0])
            log.info "Set $switch_3 to " + $lvl[0] + "%."
        }
    }
}

Is a light? If not, how do I test if a light is on?

Your issue above is related to this: "multiple: true" on your inputs. This means that "switch_1" etc is actually a list of devices so you can't ask it for the currentValue, because the system does not know which device in the list you are asking about. If you are only wanting to select one device, change that to "multiple: false" otherwise you need to loop through all the devices in the list until you get to the one you are interested in.

I don't know how to do that, but.....

Thank you thank you thank you!

I can just test on the first light and work out the loop and setting variables for either "any" or "all", depending on what I want for each part.

Download the Hubitat app