Change switch status rapidly

Hi All,

I want to change the color of my pool led spot with a zwave switch. The manual way is to switch on then off and on (Between the last off and on the time is short)

I do this luup script but don’t work. Any one has got an idea ?

the device #12 is my switch.

local test_light=luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",12)

-- I test if my light is off, if it's true I continue

if (test_light == "0") then
local pool_light_on=luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue="1"},12)
luup.call_timer("pool_light_on", 1, "1", "", "") 


local pool_light_off=luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue="0"},12)
luup.call_timer("pool_light_off", 1, "1", "", "")
luup.call_timer("pool_light_on", 1, "1", "", "")
-- normaly the colour is changed, but in that case it doesn't work.
else

-- the led is on, so I'v just had to do off then on

local pool_light_off=luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue="0"},12)
luup.call_timer("pool_light_off", 1, "1", "", "")

local pool_light_on=luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue="1"},12)
luup.call_timer("pool_light_on", 1, "1", "", "")

end

I think it’s possible to do it because I can do it manualy by pressing directly on the dashboard.

Futzle are you somewhere …?

Gilles.

Hi gilles,

Try this code:

function setPoolLight(newValue)
    luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = newValue}, 12)
end

local testLight = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 12)
if (testLight == "0") then
    luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "1"}, 12)
end

luup.call_delay("setPoolLight", 1, "0")
luup.call_delay("setPoolLight", 2, "1")

Thank you,
I will try your code tonight and let you know.

Sent from my GT-I9000

I try yours and it doesn’t work.
I hope 0,5 secondes isn’t needeed, between an off - on.

Surprisly it’s working when I launch the scene then I click ok in the message box an re-click on the scene a 1/2 seconde later.

Any idea ?

My idea is to find how to launch an instruction a 1/2 secondes later.

Sent from my Flashback 7.1 using Tapatalk

I tested it and it worked for me.
The only way to launch an instruction 0.5 seconds later is to use [tt]luup.sleep(500)[/tt] before that instruction.

Hi mcvflorin,

My apologies, the script works but the color doesn’t change. It’s funny, I search in lua language the sleep function and you give it to me.

Thank you, I’ll try and think it will work. From now I have to do some tests and find the right time.

I will give you some news.

Thank you.

Yehaaa !

it works with a sleep at 200 ms.

thank you very much, from now I can change the color of my pool easily and that makes me happy.

Sent from my GT-I9000