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

Before, or after sunrise action


Remi

Question

Hi all,

 

Can you please help me?

I'm struggling to make a LUA scene.

What I want to achieve in the end situation is to perform an action based on before or after sunrise.

 

I've already simplified the script to see if it works, but it still fails.

 

Please login or register to see this code.

 

Unfortunately my script seems to have a problem, the output is wrong

But i dont get any errors either.

 

Please login or register to see this image.

/monthly_2022_03/504704590_Screenshot2022-03-28170744.jpg.37ad06bcf1c676c8ca42f1a4ff6c9846.jpg" />

 

If anyone has time to look at it and give advice I would be very grateful

 

greets,

Remi

Edited by Remi
Link to comment
Share on other sites

13 answers to this question

Recommended Posts

  • 0

@Alex de Bruin and @Remi ,

 

LUA can compare times in format "00:00" but there must be included leading zero for hours lower than 10. So following corrected code should work as expected:

Please login or register to see this code.

If you print fibaro:getValue(1,"sunriseHour") you will notice that it always returns hours in format "00:00" e.g. --> 07:45.

 

 

  • Thanks 1
Link to comment
Share on other sites

  • 0

Remi,

You cannot compare time strings the way you try to do. Use for example a function to convert the strings to seconds.

 

 

Please login or register to see this code.

 

  • Thanks 1
Link to comment
Share on other sites

  • 0
  • Inquirer
  • Aaah I understand.

    My skills in LUA are not that good to create my own function(s), but I do understand what is happening here.

    I can also use that in the future.

     

    I made a small adjustment to your example to make it more visible to me.

    Thanks for helping!

     

    Please login or register to see this code.

     

    Please login or register to see this image.

    /monthly_2022_03/175218068_Screenshot2022-03-28184925.jpg.1e1033abbfd076b7fa152ce2421cecd9.jpg" />

     

    Link to comment
    Share on other sites

    • 0
    7 hours ago, Remi said:

    Aaah I understand.

    My skills in LUA are not that good to create my own function(s), but I do understand what is happening here.

    I can also use that in the future.

     

     

    Please try to use

    Please login or register to see this link.

    ... no LUA skills required and what you need could be done in seconds....

     

    • Like 1
    Link to comment
    Share on other sites

    • 0
    59 minutes ago, Sankotronic said:

    @Alex de Bruin and @Remi ,

     

    LUA can compare times in format "00:00" but there must be included leading zero for hours lower than 10.

     

     

     

    Didn't know that. Thanks, never too old to learn.

    • Like 1
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 13 hours ago, AR27690 said:

    Please try to use

    Please login or register to see this link.

    ... no LUA skills required and what you need could be done in seconds....

     

    Thanks, i will have a look at that later. But to be honest that look quite overwhelming ?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 6 hours ago, Sankotronic said:

    @Alex de Bruin and @Remi ,

     

    LUA can compare times in format "00:00" but there must be included leading zero for hours lower than 10.

     

    If you print fibaro:getValue(1,"sunriseHour") you will notice that it always returns hours in format "00:00" e.g. --> 07:45.

     

     

    Thanks @Sankotronic glad to see normal time notation can work too. Altho i understand the conversion to seconds too, normal time notation is a bit more noob friendly to me ?

    Link to comment
    Share on other sites

    • 0

    @Remi ,

     

    It is OK to use conversion when it is needed. For example, to have current time in correct format to compare it with sunrise and sunset you can get by simple code:

    Please login or register to see this code.

     

    If current date and time coded as a number is needed then you can use:

    Please login or register to see this code.

    It is also possible to get date and time coded as a number for specific date and time represented in UNIX time:

    Please login or register to see this code.

    To separate sunrise time string to hour and minute that can be used in calculations:

    Please login or register to see this code.

     

    I prefer to use UNIX time since it is easy to convert it to the needed format of the date and time or get it coded as number. Unfortunately some of the services does not provide it as a number, but usually already formatted as string. For example Wunderground current observation time:

    Please login or register to see this code.

    I have wrote function that can convert any format of the date and time string to UNIX time. There are two parameters that needs. First parameter is string that contains time to be converted and second parameter is _format string that tells function position of the year, month, day, hour, minutes and seconds:

    Please login or register to see this code.

    This function I wrote few years ago when I was making Weather State & Forecast VD+scene and can be done prettier, but since it works I didn't bother changing it.

     

    • Like 1
    Link to comment
    Share on other sites

    • 0
    12 hours ago, Sankotronic said:

    I have wrote function that can convert any format of the date and time string to UNIX time. There are two parameters that needs. First parameter is string that contains time to be converted and second parameter is _format string that tells function position of the year, month, day, hour, minutes and seconds:

    Please login or register to see this code.

    This function I wrote few years ago when I was making Weather State & Forecast VD+scene and can be done prettier, but since it works I didn't bother changing it.

     

    Ok, challenge on - who can make the shortest version? \n doesn't count :-) 

    Please login or register to see this code.

     

    Edited by jgab
    • Like 2
    Link to comment
    Share on other sites

    • 0
    26 minutes ago, jgab said:

    Ok, challenge on - who can make the shortest version? \n doesn't count :-) 

    Please login or register to see this code.

     

     

    @jgab

     

    I knew you will do it shorter and more LUA-ish :-) ?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thanks @Sankotronic I learn alot today :-)

    I gues i can use UNIX format the same way if i want to compare moments in time with > or <= etc...? 

    In my specific use case, since the variable 'sunriseHour' is already in normal time format it seems a extra step to convert it to UNIX first.

    When do UNIX format benefit over normal time notation? In a more complex scene?

     

     

     

     

    Link to comment
    Share on other sites

    • 0
    1 hour ago, Remi said:

    When do UNIX format benefit over normal time notation? In a more complex scene?

     

    In a lot of useful situations. Since you can get day of the week from UNIX time you can use that to make timer that includes day of the week when will be run or not.

    Good example is Alarm clock where you can setup different alarms with specific days of the week, for example one alarm for working days and another alarm for weekends. Or alarm for only one day of the week etc.

     

    You can use daylight saving to change times of tariff models if they are different during summer and winter times.

     

    And as I already pointed out, you can get any date and time format from UNIX time like 2022-03-30 or 2022 March 30 or 30 March 22 or just 10:50. Easy beasy :-)

     

    Home automation is all about time, schedule, repeating actions etc. Since now you know what you can get related to the time it is only up to you where you will find it useful.

     

    Also if you wan to know when was last time global variable changed or last value change reported by some sensor HC will return time in UNIX format:

    Please login or register to see this code.

     

    Having time when global variable value changed and comparing it with current time os.time() is easy and does not need any conversion until you need to display time on the label of VD or QA.

     

    • Like 1
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • That are indeed good use cases and things what i always was wondering too. 

    The last time a sensor reported a value. Or even with a global variable! I thought that wasnt possible.

     Great stuff to learn :-)

    For sure going to give it a try to use this.

     

    Thanks!

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