Delay of 2+ os.execute >1 second

Moderator: leecollings

Post Reply
Inso
Posts: 7
Joined: Thursday 12 October 2017 23:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Delay of 2+ os.execute >1 second

Post 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.
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post by jvdz »

Just a " &" at the end of your commandline to make it return immediately.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Inso
Posts: 7
Joined: Thursday 12 October 2017 23:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by Inso »

Works like a charm, thank you very much!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest