Hi all,
I am having trouble developing a scene to resync my hayward pool light and then set a particular color. In order to advance to a different color with the light, you need to toggle it off and then on again. So far, I have a scene that turns the light on, off and then on again to advance to the next color. The light also supports a resync, where you can power it on, then off for 11-14 seconds and then on again to bring the light to color #1. What I’m trying to do is build a series of scenes with luup code to execute the reset and then toggle the light off and on a set number of times to reach a desided color. This is the code that I am trying to use that is based on a scene that I found on the forum. It is not doing the resync, and I am not really sure why. Can anyone help me figure this out? If I’ve gone about this the wrong way, maybe there’s a simpler way to do this.
Thanks,
Bill
>
> local device = 297
> local counter = 6
> local delay = 2
> local resync_delay = 12
>
> function light_on()
>
> luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },device)
>
> luup.call_delay( ‘light_off’, delay )
>
> end
>
> function light_off()
>
> counter = counter-1
>
> if counter > 0
> then
>
> luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },device)
>
> luup.call_delay( ‘light_on’, delay )
>
> end
>
> end
>
> function light_on_once()
> luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },device)
> end
>
> function light_off_once()
> luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },device)
> end
>
>
> function light_resync()
> luup.call_delay( ‘light_on_once’, delay )
> luup.call_delay( ‘light_off_once’, delay )
> luup.call_delay( ‘light_on_once’, resync_delay )
> end
>
> light_resync()
> light_off()
Your three delays in resync()
don’t run in sequence, they run contemporaneously. So light_on_once
and light_off_once
are both being called at the same time. luup.call_delay()
schedules the callback for the delay you specified and then returns immediately, so there’s virtually no delay there between the calls.
Try:
function light_resync()
luup.call_delay( ‘light_on_once’, delay )
luup.call_delay( ‘light_off_once’, delay*2 )
luup.call_delay( ‘light_on_once’, delay*2 + resync_delay )
end
Thanks! That did the trick. Here’s the code that I worked out for setting the light color. I still have to do some testing and I’m sure it could be better written but hopefully it will help someone out.
-- Programs
-- 1 Voodoo Lounge
-- 2 Deep Blue Sea
-- 3 Royal Blue
-- 4 Afternoon Skies
-- 5 Aqua Green
-- 6 Emerald
-- 7 Cloud White
-- 8 Warm Red
-- 9 Flamingo
-- 10 Vivid Violet
-- 11 Sangria
-- 12 Twilight
-- 13 Tranquility
-- 14 Gemstone
-- 15 USA
-- 16 Mardi Gras
-- 17 Cool Cabaret
local device = 297
-- Set counter to program from list above
local counter = 8
local delay = 1.5
local resync_delay = 12
local new_delay = 0
function light_on()
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },device)
end
function light_off()
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },device)
end
--resync the lights
luup.call_delay( 'light_on', new_delay )
luup.call_delay( 'light_off', delay )
new_delay = delay + 2 + resync_delay
luup.call_delay( 'light_on', new_delay )
while counter > 1 do
counter = counter-1
new_delay = new_delay + delay
luup.call_delay( 'light_off', new_delay )
new_delay = new_delay + delay
luup.call_delay( 'light_on', new_delay )
end