Hi,
I’m trying to create a script that turns on all lights in a zone with a delay of x milliseconds between each light. I use one dimmer pr light (still cheaper than DALI).
I then noticed that when calling the setCapabilityValue method, it only updates once the script returns, thus, all lights turn on at the same time.
Is there a way to actually execute the setCapabilityValue prior to script completion?
PS: The reason for this script is because the delay in a standard flow card is set to seconds as it’s lowest input (integer). I would like to go bellow that.
My code looks like this:
// This script turns on all lights in the Garden zone in a cascade with
// the time of delayInMilliseconds in between each light.
var delayInMilliseconds = 250;
let devices = await Homey.devices.getDevices();
let zones = await Homey.zones.getZones();
for(var i in zones)
{
if(zones[i].name == 'Garden')
{
var gardenId = zones[i];
console.log('Garden found in id: ', zones[i].id);
}
}
for(var i in devices)
{
if(devices[i].zone == gardenId.id)
{
console.log(devices[i].name);
devices[i].setCapabilityValue('onoff', true);
sleep(delayInMilliseconds);
}
}
return true;
function sleep(ms) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > ms){
break;
}
}
}