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 with Script to determine Motion/Door Sensor Last Breached Time/Period


Question

Posted

Hi,

 

I am trying to write a piece of script to determine the 'time since last breached' of motion and door sensors.

If the 'time since last breached' is more than 1 hour (3600 mins), it will set variable to be 'Away'.

If the 'time since last breached' is more than 24 hours (86400 mins), it will set variable to be 'Vacation'.

 

The current script I wrote seems to always meeting the 'Vacation' criteria. I found that the formula "(os.time() - fibaro:get(motionSensorID, "value")) always result in 1453051047 seconds and higher.

Please login or register to see this code.

Is the formula to determine 'time since last breached' wrong? If so, what is the right command or formula to use?

Please login or register to see this code.

Thanks for helping.

5 answers to this question

Recommended Posts

  • 1
Posted

Maybe this will help:

Please login or register to see this code.

  • 1
Posted

Hi,

 

The final verdict of the script will now always be the last motion sensor, I don't think you want that. Made a little change: it checks if home is set and then away and vacation will not be set anymore and it checks if away is set and the vacation will not be set anymore:

Please login or register to see this code.

  • 0
Posted

The strange number results from the fact that you are subtracting property "value" from os.time() but that should be "lastBreached". The "1453051047" is the number of seconds elapsed since 1970, the start of "lua time".

  • 0
  • Inquirer
  • Posted

    Thanks borremk and petergebruers for pointing me in the right directions. I think the revised script below should be working as intended. The only worry is how the script conclude the final verdict if any presence has been found within the last hour.

     

    As I am really very new to LUA, any input is much appreciated. 

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

     

    Revised Script:

    Please login or register to see this code.

    Output of revised script:

    Please login or register to see this code.

    • 0
  • Inquirer
  • Posted

    Thanks a zillion, boerremk. The changes did the trick and tests done suggest it is in order. I did spot another mistake I made earlier and rectified it together with the changes.

     

    Here is the combined bits of functions for motion and door sensors:

    Please login or register to see this code.

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