Announcement

Collapse
No announcement yet.

Comparing DateTime values, now() vs Virtual Device?

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

    Comparing DateTime values, now() vs Virtual Device?

    For some reason I can not figure this one out...


    I would like to have a Virtual Device that stores a DateTime value. Call it AutoOff.


    I would then like to compare that Virtual Device with current time (now()).


    If current time is larger than the stored DateTime value in the Virtual Device then I need to do some stuff...


    Yes I could use a bunch of timers for this - however I am looking for a bit of a more elegant solution, with different timer auto off values (like 2 minutes in the night, 20 minutes in the morning and 5 in between - yes I have a VD which tracks Night/Morning and so on, and on top of this, if device is turned on manually (it is normally motion triggered) then it needs a full hour before doing some stuff...


    However, when I stored now()+2 minutes into a Virtual Device I got a very large negative number (int32?), however that I can not seem to use to compare with a later now().


    I am tiered, I admit that, however if someone can point me in a direction I would be happy :-)

    #2
    I may not understand what you want to do, but one option would be to use the delayed action option for device control. The event that turns on your device would have several actions to run events if the conditions are true. Based on the conditions, the event that runs would be the one with the appropriate delay for turning off your device.

    If you want to do the time interval computations yourself, then you will need to write a script, but that can be a bit tricky if you are not familiar with working with time/date functions.
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

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

    Comment


      #3
      Maybe another approach is to calculate the amount of time since the devicelastchange?

      xxx = DateDiff("s",hs.devicelastchangeref(1234),now)
      s: in second
      https://www.w3schools.com/asp/func_datediff.asp

      Comment


        #4
        I ended up with using Global Variables instead of Virtual Devices - the difference is that I can store datetime values in Global Variables, and in a Virtual Device one can only store a number. A number could of course be "number of seconds since 1st jan 1970" (UNIX Epoch) - however I decided to have something a bit more "readable".


        Now I only have to figure out how to get all Global Variables created at boot (yes I know of Startup.vb - however I can not for my life get that script to call for the "CreateGlobalVariables.vb" - I will have to work that out...).

        Comment


          #5
          Originally posted by larhedse View Post
          I ended up with using Global Variables instead of Virtual Devices - the difference is that I can store datetime values in Global Variables, and in a Virtual Device one can only store a number,
          FWIW, you can save datetime in the device string of a virtual device. (Datetime is also stored the the DeiviceLastChange field of a device as well.)
          Mike____________________________________________________________ __________________
          HS3 Pro Edition 3.0.0.548, NUC i3

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

          Comment


            #6
            Well I had a thought about that, however my lack of experience of Homeseer made me choose the current path :-)

            Comment

            Working...
            X