Async confusion


#1

1) Give a description of the problem
Want two lights to flash asynchronously. This would be part of a bigger piston. Basically I want to flash my pool light and the backyard light on/off several times when my personal weather station detects lightning in the area.

If I have a with block for each light, then the first light does its flashing sequence, then the second. I’ve tried adding async in various places but can’t seem to get the two blocks to execute asynchronously. If this was C# it would be a trivial thing to do. I realize it isn’t, but surely I’m missing something here.

2) What is the expected behaviour?
The two lights would flash the specified number of times

3) What is happening/not happening?
They don’t flash the correct number of times, don’t return to their original state and/or don’t stay on or off for the specified number of seconds.

**4) Post a Green Snapshot of the piston![image|45x37]![piston1|690x232]

5) Attach logs after turning logging level to Full
10/21/2020, 12:47:35 PM +142ms
+0ms ╔Received event [DFB House].time = 1603298852471 with a delay of 2670ms
+119ms ║RunTime Analysis CS > 64ms > PS > 39ms > PE > 16ms > CE
+121ms ║Runtime (37044 bytes) successfully initialized in 39ms (v0.3.110.20191009) (120ms)
+122ms ║╔Execution stage started
+1191ms ║║Executed physical command [Office Fan Light].off() (1065ms)
+1211ms ║║Executed physical command [Dog Cabinet].off() (15ms)
+1226ms ║║Executed physical command [Office Fan Light].off() (10ms)
+1234ms ║╚Execution stage complete. (1112ms)
+1236ms ╚Event processed successfully (1235ms)
10/21/2020, 12:47:27 PM +118ms
+1ms ╔Received event [DFB House].time = 1603298846439 with a delay of 679ms
+175ms ║RunTime Analysis CS > 70ms > PS > 90ms > PE > 15ms > CE
+178ms ║Runtime (37043 bytes) successfully initialized in 90ms (v0.3.110.20191009) (175ms)
+179ms ║╔Execution stage started
+741ms ║║Executed physical command [Dog Cabinet].off() (557ms)
+3886ms ║║Executed physical command [Office Fan Light].off() (3140ms)
+3903ms ║║Executed physical command [Dog Cabinet].on() (13ms)
+3919ms ║║Executed physical command [Office Fan Light].on() (11ms)
+3920ms ║║Fast executing schedules, waiting for 1402ms to sync up
+5343ms ║║Executed physical command [Dog Cabinet].off() (12ms)
+5344ms ║╚Execution stage complete. (5166ms)
+5346ms ║Setting up scheduled job for Wed, Oct 21 2020 @ 12:47:32 PM EDT (in 1s), with 3 more jobs pending
+5351ms ╚Event processed successfully (5351ms)
10/21/2020, 12:47:24 PM +148ms
+1ms ╔Received event [DFB House].time = 1603298843439 with a delay of 709ms
+86ms ║RunTime Analysis CS > 36ms > PS > 39ms > PE > 11ms > CE
+88ms ║Runtime (37042 bytes) successfully initialized in 39ms (v0.3.110.20191009) (87ms)
+89ms ║╔Execution stage started
+107ms ║║Executed physical command [Dog Cabinet].on() (13ms)
+124ms ║║Executed physical command [Office Fan Light].on() (11ms)
+126ms ║╚Execution stage complete. (37ms)
+129ms ║Setting up scheduled job for Wed, Oct 21 2020 @ 12:47:26 PM EDT (in 2.162s), with 8 more jobs pending
+135ms ╚Event processed successfully (135ms)
10/21/2020, 12:47:20 PM +86ms
+1ms ╔Received event [DFB House].time = 1603298840439 with a delay of -353ms
+95ms ║RunTime Analysis CS > 40ms > PS > 34ms > PE > 20ms > CE
+97ms ║Runtime (37043 bytes) successfully initialized in 34ms (v0.3.110.20191009) (96ms)
+98ms ║╔Execution stage started
+125ms ║║Executed physical command [Dog Cabinet].off() (20ms)
+130ms ║║Fast executing schedules, waiting for 254ms to sync up
+1311ms ║║Executed physical command [Office Fan Light].off() (923ms)
+1314ms ║╚Execution stage complete. (1216ms)
+1318ms ║Setting up scheduled job for Wed, Oct 21 2020 @ 12:47:23 PM EDT (in 2.036s), with 10 more jobs pending
+1326ms ╚Event processed successfully (1326ms)
10/21/2020, 12:47:17 PM +110ms
+1ms ╔Received event [DFB House].time = 1603298837439 with a delay of -329ms
+67ms ║RunTime Analysis CS > 22ms > PS > 27ms > PE > 18ms > CE
+69ms ║Runtime (37043 bytes) successfully initialized in 27ms (v0.3.110.20191009) (68ms)
+70ms ║╔Execution stage started
+95ms ║║Executed physical command [Dog Cabinet].on() (19ms)
+97ms ║║Fast executing schedules, waiting for 261ms to sync up
+380ms ║║Executed physical command [Office Fan Light].on() (18ms)
+383ms ║╚Execution stage complete. (313ms)
+386ms ║Setting up scheduled job for Wed, Oct 21 2020 @ 12:47:20 PM EDT (in 2.943s), with 12 more jobs pending
+393ms ╚Event processed successfully (393ms)
10/21/2020, 12:47:14 PM +132ms
+0ms ╔Received event [DFB House].time = 1603298834438 with a delay of -306ms
+77ms ║RunTime Analysis CS > 23ms > PS > 38ms > PE > 15ms > CE
+80ms ║Runtime (37043 bytes) successfully initialized in 38ms (v0.3.110.20191009) (78ms)
+81ms ║╔Execution stage started
+260ms ║║Executed physical command [Dog Cabinet].off() (172ms)
+263ms ║║Fast executing schedules, waiting for 73ms to sync up
+354ms ║║Executed physical command [Office Fan Light].off() (15ms)
+358ms ║╚Execution stage complete. (278ms)
+363ms ║Setting up scheduled job for Wed, Oct 21 2020 @ 12:47:17 PM EDT (in 2.945s), with 14 more jobs pending
+370ms ╚Event processed successfully (370ms)
10/21/2020, 12:47:11 PM +61ms
+0ms ╔Received event [DFB House].time = 1603298831438 with a delay of -378ms
+43ms ║RunTime Analysis CS > 14ms > PS > 20ms > PE > 10ms > CE
+45ms ║Runtime (37043 bytes) successfully initialized in 20ms (v0.3.110.20191009) (44ms)
+46ms ║╔Execution stage started
+67ms ║║Executed physical command [Dog Cabinet].on() (15ms)
+71ms ║║Fast executing schedules, waiting for 335ms to sync up
+427ms ║║Executed physical command [Office Fan Light].on() (15ms)
+432ms ║╚Execution stage complete. (386ms)
+437ms ║Setting up scheduled job for Wed, Oct 21 2020 @ 12:47:14 PM EDT (in 2.941s), with 16 more jobs pending
+451ms ╚Event processed successfully (451ms)
10/21/2020, 12:47:08 PM +485ms
+0ms ╔Received event [DFB House].time = 1603298828438 with a delay of 47ms
+64ms ║RunTime Analysis CS > 18ms > PS > 28ms > PE > 17ms > CE
+67ms ║Runtime (37041 bytes) successfully initialized in 28ms (v0.3.110.20191009) (66ms)
+68ms ║╔Execution stage started
+443ms ║║Executed physical command [Dog Cabinet].off() (367ms)
+481ms ║║Executed physical command [Office Fan Light].off() (33ms)
+485ms ║╚Execution stage complete. (417ms)
+490ms ║Setting up scheduled job for Wed, Oct 21 2020 @ 12:47:11 PM EDT (in 2.464s), with 18 more jobs pending
+497ms ╚Event processed successfully (497ms)
10/21/2020, 12:47:05 PM +314ms
+1ms ╔Received event [DFB House].test = 1603298825314 with a delay of 0ms
+69ms ║RunTime Analysis CS > 24ms > PS > 27ms > PE > 18ms > CE
+72ms ║Runtime (37040 bytes) successfully initialized in 27ms (v0.3.110.20191009) (70ms)
+73ms ║╔Execution stage started
+78ms ║║Cancelling statement #1’s schedules…
+111ms ║║Executed physical command [Dog Cabinet].on() (17ms)
+127ms ║║Executed virtual command [Dog Cabinet].flash (40ms)
+152ms ║║Executed physical command [Office Fan Light].on() (17ms)
+158ms ║║Executed virtual command [Office Fan Light].flash (29ms)
+160ms ║║Requesting a wake up for Wed, Oct 21 2020 @ 12:47:35 PM EDT (in 30.1s)
+188ms ║╚Execution stage complete. (115ms)
+203ms ║Setting up scheduled job for Wed, Oct 21 2020 @ 12:47:08 PM EDT (in 2.922s), with 20 more jobs pending
+210ms ╚Event processed successfully (210ms)


