Thanks for these helpful suggestions rlkoshak.
I suppose I was exaggerating a little when I claimed 2 seconds… To toggle power on three LIFX bulbs, it takes a little over .5 seconds. Add in the two outlets and we’re at more like 1 second. The speed is a frustration, but more-so that all the Items switch at different times.
The goals for this exercise:
LIFX Lights: function similar to the LIFX app - very quick and exactly simultaneous switching of Items. Third-party apps using the LIFX LAN Protocol can also accomplish this (LIFX Tasker Plugin, AutoHue on Android).
Orbivo Switches: quick and reliable execution, does not need to be exactly simultaneous.
-
Instead of sending the command to the group, send it to reach member individually. MyGroup.members.forEach[i | I.sendCommand(OFF)]
This appears to be equivalent to MyGroup.sendCommand(). The Items fire in the same order, and in (as far as I can tell) the same speed.
-
Create a separate rule fur each light that triggers on the same event. Each rule runs in parallel.
This is very slightly faster than MyGroup.sendCommand(). The Items fire in random order and at random intervals.
-
Create a timer that goes off in 50 msec or so and send the command from the timer. Timers run in a separate thread.
I tried a few solutions here:
3.1
var DateTime targetTime = now.plusMillis(1000)
createTimer(targetTime) [| sendCommand(LIFX_63_color, receivedCommand) ]
createTimer(targetTime) [| sendCommand(LIFX_00_color, receivedCommand) ]
createTimer(targetTime) [| sendCommand(LIFX_2C_color, receivedCommand) ]
createTimer(targetTime) [| sendCommand(Orvibo_58, receivedCommand)]
createTimer(targetTime) [| sendCommand(Orvibo_C8, receivedCommand)]
With this code, only Orvibo_C8 fired.
3.2
createTimer(now.plusMillis(50)) [| sendCommand(LIFX_63_color, receivedCommand) ]
createTimer(now.plusMillis(50)) [| sendCommand(LIFX_00_color, receivedCommand) ]
createTimer(now.plusMillis(50)) [| sendCommand(LIFX_2C_color, receivedCommand) ]
createTimer(now.plusMillis(50)) [| sendCommand(Orvibo_58, receivedCommand)]
createTimer(now.plusMillis(50)) [| sendCommand(Orvibo_C8, receivedCommand)]
This code worked, but not well. This appears to be the slowest solution, probably because of the delay. Items fire in random order. It also seems that if an Item hasn’t fired by 50ms (with each of these solutions there are occasionally longer than normal delays) that it won’t fire at all.
3.4 (createTimers in separate rules)
var DateTime targetTime = null
Setting a single targetTime for all Timers
when
Item FF_Bed_Lights_Sw5 received command /* this is the switch in sitemap */
then
targetTime = now.plusMillis(2000)
sendCommand(FF_Bed_Lights_Sw6, receivedCommand) /* this switch only triggers other rules */
end
Multiple rules run in parallel creating Timers based on the original targetTime (one example, total is three LIFX and two Orvibo)
when
Item FF_CB_Bed_Lights_Sw6 received command /* switch triggered above */
then
createTimer(targetTime) [| sendCommand(LIFX_2C_color, receivedCommand)]
end
This fires only one of the Items at random.
My learning from this testing:
- Timers aren’t a good method of creating parallel actions, since only one timer (apparently) can execute at the same time and the rest will silently fail
- OH2 probably internally converts MyGroup.sendCommand() to iterative commands across the group
- It’s possible that the LIFX or Orvibo bindings are restricting the parallel execution. Maybe there is a function on the LAN Protocol that simultaneously changes lights, but the LIFX binding uses iterative changing instead?
I’m not familiar with JSR233, coffee, and Jython. Can you point me in the direction of more info?
Thanks for all your help.