How do I fix a "Failed to save page" error?


(Joe) #1

So I started messing around with modifying the Switch Changes Mode app and I was able to get it to work mostly. I was trying to add an option to only run in certain modes. Everything works fine in the IDE, but as soon as I publish it, I get an error when saving the configuration.

The error is “Failed to save page: defaultPage

The weird thing is if I hit the back button and say I want to revert my changes, everything saves and works. Any Suggestions?

definition(
    name: "Switch Changes Mode",
    namespace: "Keo",
    author: "Me",
    description: "Ties a mode to a switch's state. Perfect for use with IFTTT.",
    category: "Convenience",
    iconUrl: "https://raw.githubusercontent.com/MichaelStruck/SmartThings/master/IFTTT-SmartApps/App1.png",
    iconX2Url: "https://raw.githubusercontent.com/MichaelStruck/SmartThings/master/IFTTT-SmartApps/App1@2x.png",
    iconX3Url: "https://raw.githubusercontent.com/MichaelStruck/SmartThings/master/IFTTT-SmartApps/App1@2x.png")

preferences {
   	section("Choose a switch to use...") {
		input "controlSwitch", "capability.switch", title: "Switch", multiple: false, required: true
	}
	section("Change to a new mode when...") {
		input "onMode", "mode", title: "Switch is on", required: false
		input "offMode", "mode", title: "Switch is off", required: false 
	}
}

def installed() {
	log.debug "Installed with settings: ${settings}"
    log.debug "Current mode = ${location.mode}"
	subscribe(controlSwitch, "switch", "switchHandler")
}

def updated() {
	log.debug "Updated with settings: ${settings}"
	log.debug "Current mode = ${location.mode}"
	unsubscribe()
	subscribe(controlSwitch, "switch", "switchHandler")
    subscribeToEvents()
}

def switchHandler(evt) {
    log.debug "Current mode = ${location.mode}"
	if (evt.value == "on") {
    	changeMode(onMode)
    } else {
    	changeMode(offMode)
    }
}

def changeMode(newMode) {
    log.debug "new mode = ${newMode}"
    if (newMode && location.mode != newMode) {
         log.debug "Mode = ${location.mode}"
		 if (location.modes?.find{it.name == newMode}) {
			setLocationMode(newMode)
		 }
		 else {
		   log.debug "Unable to change to undefined mode '${newMode}'"
		 }
	}
}

(Joe) #2

commenting out this fixed my problem. I don’t understand why, so could someone explain it to me?


(Kevin Tierney) #3

subscibetoEvents() is looking for a method in your code called subscribetoEvents which is not there.

You are doing your subscribe commands in the installed and updated methods.

If you had a bunch of subscribes to call, you could eliminate the duplication by having a separate subscribeToEvents() method that had all those commands and installed() and updated() would call it


(Joe) #4

Thank you. I am just getting my feet wet with this.