#2

Quick Answer:

Every single thing in SmartThings is synchronous(One step at a time)

The ASYNC is an illusion that goes on to the next task when a WAIT begins.


#3

So there’s no way to flash multiple lights simultaneously?


#4

That was an interesting log. It did actually do everything it was supposed to, except with a couple of extra offs at the end for no obvious reason. The timings were getting a bit screwed up by then so the piston was doing well to sort itself out.

I’ve never played with flashing lights, but it seems to me that three seconds is quite a small delay to work with on SmartThings, especially when working with two lights. It is unremarkable when cloud latency drifts to a second or two, and timers often run a fraction of a second early, so there isn’t a lot of wriggle room there.


#5

Yes, the logs make no sense to me. And I get it about latency, but if I just flash one light it works fine. Soon as I add a second light, it falls apart. Really hard to imagine that just turning on or off a zwave switch is such an intensive operation that ST can’t handle two devices at once.

I have a rule in alarm.com that turns off all interior lights and fans except the master bedroom when the system switches to armed stay. At least 8 lights and 1 fan, sometimes more. When I arm the system it takes a few seconds for anything to happen but then they all turn off in very quick succession, in only a second or two.

Maybe I’m comparing apples to oranges here, but flashing two lights for a few seconds should be a trivial task but maybe ST just isn’t up to the task.

