Hey guys!
I am writing a smartapp to perform certain operations when in different “modes”. As of right now, I am testing some really basic functionality which is not working as desired. The flow of control is as follows:
- I ping the HTTP endpoint
changestate/trigger
and so in that function I set the value ofatomicState.currState
to trigger. I have verified this to work because the JSON and sendPush return the correct data. - I then invoke the
contactHandler
method by changing the state of the contact handler. We would expect that “Contact Sensor Handler entered in trigger state” be printed out since theatomicState.currState
is currently trigger (as set above). However, when I log it theatomicState.currState
is somehow still “dummy” and I cannot figure out why.
I have verified already that the initialization function is not called again as well as tried it with state instead of atomic state. I am not sure why this is happening and so I would really appreciate some input. The code that I am using has been shown below:
preferences {
section("Turn on when motion detected:") {
input "contactSensor", "capability.contactSensor", required: true, title: "Which in-motion object?"
}
section("Turn on this light") {
input "lightSwitch", "capability.switch", required: true, title: "Which switch object?"
}
}
mappings {
path("/changestate/:state") {
action: [
GET: "changeState"
]
}
}
def installed() {
initialize()
}
def updated() {
unsubscribe()
initialize()
}
def initialize() {
atomicState.currState = "dummy"
subscribe(contactSensor, "contact", contactHandler)
}
def contactHandler(evt) {
sendPush "Current State: ${atomicState.currState}"
if (atomicState.currState == "trigger") {
sendPush "Contact Sensor Handler entered in trigger state"
} else {
sendPush "Contact Sensor can only be accessed in the trigger state"
}
}
def changeState() {
atomicState.currState = params.state
sendPush "Current State: ${atomicState.currState}"
return [message: "Current State: ${atomicState.currState}"]
}
Thanks!