Hi,
For some reason, in the scenario below, a state I am setting is not persisting between executions.
If the lights are on and I hit the button (step 1) that triggers dimBtnHandler(evt), state.altStateDim gets set to true. After that execution completes, if I then hit the button (step 2) that triggers offBtnHandler(evt), state.altStateDim gets set to false. After that execution completes, if I then hit the button (step 3) that triggers onBtnHandler(evt), state.altStateDim somehow is set to true even though the last execution set it to false.
If I omit the dim button press from this and just trigger on and off handlers, state.on toggles between true and false, persisting between executions as expected.
I read through the SmartThings documentation on state and picked up no clues as to this behavior. What am I missing?
def initialize() {
state.on = isOn()
state.altStateDim = false
if (onOffBtn && onBtnNum) {
subscribe(onOffBtn, "pushed.${onBtnNum}", onBtnHandler)
}
if (onOffBtn && offBtnNum) {
subscribe(onOffBtn, "pushed.${offBtnNum}", offBtnHandler)
}
if (dimBtn && dimBtnNum) {
subscribe(dimBtn, "pushed.${dimBtnNum}", dimBtnHandler)
}
}
def offBtnHandler(evt) {
log("Off Button Press - Turning Off Bulbs")
state.on = false
state.altStateDim = false
//DEBUGGING*****************************************
log("debug off-press ${state.on} ${state.altStateDim}")
for (bulb in bulbs) {
bulb.off()
}
}
def onBtnHandler(evt) {
log("On Button Press - Turning On Bulbs")
state.on = true
//DEBUGGING*****************************************
log("debug on-press ${state.altStateDim}")
for (bulb in bulbs) {
bulb.on()
}
doOtherStuff()
}
def dimBtnHandler(evt) {
state.altStateDim = true
//DEBUGGING*****************************************
log("debug off-press ${state.altStateDim}")
dim()
}
Here is my actual log. The dim button was hit prior to this:
app:14332021-01-21 09:28:34.428 am info debug on-press before exec state.on true, state.altStateDim true, state.altStateBright false
app:14332021-01-21 09:28:34.414 am info On Button Press - Turning On Bulbs
app:14332021-01-21 09:28:27.470 am info debug off-press after exec state.on false, state.altStateDim false, state.altStateBright false
app:14332021-01-21 09:28:27.377 am info debug off-press before exec state.on true, state.altStateDim true, state.altStateBright false
app:14332021-01-21 09:28:27.370 am info Off Button Press - Turning Off Bulbs
Here's the log with no dim button pressing:
app:14332021-01-21 09:35:39.868 am info debug on-press after exec state.on true, state.altStateDim false, state.altStateBright false
app:14332021-01-21 09:35:39.472 am info debug on-press before exec state.on false, state.altStateDim false, state.altStateBright false
app:14332021-01-21 09:35:39.464 am info On Button Press - Turning On Bulbs
app:14332021-01-21 09:35:37.129 am info debug off-press after exec state.on false, state.altStateDim false, state.altStateBright false
app:14332021-01-21 09:35:37.055 am info debug off-press before exec state.on true, state.altStateDim false, state.altStateBright false
app:14332021-01-21 09:35:37.039 am info Off Button Press - Turning Off Bulbs
app:14332021-01-21 09:35:35.490 am info debug on-press after exec state.on true, state.altStateDim false, state.altStateBright false
app:14332021-01-21 09:35:35.114 am info debug on-press before exec state.on false, state.altStateDim false, state.altStateBright false
app:14332021-01-21 09:35:35.110 am info On Button Press - Turning On Bulbs