Yeelight (execute = function) time delay  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Inso80
Posts: 12
Joined: Thursday 17 May 2018 13:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Yeelight (execute = function) time delay

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Inso80
Posts: 12
Joined: Thursday 17 May 2018 13:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yeelight (execute = function) time delay

Post 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
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Yeelight (execute = function) time delay

Post by dannybloe »

Or use openURL. It supports delays.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest