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

Motion lastBreached


Question

Posted

Hi


I am trying to create a simple Virtual Device to show the elapsed time since motion on a number of sensors, I have the following updating a label

 

fibaro:call(335, "setProperty", "ui.Label1.value", tostring(fibaro:getValue(166, "lastBreached")));

 

Any idea how to convert the response of 1555934942 into time since last motion detected?

 

Thanks

18 answers to this question

Recommended Posts

  • 0
Posted

Like this ?

Please login or register to see this code.

 

  • 0
Posted
39 minutes ago, Dman568 said:

Hi


I am trying to create a simple Virtual Device to show the elapsed time since motion on a number of sensors, I have the following updating a label

 

fibaro:call(335, "setProperty", "ui.Label1.value", tostring(fibaro:getValue(166, "lastBreached")));

 

Any idea how to convert the response of 1555934942 into time since last motion detected?

 

Thanks

 

Could you share whole lua code with us please..

thanks

  • 0
  • Inquirer
  • Posted
    12 hours ago, jgab said:

    Like this ?

    Please login or register to see this code.

     

    Thanks that is showing a time now but it inst the elapsed time, the last motion was an hour ago but that is showing 08:43:36

    • 0
    Posted (edited)
    4 hours ago, Dman568 said:

    Thanks that is showing a time now but it inst the elapsed time, the last motion was an hour ago but that is showing 08:43:36

    To check what the last breached time was test

    Please login or register to see this code.

    and to be sure that you don't  have a really old lastBreached value

    Please login or register to see this code.

     

    Edited by jgab
    • 0
    Posted
    24 minutes ago, jgab said:

    To check what the last breached time was test

    Please login or register to see this code.

    and to be sure that you don't  have a really old lastBreached value

    Please login or register to see this code.

     

     

    Sorry, didn't think about dst.

    You need to do something like

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted
    2 hours ago, jgab said:

     

    Sorry, didn't think about dst.

    You need to do something like

    Please login or register to see this code.

     

    Cheers I have the following code in the mainloop

     

    function toTime(t) return string.format("%02d:%02d:%02d",t/3600,(t%3600)/60,t%60) end
    fibaro:debug(os.date("Time elapsed %H:%M:%S",os.time()-fibaro:getValue(166, "lastBreached")))
    fibaro:debug(os.date("Time now %H:%M:%S",os.time()))
    fibaro:debug(os.date("Last breached %H:%M:%S",fibaro:getValue(166, "lastBreached")))
    fibaro:debug(os.date("Time elapsed %H:%M:%S",os.time()-fibaro:getValue(166, "lastBreached")))
    fibaro:debug(os.date("Last breached %c",fibaro:getValue(166, "lastBreached")))
    fibaro:debug(string.format("Time elapsed %H:%M:%S",toTime(os.time()-fibaro:getValue(166, "lastBreached"))))

     

    The debug output is 

     

    [DEBUG] 15:13:52: Time elapsed 15:24:58
    [DEBUG] 15:13:52: Time now 15:13:52
    [DEBUG] 15:13:52: Last breached 07:48:54
    [DEBUG] 15:13:52: Time elapsed 15:24:58
    [DEBUG] 15:13:52: Last breached Tue Apr 23 07:48:54 2019
    [ERROR] 15:13:52: line 8: invalid option '%H' to 'format'

     

    time now and time last breached are correct but the time elapsed isn't. I can see it is just date manipulation but not sure what it should be

    • 0
    Posted

    Hi, I suspect line 8 invalid is the cause of your error

    print(os.date("Last breached %H:%M:%S",fibaro:getValue(166, "lastBreached")))

    ony end I see the difference between last breached and the present time

     

    • 0
    Posted (edited)
    3 hours ago, Sjakie said:

    Hi, I suspect line 8 invalid is the cause of your error

    print(os.date("Last breached %H:%M:%S",fibaro:getValue(166, "lastBreached")))

    ony end I see the difference between last breached and the present time

     

    Sorry, cut and paste error

    Please login or register to see this code.

     

    Edited by jgab
    • Like 1
    • 0
  • Inquirer
  • Posted
    28 minutes ago, jgab said:

    Sorry, cut and paste error

    Please login or register to see this code.

     

    Perfect exactly what i was looking for, thank you so much for your help

    • 0
    Posted

    @Dman568

     

    I was looking for that because the mobile app doesn’t show the lastbreached time.

     

    Could you share the complete VD? And can I add more sensors to it so I can watch them all in 1 vd?

     

    thank you in advance.

    • 0
    Posted (edited)

    @Dman568  Wondering if you get the same screen as me ? Time displayed is always with hour set to 1 Minutes and seconds are correct but it always adds hour. Believe it has to do with left padded integer.

    Please login or register to see this spoiler.

     

    Edited by MARCUSP.I.L
    • 0
  • Inquirer
  • Posted
    7 hours ago, kevin said:

    @Dman568

     

    I was looking for that because the mobile app doesn’t show the lastbreached time.

     

    Could you share the complete VD? And can I add more sensors to it so I can watch them all in 1 vd?

     

    thank you in advance.

    Here is my code, you need a label for each one on the VD

     

    function toTime(t) return string.format("%02d:%02d:%02d",t/3600,(t%3600)/60,t%60) end
    fibaro:debug(os.date("Time now %c",os.time()))
    fibaro:debug(os.date("Last breached %c",fibaro:getValue(166, "lastBreached")))
    fibaro:debug(string.format("Time elapsed %s",toTime(os.time()-fibaro:getValue(166, "lastBreached"))))

    fibaro:call(335, "setProperty", "ui.Label1.value",string.format("%s",toTime(os.time()-fibaro:getValue(280, "lastBreached"))))
    fibaro:call(335, "setProperty", "ui.Label2.value",string.format("%s",toTime(os.time()-fibaro:getValue(276, "lastBreached"))))
    fibaro:call(335, "setProperty", "ui.Label3.value",string.format("%s",toTime(os.time()-fibaro:getValue(176, "lastBreached"))))
    fibaro:call(335, "setProperty", "ui.Label4.value",string.format("%s",toTime(os.time()-fibaro:getValue(262, "lastBreached"))))
    fibaro:call(335, "setProperty", "ui.Label5.value",string.format("%s",toTime(os.time()-fibaro:getValue(302, "lastBreached"))))
    fibaro:call(335, "setProperty", "ui.Label6.value",string.format("%s",toTime(os.time()-fibaro:getValue(326, "lastBreached"))))
    fibaro:call(335, "setProperty", "ui.Label7.value",string.format("%s",toTime(os.time()-fibaro:getValue(229, "lastBreached"))))
    fibaro:call(335, "setProperty", "ui.Label8.value",string.format("%s",toTime(os.time()-fibaro:getValue(166, "lastBreached"))))

     

     

    3 hours ago, MARCUSP.I.L said:

    @Dman568  Wondering if you get the same screen as me ? Time displayed is always with hour set to 1 Minutes and seconds are correct but it always adds hour. Believe it has to do with left padded integer.

    Please login or register to see this spoiler.

    this is my VD

    Please login or register to see this attachment.

    • Thanks 1
    • 0
    Posted (edited)

    Hi,

     

    I had finally the time to add this to my system. I would like to see the date and time it was breached for the last time. Not the time that is elapsed. Who can help me with the correct code to get this?

     

    Thank you in advance.

     

    Kevin

    Edited by kevin
    • 0
    Posted

    I tried a lot last several days but can't get it working like how I want it.

     

    Can someone help me? I don't want to see the elapsed time but the date and time when it was last breached.

     

    Kevin

    • 0
    Posted
    3 hours ago, kevin said:

    I tried a lot last several days but can't get it working like how I want it.

     

    Can someone help me? I don't want to see the elapsed time but the date and time when it was last breached.

     

    Kevin

     

    fibaro:call(335, "setProperty", "ui.Label1.value", os.date("%c",fibaro:getValue(280, "lastBreached")))
    fibaro:call(335, "setProperty", "ui.Label2.value", os.date("%c",fibaro:getValue(276, "lastBreached")))
    fibaro:call(335, "setProperty", "ui.Label3.value", os.date("%c",fibaro:getValue(176, "lastBreached")))
    fibaro:call(335, "setProperty", "ui.Label4.value", os.date("%c",fibaro:getValue(262, "lastBreached")))
    fibaro:call(335, "setProperty", "ui.Label5.value", os.date("%c",fibaro:getValue(302, "lastBreached")))
    fibaro:call(335, "setProperty", "ui.Label6.value", os.date("%c",fibaro:getValue(326, "lastBreached")))
    fibaro:call(335, "setProperty", "ui.Label7.value", os.date("%c",fibaro:getValue(229, "lastBreached")))
    fibaro:call(335, "setProperty", "ui.Label8.value", os.date("%c",fibaro:getValue(166, "lastBreached")))

    • Thanks 1
    • 0
    Posted (edited)

    Thank you @jgab, I don't know why I didn't found this myself:oops:. I have added a line for a time format.

    Now it's looking great in the VD.

     

     

    Please login or register to see this attachment.

    Edited by kevin
    • 0
    Posted

    Thanks,

    You see that I use os.date("%c",<time>) to format the time. There are many more options besides '%c' that that can be combined and allow you to put together a format of your own choice. 

    See 

    Please login or register to see this link.

    Ex. os.date("breached at %b %d, %X")

    Results in the string "breached at May 19, 10:00:22"

     

     

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