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}'"
}
}
}