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

Help. I have a problem with hub.get() command in LUA in my scene


Herni

Question

                Hi Everybody,

 

                I have a problem. I´m trying to measure the difference time between the change state of the S1 channel of a double switch. 

                Therefore, in my scene is using the hub.get () command to extract "lastmodificationtime" of the value of the channel (see the picture below):

 

 

Please login or register to see this image.

/monthly_2022_07/image.png.77bd4874ca813d326643c0acb802d17d.png" />

 

               After to extract the "lasttime1" value i compare the os.time() value with "lasttime1" value (to compare the time from high state to low state) (see picture below) 

 

MDE_2.PNG.46b79901f50aaa7ee1757d4397924f60.PNG

 

The problem is the if(tonumber(os.time() - lasttime1) sentence. I´m not sure if the problem is the data type used or not. But i can´t do that the if(tonumber(os.time() - lasttime1) sentence ejecute correctly. Could anybody help me? Thanks in advance. Best regard. 

 

                                               Hernán

 

 

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Try to add a debug statement before the test to see if you have the values you expect
Instead of 

Please login or register to see this code.

try

Please login or register to see this code.

 

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Hi Jgab,

     

    Thanks for the reply. I tried a debug statement (see the picture below),

     

    Please login or register to see this attachment.

     

    I think that the problem is the hub.get(25, "value") statement because the lastime1 value is 21:00:00, is not near to 19:20:23. I hold the momentary switch only a few seconds to test. I don´t know where is the problem yet. Thanks in advance. 

     

                                     Hernan

    Link to comment
    Share on other sites

    • 0

    Yes, the problem is lasttime1,  it's not a full time, like os.time(). Its a much smaller value (you see the diff is almost a full time value)

    Are you sure you are running the IF branch that is getting the value?

    Put a debug directly after

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi Jgab,

     

    I´m not sure. Because in the original script first i put the "a =hub.getValue(25,"value")" statement to capture the id = 25 value. After that i use the "a, lasttime1= hub.get(25,"value");" statement to capture lasttime1 value (when the rise edge to double switch is present). Homever i´m not sure if the first time when the "a =hub.getValue(25,"value")" statement is used it clear the lasttime1 value and the second time when the "a, lasttime1= hub.get(25,"value");" statement is used lasttime1 obtain another value. 

    Otherwise, 

    Homever, i have done that you asked me (see picture below)

     

    Please login or register to see this attachment.

     

    I´m running only the "hub.debug("SCENE6","lasttime1:",lasttime1)" statement after the "a, lasttime1= hub.get(25,"value");" statement to see the time values of rising and falling edge ( see the marks 1 and 2 in the console).  I don´t understand the format of these values. When i do the arithmetic operation of these value i think that the result must be a few seconds (1, 2 or 3 seconds depend how much time i hold down the momentary switch). But the result is not as expected. Thanks.

     

                                           Hernán

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi Jgab,

     

    The problem is the scope of the variable "local" lasttime1. When the momentary switch is pressed the first time the local lasttime1 variable value save the system time. But it variable have a local scope. When the momentary switch is released the script begin to run again and the local lastime1 variable reset to 0 value (see the picture below)

     

    Please login or register to see this attachment.

     

    I have change script and the declare in the variable panel of the Yubii Home Controller, the global variable "lasttime1" to hold the first value in memory (see picture below). But the result of the difference of the values is 0 now. In the picture the difference time between rising and falling edges is 2 seconds. I don´t know where is

    the problem now. Could you help me with it?

     

    Please login or register to see this attachment.

     

    Thanks very much. 

     

                                              Hernán

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi Jgab,

     

    The problem was resolved. The problem was the data type of the operands (lastime and lastime2 (or the value returned of the os.time() function). See the picture below.

     

    Please login or register to see this attachment.

     

    Thank you very much for help me. Best regard.

     

                                                                                 Hernán

     

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