How to capture and return to previous state


#1

1) Give a description of the problem
Looking to capture the state of some lighting devices, indicate an alarm change, and then return to that previous state. In the process there of learning about how capturing state function works.

2) What is the expected behaviour?
To capture the state of the devices, indicate a an alarm change and return to previous state

3) What is happening/not happening?
Just want to make sure the syntax is correct and piston has been built correctly.

**4) Post a Green Snapshot of the piston!

5) Attach logs after turning logging level to Full
n.a.

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

I would capture/restore Level, Switch, plus one of the following:

  • Color
    or
  • colorTemp
    or
  • Hue, Saturation

The logic behind this is there is usually contradictory data between the three listed above, so trying to restore all of them will usually return the incorrect color.


On an unrelated note:
Keep in mind that “Set level to 0%” does not actually change the level. It only sends an “Off” command. The level will remain at 100% until a new level command is sent.

If you are trying to dim the lights to prepare it for the future, then “Set level to 1%” does the trick.


#3

Thank you for the tip on the Set level!

I have not had a chance to test this piston yet so dont have any real world feedback just yet. My bigger looming question is that simply choosing to “capture… to local state” and “restore… from local state” will work just fine? I have seen a few example pistons and they seem to capture/restore to a folder or another something and wasnt sure if that was needed in this case or how that even worked.


#4

It is supposed to… but personally, I usually create variables, and store the dataPoints there.

temp

and then later in the code:

temp


#5

That’s the part I am interested about learning more about! Can you provide some more info about how to go about that? What type of variable do you create, how can you use it elsewhere, etc?


#6

Coming back to this for an issue. This appears to be working however when the piston finishes execution RGB Bulb 1 (out of the 3x in the piston) will not restore. Just want to make sure that at first glance all of this looks right?


#7

There is no reference to RGB Bulb 1 anywhere in your code above. (only 2, 3 & 6)


#8

Sorry, in my head was thinking first one so typed #1, its RGB Bulb 2 in that piston.


#9

Bump, still have RGB Bulb #2 that does not return to original state. Havent ran the piston in a minute but otherwise syntax wise the piston looks correct?


#10

To diagnose, we’d need to see your piston with Trace turned on, and logging to Full during an error…


#11

Ran it this morning, same issue. just RGB #2 (kitchen sink bulb) remains on after its all done

Logs below

10/11/2019, 8:00:48 AM +308ms
+1ms ╔Received event [Home Master].time = 1570795246650 with a delay of 1658ms
+241ms ║RunTime Analysis CS > 78ms > PS > 121ms > PE > 42ms > CE
+244ms ║Runtime (47329 bytes) successfully initialized in 121ms (v0.3.110.20191009) (242ms)
+245ms ║╔Execution stage started
+272ms ║║Restoring attribute ‘hue’ to value ‘33.0’ using command setHue(33.0)
+282ms ║║Executed physical command [Kitchen Sink Bulb].setHue([33.0]) (10ms)
+293ms ║║Restoring attribute ‘level’ to value ‘60’ using command setLevel(60)
+303ms ║║Executed physical command [Kitchen Sink Bulb].setLevel([60]) (9ms)
+313ms ║║Restoring attribute ‘saturation’ to value ‘100’ using command setSaturation(100)
+322ms ║║Executed physical command [Kitchen Sink Bulb].setSaturation([100]) (7ms)
+325ms ║║Restoring attribute ‘switch’ to value ‘on’ using command on()
+334ms ║║Executed physical command [Kitchen Sink Bulb].on() (9ms)
+335ms ║║Executed virtual command [Kitchen Sink Bulb].loadStateLocally (74ms)
+348ms ║║Restoring attribute ‘hue’ to value ‘270.0’ using command setHue(270.0)
+4901ms ║║Executed physical command [Living Room Couch LED].setHue([270.0]) (4551ms)
+4911ms ║║Restoring attribute ‘level’ to value ‘30’ using command setLevel(30)
+4949ms ║║Executed physical command [Living Room Couch LED].setLevel([30]) (37ms)
+4960ms ║║Restoring attribute ‘saturation’ to value ‘76’ using command setSaturation(76)
+4976ms ║║Executed physical command [Living Room Couch LED].setSaturation([76]) (14ms)
+4979ms ║║Restoring attribute ‘switch’ to value ‘off’ using command off()
+4983ms ║║Skipped execution of physical command [Living Room Couch LED].off([]) because it would make no change to the device. (3ms)
+4984ms ║║Executed virtual command [Living Room Couch LED].loadStateLocally (4647ms)
+4996ms ║║Restoring attribute ‘hue’ to value ‘270.0’ using command setHue(270.0)
+5018ms ║║Executed physical command [Living Room TV Backlight].setHue([270.0]) (20ms)
+5029ms ║║Restoring attribute ‘level’ to value ‘30’ using command setLevel(30)
+5059ms ║║Executed physical command [Living Room TV Backlight].setLevel([30]) (29ms)
+5069ms ║║Restoring attribute ‘saturation’ to value ‘76’ using command setSaturation(76)
+5087ms ║║Executed physical command [Living Room TV Backlight].setSaturation([76]) (16ms)
+5090ms ║║Restoring attribute ‘switch’ to value ‘off’ using command off()
+5094ms ║║Skipped execution of physical command [Living Room TV Backlight].off([]) because it would make no change to the device. (3ms)
+5095ms ║║Executed virtual command [Living Room TV Backlight].loadStateLocally (109ms)
+5113ms ║║Comparison (time) 28853406 is_between (time) 28800000 … (time) 0 = true (11ms)
+5115ms ║║Time restriction check passed
+5117ms ║║Condition #29 evaluated true (18ms)
+5118ms ║║Condition group #21 evaluated true (state did not change) (20ms)
+5119ms ║║Cancelling statement #21’s schedules…
+5213ms ║║Executed virtual command sendSMSNotification (84ms)
+5223ms ║║Executed virtual command sendSMSNotification (2ms)
+5233ms ║║Executed virtual command sendSMSNotification (1ms)
+5236ms ║║Cancelling statement #32’s schedules…
+5249ms ║║Executed virtual command executePiston (9ms)
+5253ms ║║Executed virtual command wait (0ms)
+5254ms ║║Requesting a wake up for Fri, Oct 11 2019 @ 8:01:03 AM EDT (in 10.0s)
+5258ms ║╚Execution stage complete. (5013ms)
+5259ms ║Setting up scheduled job for Fri, Oct 11 2019 @ 8:01:03 AM EDT (in 9.996s)
+5266ms ╚Event processed successfully (5266ms)


#12

That is correct. The other two bulbs were instructed to turn OFF…
…but they were already off, so no command was sent.
(as seen below)


If you think OFF was the wrong attribute to restore, you’d have to analyze the log from a minute earlier. (7:59:35)