I don’t care about timer drifts and precise timings, I just want the lights to flash rapidly enough that they will attract attention during the daytime. Maybe yet another reason to consider Hubitat, if the underlying problem is ST’s latency.


#6

Maybe I am “old school”, but if I have the room to code, I often break down the steps manually, instead of using the “emulated flash”.

The code may not “look” as perty, but the end results are usually significantly smoother.
(for example: with hand coding, you can choose the order of the flash) IE:

  • Set Bulb3 to on
  • Wait 1500ms
  • Set Switch1 to on
  • Wait 1500ms
  • Set Bulb3 to off
  • Wait 1500ms
  • Set Switch1 to off
  • Wait 1500ms
    etc

(Copy / paste is your friend)

One bonus result with this method is the manual flash could be aborted if the conditions change.
(unless you want it to push onwards using TCP)


Pro Tip:

Approximately every ten seconds, you can expect a hiccup in the timing… Maybe an extra 2 seconds.
(I try to keep under 9 sec total if precision matters)


#7

I will give that a try. Generally, I assume that a built-in function is preferable because presumably the person who wrote it understands how things work under the hood, and it’s written in an optimal manner. But unless I’m missing something, the documentation for things like ‘flash’ is non existent so maybe it’s not such a good assumption to make.

Ugh. Webcore is cool but I wish I could write stuff in a real language like C#. I’m sure webcore isn’t for that type of audience but I can’t stand all this click and choose stuff.


#8

For a new language, with less than perfect documentation, the popup windows simply assist with the proper syntax & structure.