Page 1 of 1

Delay of 2+ os.execute >1 second

Posted: Friday 13 October 2017 17:23
by Inso
Hi

I have a few Yeelight lamps and a cube. Idea is to execute commands on all lamps simultaniously. At the moment, I have a very small script, which only puts the lamps on and off.

Code: Select all

commandArray = {}

SwitchDevice = 'Xiaomi Cube weiss';
IP1 = '192.168.178.54';
IP2 = '192.168.178.50';
PORT = '55443'

if (devicechanged[SwitchDevice]=='clock_wise') then
     runcommandoff1 = "sudo echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"on\", \"smooth\", 500]}\\r\\n' | nc -w1 "..IP1.." " ..PORT.."";;
      runcommandoff2 = "sudo echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"on\", \"smooth\", 500]}\\r\\n' | nc -w1 "..IP2.." " ..PORT.."";;
os.execute(runcommandoff1);
os.execute(runcommandoff2);
     
 elseif (devicechanged[SwitchDevice]=='anti_clock_wise') then
    runcommandoff1 = "sudo echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"off\", \"smooth\", 500]}\\r\\n' | nc -w1 "..IP1.." " ..PORT.."";;
    runcommandoff2 = "sudo echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"off\", \"smooth\", 500]}\\r\\n' | nc -w1 "..IP2.." " ..PORT.."";;
--     os.execute("runcommandoff1 | runcommandoff2");
    os.execute(runcommandoff1);
    os.execute(runcommandoff2);
end
return commandArray
Problem is the 1+second(s) delay between every os.execute. Does domotics wait for a reply, so maybe there is a fire and forget-option I miss? Or is there any other way to get the lamps react ~simultaniously? (Without working with groups).
I also tried to execute both commands at once

Code: Select all

os.execute("runcommandoff1 | runcommandoff2");
Nothing happens, I do not even get an error.

Re: Delay of 2+ os.execute >1 second

Posted: Friday 13 October 2017 17:33
by jvdz
Just a " &" at the end of your commandline to make it return immediately.

Jos

Re: Delay of 2+ os.execute >1 second

Posted: Friday 13 October 2017 18:17
by Inso
Works like a charm, thank you very much!