When passing parameters via the href command when there is more than one section, it’s broken in Android.
This is difficult to explain but the end result is if you have a loop for input parameters and you want to pass the parameters to the href page it doesn’t work on Android. It works perfectly on iOS.
Try this simple test example
definition(
name: "Test HREF App",
namespace: "smartthings",
author: "SmartThings",
description: "Test HREF Pages",
category: "SmartThings Labs",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/App-LightUpMyWorld.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/App-LightUpMyWorld@2x.png"
)
preferences {
page(name: "main")
page(name: "testPage")
}
def main() {
dynamicPage(name: "main", title: "HREF Test", uninstall: true, install: true) {
for (int i = 1; i <= 5; i++) {
def priorName = settings."userNames${i}"
section("User #${i}") {
if (priorName) {
input name: "userNames${i}", description: "${priorName}", title: "Name", defaultValue: priorName, type: "text", multiple: false, required: false, submitOnChange: true
} else {
input name: "userNames${i}", description: "Tap to set", title: "Name", type: "text", multiple: false, required: false, submitOnChange: true
}
def hrefParams = [
user: i as String,
passed: true
]
log.trace "$i Params: $hrefParams"
href(name: "testPage", params: hrefParams, title: "Click here to define actions for ${settings."userNames${i}"}", page: "testPage", description: "", required: false)
}
}
section("Mode Change Open Door/Window/Switch Notification") {
def modes = location.modes
for (mode in modes) {
// Unlock actions for each mode
def hrefParams1 = [
user: mode as String,
passed: true
]
href(name: "modeDoorMonitor", params: hrefParams1, title: "When switching to mode ${mode}", page: "testPage", description: "", required: false)
}
}
}
}
def testPage(params) {
// params is broken, after doing a submitOnChange on this page, params is lost. So as a work around when this page is called with params save it to state and if the page is called with no params we know it's the bug and use the last state instead
if (params.passed) {
atomicState.params = params // We got something, so save it otherwise it's a page refresh for submitOnChange
}
def user = atomicState.params?.user ?: ""
def name = user ? settings."userNames${user}" : ""
log.trace "Actions Page, user:$user, name:$name, passed params: $params, saved params:$atomicState.params"
dynamicPage(name:"testPage", title: "Setup actions for each door" + (user ? " for user $name." : ""), uninstall: false, install: false) {
section {
input "userOverrideUnlockActions${user}", "bool", title: "Define specific actions for $name", required: true, submitOnChange: true
}
}
}
def initialize() {
}
def updated() {
}
@slagle @jody.albritton I’ve reported this to support ticket number 195968
Am I doing this incorrectly or is just a broken Android behavior?