I can confirm the short version works in a dth, however there’s quite a bit of funk to it
It will not update a setting unless it’s already been set (once), after that it’s fine.
The preferences settings in the UI aren’t updated to match those set in code…
The long version, just sets the pref to null, most awesomely, this is reflected in the ui…
/*
*/
metadata {
definition (name: "updateSettingDTH", namespace: "mmaxwell", author: "mike maxwell") {
capability "Switch"
}
preferences {
input name: "enum1", type: "enum", title: "test enum 1", description: "enum1", required: true, options:["1","0"]
input name: "bool1", type: "bool", title: "test bool 1", description: "bool1", required: true
}
tiles {
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "off", label: '${currentValue}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
state "on", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
}
main "switch"
details(["switch"])
}
}
def on() {
sendEvent(name: "switch", value: "on")
//device.updateSetting("enum1", [type: "enum", value: "1"]) //sets input to null
//device.updateSetting("bool1", [type: "bool", value: true]) //sets input to null
device.updateSetting("enum1","1") //works
device.updateSetting("bool1", true) //works
log.debug "values after ON, enum1:${enum1}, bool1:${bool1}"
}
def off() {
sendEvent(name: "switch", value: "off")
//device.updateSetting("enum1", [type: "enum", value: "0"]) //sets input to null
//device.updateSetting("bool1", [type: "bool", value: false]) //sets input to null
device.updateSetting("enum1","0") //works
device.updateSetting("bool1", false) //works
log.debug "values after OFF, enum1:${enum1}, bool1:${bool1}"
}
def updated(){
log.debug "values after pref set, enum1:${enum1}, bool1:${bool1}"
}
I had assumed that the long version was a map parameter element, maybe device.updateSetting(“bool1”, type: “bool”, value: true) would work, if someone else wants to test this…