Flash Multiple Hue Bulbs Simultaneously


#1

1) Give a description of the problem
I would like to flash multiple Hue bulbs at once, but not all the same colors at the same time

2) What is the expected behaviour?
All three bulbs will enter the flash pattern simultaneously

3) What is happening/not happening?
Only one bulb is flashing first, then the next

**4) Post a Green Snapshot of the piston

5) Attach logs after turning logging level to Full
There’s a lot of log, do you really need it if it’s obvious in the code what I’m doing wrong?

I’ve tried setting the ‘IF’ to asynchronous but that didn’t work. Probably because that only affects the ‘IF’ side and not the ‘then’ side?

The key here is I want them to flash different colors at the same time, otherwise I would just add them all to the same ‘WITH’ group.

Thanks in advance!


#2

change the three for ($index = 0 to 10 step 1) to asynchronous

async for ($index = 0 to 10 step 1)


#3

Is this what you mean? I tried this but this doesn’t work. Only the first light comes on still.

Thanks!


#4

not what I meant…sorry.

just edit the first piston you had, click on each of the three for lines and then click the cogwheel and change each of them to async.


#5

Ok, I tried this, same thing happens. Only the first bulb starts the colors, the other two remain the same until the first one finishes its flash pattern

Here’s some of the log. As you can see, it’s only commanding the first bulb.

