Page 1 of 1

Yeelight (execute = function) time delay

Posted: Thursday 17 May 2018 13:47
by Inso80
Hi,

I have some Yeelight lamps and stripes, and use the folowing code to switch my lamp on (includes mode, color and so on)

Code: Select all

	execute = function(domoticz, device)
        IPR1 = {'192.168.178.59'}
        PORT = '55443';
        for n, IP in pairs(IPR1) do
               runcommandoff = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":[\"cf\",4,1,\"500,1,16711680,1,    300000,7,0,0, 300000,2,1700,1, 300000,2,1700,100 \"]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."&";;     
               os.execute(runcommandoff);
  end
end
It is triggered by a human body sensor.
I´d like to delay the time for the switch off command. Atm the HBS switches to off after 1,5min which is the maximum time, and way too fast.
I found functions on the manual as

Code: Select all

-- switch on for 2 minutes after a randomized delay of 1-10 minutes
device.switchOff().withinMin(10).forMin(2)
device.close().forMin(15)
device.open().afterSec(20)
device.open().afterMin(2)
which does not help me, as I do not toggle a device, I write the commands myself.
Only way I found is setting time as a variable (f.e. local time +10min) and create an on time event using this variable - seems to be much code and effort for a "simple" delay function .
Is there any better way to delay an execute function?

Re: Yeelight (execute = function) time delay  [Solved]

Posted: Thursday 17 May 2018 18:06
by waaren
you could use the domoticz.variables('anotherVar').set(1).afterMin(10) approach and let the script trigger on the variable change to do the action.
Another way is to use the linux at now+10minutes command

Re: Yeelight (execute = function) time delay

Posted: Friday 25 May 2018 21:11
by Inso80

Code: Select all

domoticz.variables('anotherVar').set(1).afterMin(10)
awesome way to have a delay, thank you very much, works like a charm :D

Re: Yeelight (execute = function) time delay

Posted: Friday 25 May 2018 22:41
by dannybloe
Or use openURL. It supports delays.