Sleeping in FlicScript
-
I would like to have a run a script every hour to check the time and change the brightness of a light throughout the evening.
Is it possible for the Flic Hub LR to run a script on a schedule, or would I need to have the script running continuously manually create a loop using
setTimeout
to sleep for an hour? Or is there some better way to sleep in a loop, like how a script can wait for a button press but being trigger at a time instead of on an event?Would it be horribly inefficient for the hub to have script sleeping for long periods using
setTimeout
or is that effectively the same as having a script running continuously and waiting for a button press?Thank you!
-
pico
-
@Emil Thank you! This is exactly the confirmation I needed to get started with my project! It's so cool to be able to script Matter devices!
-
Using
setTimeout
orsetInterval
is the preferred way. That is effectively the same performance cost as having a script running waiting for a button press. As long as your script doesn't do anything (consuming cpu cycles), the only cost is some RAM for the process to be active, which is totally fine. Note that you should never have a busy loop though, since FlicScript is event based.Make sure you tick "Restart after crash" before starting, so that your script will be restarted also after the hub reboots, e.g. after a power cut or firmware update.