2/28/2020, 9:28:09 PM +87ms
+1ms ╔Received event [Home].time = 1582954089325 with a delay of -238ms
+52ms ║RunTime Analysis CS > 21ms > PS > 8ms > PE > 23ms > CE
+55ms ║Runtime (42597 bytes) successfully initialized in 8ms (v0.3.110.20191009) (53ms)
+56ms ║╔Execution stage started
+76ms ║║Cancelling statement #6's schedules...
+105ms ║║Executed physical command [Family Room 1].setColor([[hex: #0000FF, hue:67, saturation:100, level:50]]) (14ms)
+116ms ║║Executed physical command [Family Room 1].setColor([[hex: #B22222, hue:0, saturation:68, level:42]], [delay: 2000]) (11ms)
+122ms ║║Executed physical command [Family Room 1].setColor([[hex: #0000FF, hue:67, saturation:100, level:50]], [delay: 4000]) (5ms)
+139ms ║║Executed physical command [Family Room 1].setColor([[hex: #B22222, hue:0, saturation:68, level:42]], [delay: 6000]) (16ms)
+146ms ║║Executed physical command [Family Room 1].on([delay: 8099]) (5ms)
+147ms ║║Executed virtual command [Family Room 1].flashColor (62ms)
+148ms ║║Requesting a wake up for Fri, Feb 28 2020 @ 9:28:17 PM PST (in 8.1s)
+153ms ║╚Execution stage complete. (98ms)
+154ms ║Setting up scheduled job for Fri, Feb 28 2020 @ 9:28:17 PM PST (in 8.096s)
+167ms ╚Event processed successfully (166ms)
2/28/2020, 9:28:01 PM +69ms
+1ms ╔Received event [Home].time = 1582954081444 with a delay of -375ms
+86ms ║RunTime Analysis CS > 56ms > PS > 6ms > PE > 24ms > CE
+89ms ║Runtime (42597 bytes) successfully initialized in 6ms (v0.3.110.20191009) (87ms)
+90ms ║╔Execution stage started
+125ms ║║Executed physical command [Family Room 1].setColor([[hex: #008000, hue:33, saturation:100, level:25]]) (6ms)
+133ms ║║Executed physical command [Family Room 1].setColor([[hex: #FFFF00, hue:17, saturation:100, level:50]], [delay: 2000]) (8ms)
+140ms ║║Executed physical command [Family Room 1].setColor([[hex: #008000, hue:33, saturation:100, level:25]], [delay: 4000]) (5ms)
+147ms ║║Executed physical command [Family Room 1].setColor([[hex: #FFFF00, hue:17, saturation:100, level:50]], [delay: 6000]) (6ms)
+153ms ║║Executed physical command [Family Room 1].on([delay: 8099]) (5ms)
+154ms ║║Executed virtual command [Family Room 1].flashColor (40ms)
+155ms ║║Requesting a wake up for Fri, Feb 28 2020 @ 9:28:09 PM PST (in 8.1s)
+160ms ║╚Execution stage complete. (70ms)
+161ms ║Setting up scheduled job for Fri, Feb 28 2020 @ 9:28:09 PM PST (in 8.095s)
+168ms ╚Event processed successfully (168ms)
2/28/2020, 9:27:53 PM +130ms
+0ms ╔Received event [Home].time = 1582954074961 with a delay of -1832ms
+50ms ║RunTime Analysis CS > 23ms > PS > 7ms > PE > 20ms > CE
+52ms ║Runtime (42598 bytes) successfully initialized in 7ms (v0.3.110.20191009) (51ms)
+54ms ║╔Execution stage started
+65ms ║║Cancelling statement #3's schedules...
+151ms ║║Executed virtual command iftttMaker (81ms)
+156ms ║║Cancelling statement #6's schedules...
+184ms ║║Executed physical command [Family Room 1].setColor([[hex: #0000FF, hue:67, saturation:100, level:50]]) (13ms)
+191ms ║║Executed physical command [Family Room 1].setColor([[hex: #B22222, hue:0, saturation:68, level:42]], [delay: 2000]) (5ms)
+198ms ║║Executed physical command [Family Room 1].setColor([[hex: #0000FF, hue:67, saturation:100, level:50]], [delay: 4000]) (6ms)
+203ms ║║Executed physical command [Family Room 1].setColor([[hex: #B22222, hue:0, saturation:68, level:42]], [delay: 6000]) (4ms)
+211ms ║║Executed physical command [Family Room 1].on([delay: 8099]) (7ms)
+212ms ║║Executed virtual command [Family Room 1].flashColor (45ms)
+213ms ║║Requesting a wake up for Fri, Feb 28 2020 @ 9:28:01 PM PST (in 8.1s)
+217ms ║╚Execution stage complete. (164ms)
+219ms ║Setting up scheduled job for Fri, Feb 28 2020 @ 9:28:01 PM PST (in 8.096s)
+226ms ╚Event processed successfully (226ms)
2/28/2020, 9:27:44 PM +887ms
+2ms ╔Received event [MrRoboto].switch = on with a delay of 70ms
+51ms ║RunTime Analysis CS > 21ms > PS > 7ms > PE > 23ms > CE
+54ms ║Runtime (42593 bytes) successfully initialized in 7ms (v0.3.110.20191009) (51ms)
+55ms ║╔Execution stage started
+63ms ║║Comparison (enum) on changes_to (string) on = true (0ms)
+64ms ║║Cancelling condition #16's schedules...
+65ms ║║Condition #16 evaluated true (6ms)
+66ms ║║Cancelling condition #15's schedules...
+67ms ║║Condition group #15 evaluated true (state changed) (8ms)
+69ms ║║Cancelling statement #17's schedules...
+72ms ║║Executed virtual command wait (0ms)
+74ms ║║Requesting a wake up for Fri, Feb 28 2020 @ 9:27:54 PM PST (in 10.0s)
+78ms ║╚Execution stage complete. (23ms)
+79ms ║Setting up scheduled job for Fri, Feb 28 2020 @ 9:27:54 PM PST (in 9.995s)
+98ms ╚Event processed successfully (98ms)

#6

I offer a mathematical perspective:

  • 3 Bulbs are being controlled
  • Each Flash command is actually four (hex, hue, saturation, level)

So every two seconds, you want 12 commands issued, with a new color each time.
This means it will take 16 seconds (84 commands) to complete one cycle.

… and then (let me get this straight), you want to loop this all 11 times?

Sooo, you want 924 commands to be sent over a 2 min 56 sec time period?!?

Please be aware that if you decide to stick with this logic, then your entire SmartHome will be sluggish for 3 minutes, and all other pistons that try to run during that period will be negatively impacted


I will be honest… No matter how fancy your code looks when you are done, no matter how elegant your looping may end up, you can practically guarantee that it will get out of sync nearly every single time it runs.

For reference, IF your SmartHome was 99% reliable, (which is not an easy achievement), then statistically it would falter 9 times out of 924…

For what it’s worth, I have a “Notification” light in my house that changes colors as alerts come in, and I can say personally, I find that even a ten second flash verges on being too long for me. Most of my alerts have been reduced to 8 seconds or less, before the piston returns the bulb to it’s normal color.

Do with that what you will


#7

I’d be prepared to heed @WCmore’s advice, but if you want to suck it and see anyway …

Try bringing all three ‘with’ tasks into the one ‘for’ loop as you did in the third post of the thread. Then instead of applying ‘async’ to the ‘for’ loop, apply it to the FIRST TWO ‘with’ statements. Don’t apply it to the third as you need that to provide the timing for the loop.

Should it work (I just thought it looked plausible) you may find that turning off MrRoboto’s switch will bring the piston to a juddering halt before it can hit your last ‘if’ block and tidy things up. That would be a Task Cancellation Policy issue.


#8

Thanks for the information! I actually got it going by breaking it up into 3 separate IF statements, one for each bulb.

As for why I wanted to do it, it was a joke that I only needed to make work when my mother came to visit for the weekend. I had gotten, as you can see in the code, a new Roomba. She suggested I name it Mr. Roboto, so I created a custom routine with Google Assistant to reply “my pleasure” when I said “Hey Google, domo arigato Mr. Roboto”. It would then start the Roomba, turn on a virtual switch which was tied to starting this routine, and start playing “Mr. Roboto” by Styx. The lights were flashing as if they were stage lights at a concert, and the Roomba would back off the dock at the right time. It was all quite fantastic and good for a laugh with some family and has since been deleted :slight_smile: