To my absolute shock, this worked for me. I was only expecting this to work from a driver, as it was my assumption that you would need information like the node ID that the hub handles for you, but it turns out that the method signature you find that lets you specify it does indeed work. I wrote this little app to test setting the selected dimmer to 1%, and it works:
definition(
name: "Test App (With Button)",
namespace: "RMoRobert",
author: "Robert Morris",
description: "Minimal test app",
category: "Convenience",
iconUrl: "",
iconX2Url: "",
iconX3Url: ""
)
preferences {
page name: "pageMainPage"
}
def pageMainPage() {
dynamicPage(name: "pageMainPage", install: true, uninstall: true) {
section("Test App") {
input name: "dev1", type: "capability.switchLevel", title: "Select device:", submitOnChange: true
input name: "btn1", type: "button", title: "Push Me!"
}
}
}
void appButtonHandler(String btn) {
switch (btn) {
case "btn1":
Short targetLevel = 0x01
hubitat.zwave.Command cmd = new hubitat.zwave.commands.switchmultilevelv1.SwitchMultilevelSet(value: targetLevel)
hubitat.device.HubAction hubAction = new hubitat.device.HubAction(cmd.format(), hubitat.device.Protocol.ZWAVE, dev1.deviceNetworkId)
log.trace "doing sendHubCommand for hubAction: $hubAction"
sendHubCommand(hubAction)
break
default:
log.warn "Unhandled button: $btn"
}
}
Perhaps even more shockingly, it works even with secure devices. I was expecting to need to use zwaveSecureEncap()
like you do in a driver (and was expecting that to fail since the app probably wouldn't have the data it needs, if this method is even implemented there at all), but either the platform handles this on its own, or there is something going on with the fact that I left the "lower" grants selected (as I usually do) when pairing an S2 Authenticated device I tested this with.
So, in case you haven't figured anything out already, it looks like this might actually work. Now, if someone could tell me why, particularly in the secure case... 