Flic Home

    Community

    • Login
    • Search
    • Popular
    • Users

    Sleeping in FlicScript

    Flic Hub SDK
    2
    3
    178
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • pico
      pico last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • Referenced by  pico pico 
      • pico
        pico @Emil last edited by

        @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!

        1 Reply Last reply Reply Quote 0
        • Emil
          Emil FlicTeam last edited by

          Using setTimeout or setInterval 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.

          pico 1 Reply Last reply Reply Quote 0
          • First post
            Last post