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


  • 0

LUA scene day and time


kevin

Question

Hi,

 

I'm learning to make scenes in LUA, I'm creating all of my block scenes in LUA now, by doing that I understand it bit by bit a little better. And with HomeTable it is way easier than using the ID's.  Thank you @AutoFrank and the people who helped him:-D

 

I want to use some things like, if day is a weekday then do this and if it's weekend to that. And want to know how to use a time in LUA. So that I can type when time is 21:00 then .....

It would be great to also know what I need to put in the header on top of the LUA scene.

 

Thank you in advance.:rolleyes:

 

Kevin

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
10 hours ago, kevin said:

Hi,

 

I'm learning to make scenes in LUA, I'm creating all of my block scenes in LUA now, by doing that I understand it bit by bit a little better. And with HomeTable it is way easier than using the ID's.  Thank you @AutoFrank and the people who helped him:-D

 

I want to use some things like, if day is a weekday then do this and if it's weekend to that. And want to know how to use a time in LUA. So that I can type when time is 21:00 then .....

It would be great to also know what I need to put in the header on top of the LUA scene.

 

Thank you in advance.:rolleyes:

 

Kevin

 

This is a simple scen that runs the function clock(time, sunrise,sunset,day,weekend) every minute.

-time is a string "HH:MM", type "21:00",

-sunrise/sunset is similar strings for those hours,

-day is a string type "Monday", you can provide another map with the dayMap variable.

-weekend is a boolean that is true when it is a weekend.

 

Inside clock() you can do various if-then-else to decide if its time for action.

You can do tonumber("21:00") to get the number of seconds 21 hours represents. Allows you to calculate tonumber(sunset)-tonumber("00:30") etc...

Good way to hone those if-then-else Lua skills... 

Please login or register to see this code.

 

Edited by jgab
Link to comment
Share on other sites

  • 0
  • Inquirer
  • Thank you for your response @jgab

    I had no time to look at it and still need to find time to try it.

     

    If I understand it correct this is a separate scene that only monitors the day and time.  How do I incorporate this in an other scene?

    Link to comment
    Share on other sites

    • 0
    On 3/26/2019 at 1:41 PM, kevin said:

    Thank you for your response @jgab

    I had no time to look at it and still need to find time to try it.

     

    If I understand it correct this is a separate scene that only monitors the day and time.  How do I incorporate this in an other scene?

     

    Well, the idea was that instead of just 'fibaro:debug(" 21:00 on a Monday")' you could insert statements to "if day is a weekday then do this and if it's weekend to that" etc. e.g. turning on/off lights or whatever, using simple Lua if-then-else conditions

    What the scene helps you with is to make it easy to test against time parameters like time-of-day, day, sunset/sunrise, weekend to create a simple scheduler.

    I'm not sure what you mean by "Incorporate in another scene". If you want to do things at specific times you need a setTimeout model like this (I would advice against fibaro:sleep) in your scene. The way this setTimeout is coded it will not start to drift as is common when implementing a setTimeout loop the simple way... which often causes problems for schedulers...

    Ex.

    Please login or register to see this code.

     

    Edited by jgab
    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
    Answer this question...

    ×   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...