Announcement

Collapse
No announcement yet.

Calculate occupation time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Calculate occupation time

    I'm trying to calculate the time between the current time and the time that the device has changed for the last time.

    &hs.setdevicestring(259,TIME-NOW,true) doesn't work

    And is it possible to calculate the time in hours:min when the current time-the time that the device has changed for the last time < 24 hours and calculate the time in days when the current time-the time that the device has changed for the last time > 24 hours?

    I want to show show the occupation time in hours or days depending on < 24 hours and > 24 hours in HStouch.

    For example:
    01:30

    or

    2 days

    #2
    Have a look at the DateDiff function: Here
    http://www.midondesign.com

    Comment


      #3
      Originally posted by Midon View Post
      Have a look at the DateDiff function: Here
      Thanks Midon,

      But when i try to use the DateDiff a get a strange result:

      &hs.setdevicestring(259, DateDiff("h",now,time),true)

      result: -1034520

      Comment


        #4
        What are the values of now and time?
        Mike____________________________________________________________ __________________
        HS3 Pro Edition 3.0.0.548, NUC i3

        HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | X10: XTB-232, -IIR | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

        Comment


          #5
          Originally posted by Uncle Michael View Post
          What are the values of now and time?
          Uncle Michael,

          I think i've to make a second virtual device so that i can extract the time stamp from the device that has been changed from the current time.

          At this moment when the device status changes, the device string = current time-time stamp (which is also the same time as the current time) The result is always the same: -1034520

          Comment


            #6
            I just tried this script:
            Code:
                Sub Main(ByVal Params As Object)
            
                hs.setdevicestring(1407, DateDiff("n",hs.DeviceLastChangeRef(502),NOW),true)
            
                End Sub
            (My time since last change is less than 20 minutes ago, so I chose minutes rather than hours.) My device string reads '9', when the device changed nine minutes ago, '6' when it had been six minutes.

            I'm suspicious that the value of your 'time' is not in date format. If you use the HS function for device last change in your formula, it should give you the result you are looking for.
            Mike____________________________________________________________ __________________
            HS3 Pro Edition 3.0.0.548, NUC i3

            HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | X10: XTB-232, -IIR | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

            Comment


              #7
              Originally posted by Uncle Michael View Post
              I just tried this script:
              Code:
                  Sub Main(ByVal Params As Object)
              
                  hs.setdevicestring(1407, DateDiff("n",hs.DeviceLastChangeRef(502),NOW),true)
              
                  End Sub
              (My time since last change is less than 20 minutes ago, so I chose minutes rather than hours.) My device string reads '9', when the device changed nine minutes ago, '6' when it had been six minutes.

              I'm suspicious that the value of your 'time' is not in date format. If you use the HS function for device last change in your formula, it should give you the result you are looking for.
              I will give it a try!

              Thank you for your input

              EDIT:

              Thank you Uncle Michael, that works great!
              Last edited by michaeldecharon; January 10, 2018, 05:49 AM.

              Comment

              Working...
              X