State variable not updating in SmartApp (corrupted?)

@slagle @jody.albritton

The state variable isn’t updating correctly in the smartapp, I’m using the add and remove functions to maintain a list of active devices to monitor. However as you can see from the output below, it doesnt’ seem to update the state variable. I’ve synchronized it using the synchronize(state) call to avoid issues but it will isn’t working. What’s could be going on?

f5a29d30-4baf-4fef-9f06-b52e3fc07e5d 8:52:15 AM: trace Monitor camera list [d2e9dc37-3a4c-43a6-a7a8-f217edefa2c6]
f5a29d30-4baf-4fef-9f06-b52e3fc07e5d 8:52:09 AM: debug Checking Camera Living Room Camera for Active Motion Alarms
f5a29d30-4baf-4fef-9f06-b52e3fc07e5d 8:52:01 AM: trace Updated monitor camera list
f5a29d30-4baf-4fef-9f06-b52e3fc07e5d 8:52:01 AM: trace StopMonitor called for camera Living Room Camera, removing camera d2e9dc37-3a4c-43a6-a7a8-f217edefa2c6 from monitor camera list [d2e9dc37-3a4c-43a6-a7a8-f217edefa2c6]
f5a29d30-4baf-4fef-9f06-b52e3fc07e5d 8:52:04 AM: trace Monitor camera list [d2e9dc37-3a4c-43a6-a7a8-f217edefa2c6]

As you can see above, the monitor list contains a list of cameras id’s. When stop monitor is called and after “updated” list to remove the camera id from the list, it shows up (blank). (great so far)

However the next time Monitor Task is called the list STILL contains the camera id!!

Is the state variable corrupted or is something else going on?

EDIT: For completeness here are the add and remove functions being used:

    synchronized(state) {
        devMonitored = state.cameraList.remove( // remove camera to stop monitoring


    synchronized(state) {
        state.cameraList.add( // add camera to be monitored

I’m getting ROYALLY pissed off and IRRITATED with this platform!

An atomicState variable that is assigned a number in the initialize() function of a SmartApp is BLANK when accessed from another function somewhere else in the app. It seems to behave like a local variable, it seems to have different contexts, when a function is called via a scheduler it seems to have it’s own scope than when it’s accessed via initialize()

Apps that were working earlier are not longer working now.

Isn’t atomicState supposed to be a “global” context variable?? @slagle @jody.albritton

The state variable is also behaving the same way!!! That’s why half the apps no longer work. I can’t RESET the state variable in the updated() function because it has NO effect on it outside the scope of the updated() function. It’s like each function/context has it’s own scope of the state variable.

Come on guys, something so fundamental is breaking is RIDICULOUS! I’m at a COMPLETE loss. Short of uninstalling the app each time there’ no way to reset anything within state from the updated() function of a SmartApp

Use of synchronized aggravates the problem!

synchronized(state) {
state.cameraList.add( // add camera to be monitored

Please talk to @slagle and describe the issue carefully and patiently. He’s on top of this.


Please PM, email, or join our slack channel, without through details on what you are trying to do it’s really hard to help.

1 Like

That’s definitely “not to spec” (if in doubt, the spec is the Documentation, unless @jim has pending updates).

And so it is likely a bug, which you can help @slagle clarify, confirm and escalate.

I can try and help debug. I see the code snippets above, but aside from not needing the synchronized block nothing sticks out from me aside from the other issues we’ve had reported and are working on regarding inconsistent state reads.

If someone has a test app demonstrating the behavior that I can install I can look more.


1 Like

I’ve given @slagle some code to look at. I think I had posted some code on a different thread. Creating new code just to replicate this will take some work. Lets see if Tim can replicate the issue using the code I’ve given him with his cams.

1 Like