Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


HC3 Scenes - schedule actions on times


jgab

Recommended Posts

When doing a scene on the HC3 there is the option to schedule invocations of the scene using the conditions sections and the 'cron' property.

Please login or register to see this code.

The above condition will trigger the scene every minute.

 

There are possibilities to be more specific and only trigger every minute on weekends with the value {"*", "*", "*", "*", "6,7", "*"}. etc.. 

It's also possible to limit it between sunset and sunrise but then we need to make more elaborate conditions. If we want to cover many different times we either need to create a very long condition (with any) and in the scene test what time was triggered - or create many smaller scenes that may turn out difficult to maintain.

 

So, if you want to keep most of your time scheduling in one scene, one approach is to setup a trigger for every minute like the condition above - and then in the scene make tests if the time is right for your various actions

 

One approach to structure such as scene is like below. It relies on being triggered every minute - and calling a user provided function clock(....) with various "nice to have parameters" that can be easily tested against if the time is right to carry out some actions.

Please login or register to see this code.

We can reason about time as a Lua string of format "HH:MM". We can test for equality and less than and greater than (be aware of times spanning midnight). We have also boosted the tonumber() function so that it converts a "HH:MM" string to it's value in seconds. That allows us to do some simple arithmetic like in the last example where we test if the time is 10min before sunrise and it's weekend.

Running a scene like this every minute will not take a huge toll on the HC3...

 

Anyway, this is a simple way to create a scheduler of actions using a scene - I'm sure there will be more to come...

Edited by jgab
  • Like 1
  • Thanks 3
Link to comment
Share on other sites

  • 4 weeks later...

This is great! Thank you very much for sharing. 

Link to comment
Share on other sites

  • 1 month later...
On 3/23/2020 at 5:06 PM, jgab said:

When doing a scene on the HC3 there is the option to schedule invocations of the scene using the conditions sections and the 'cron' property.

Please login or register to see this code.

The above condition will trigger the scene every minute.

 

There are possibilities to be more specific and only trigger every minute on weekends with the value {"*", "*", "*", "*", "6,7", "*"}. etc.. 

It's also possible to limit it between sunset and sunrise but then we need to make more elaborate conditions. If we want to cover many different times we either need to create a very long condition (with any) and in the scene test what time was triggered - or create many smaller scenes that may turn out difficult to maintain.

 

So, if you want to keep most of your time scheduling in one scene, one approach is to setup a trigger for every minute like the condition above - and then in the scene make tests if the time is right for your various actions

 

One approach to structure such as scene is like below. It relies on being triggered every minute - and calling a user provided function clock(....) with various "nice to have parameters" that can be easily tested against if the time is right to carry out some actions.

Please login or register to see this code.

We can reason about time as a Lua string of format "HH:MM". We can test for equality and less than and greater than (be aware of times spanning midnight). We have also boosted the tonumber() function so that it converts a "HH:MM" string to it's value in seconds. That allows us to do some simple arithmetic like in the last example where we test if the time is 10min before sunrise and it's weekend.

Running a scene like this every minute will not take a huge toll on the HC3...

 

Anyway, this is a simple way to create a scheduler of actions using a scene - I'm sure there will be more to come...

 

 

 

hello @jgab

 

just a quick and stupid question... or two... :)

 

* how to do when you want a condition running the scene every 2 minutes ? every 5 ...

* how to do to launch scene every hours at the 17th and 43rd minutes of it ?

 

struggling with this :)

thanks in advance,

 

br

mde

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

  • Topic Author
  • 5 hours ago, Mateo said:

    hello @jgab

    just a quick and stupid question... or two... :)

    * how to do when you want a condition running the scene every 2 minutes ? every 5 ...

    * how to do to launch scene every hours at the 17th and 43rd minutes of it ?

    struggling with this :)

    thanks in advance,

    br

    mde

    Well, there are a couple of ways to do that.

    First to recognise that the 'time' parameter is in the format "HH:MM".

    You can extract the minute part with time:sub(4)

    Please login or register to see this code.

    You can also match against a string pattern

    Please login or register to see this code.

    If you want to match against every nth minute there are some other approaches

    Our 'tonumber' converts the time string to seconds. You can then test if the seconds are evenly divided with the minute interval you look for

    Please login or register to see this code.

    This will run 00:02, 00:04 etc. If you don't care if it starts on an even interval, e.g. 00:01,00:03,.. is ok you can keep your own minute counter. The clock function is called every minute so you can add that counter as a variable

    Please login or register to see this code.

    A general way to test against different minute intervals is to check if the minute part of the string exists within a larger string of minutes that you want to match.

    Ex. if current minute part "17" exists in the string "09 17 23 43 59", which in this case it does

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    • 1 year later...
    • 1 year later...

    hi all, 

    I am a newbe in LUA and I have a very basic question. 

    Assume the lights in the kitchen shall be switched on at sunset and switched off at -say- 23:00

    Would you advise making two scenes (one to switch on and another to switch off) or combine the triggers in one scene and include some if-then-else statements in the actions?

    Link to comment
    Share on other sites

    • 8 months later...
    On 8/3/2020 at 1:58 AM, Mateo said:

    Please login or register to see this code.

    Hi

     

    in this line if I want to execute in every 2 min  (for testing) how I need to change the time:match part? 

    Link to comment
    Share on other sites

  • Topic Author
  • 6 hours ago, iTibor said:

    Hi

     

    in this line if I want to execute in every 2 min  (for testing) how I need to change the time:match part? 

    You extract the minute part. Convert it to a number and check if the number is evenly divisible with 2...

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...