Announcement

Collapse
No announcement yet.

VB Script - Get time value

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

    VB Script - Get time value

    Hi
    as part of the hstouch i am building, i am using 2 virtual devices to select a time (hours:min) and to be able to schedule an event to perform action.

    but something changed during the few upgrades of HS3 i imagine.
    the value date returns also the date even if i want only the time.


    Sub Main(Parm As Object)
    Dim EvRef As Integer
    Dim EvTime As date
    Dim DevHours As Integer
    Dim DevMins As Integer
    Dim DevRefH As Integer
    Dim DevRefM As Integer


    DevRefH = hs.GetDeviceRef("V97")
    DevRefM = hs.GetDeviceRef("V98")
    DevHours = hs.DeviceValue(DevRefH)
    DevMins = hs.DeviceValue(DevRefM)


    EvTime = ((DevHours) &":"& (DevMins))

    hs.writelog ("Test9",EvTime)


    End Sub



    i get this in the log:
    Test9 9/7/2015 12:05:00 PM

    i selected 12 in the virtual device for hours and 05 for the virtual device for minutes.
    but i get also the date in the value and i need only the time.

    anyone knows what i am missing?
    thanks

    #2
    The computer does what you tells it to do. EvTime is specified as a "Date" object (which also carries time) so it gives you that.

    You can change
    Code:
     hs.writelog ("Test9",EvTime)
    to this:
    Code:
     hs.writelog ("Test9",EvTime.ToShortTimeString)
    (and you can use .ToLongTimeString if you need the seconds aswell. If you need even more precision use .TimeOfDay instead).
    HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
    Running on Windows 10 (64) virtualized
    on ESXi (Fujitsu Primergy TX150 S8).
    WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

    Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

    Comment


      #3
      thanks for the quick reply.
      when i added the .toshorttimestring the log gave me this:

      Sep-07 13:36:23 Test9 12:02 PM
      so that worked.


      but when i add this to the script (the EVREF is the event's name)
      hs.EventSetTimeTrigger(EvRef,EvTime.ToShortTimeString)

      the event is created but without any time trigger.

      when i use:
      hs.EventSetTimeTrigger(EvRef,EvTime)


      the task is created but with the correct time as a trigger but the current date.
      since i usually create tasks for 3 AM in the morning, the task will not run since the date will be wrong.
      any idea why it is working with the write.log but not with the hs.EventSetTimeTrigger?

      this is in the log:
      Running script Schedule Action.vb :Exception has been thrown by the target of an invocation.->Does entry point Main exist in script? at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0 at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in :0 at A.c17b105f989efe61e5979e67bec1ef734.cffd66cb0782c50126727e3f a75582d7a () [0x00000] in :0

      Comment


        #4
        Yeah, this is a known error... hs.EventSetTimeTrigger STILL doesn't work like it should.
        HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
        Running on Windows 10 (64) virtualized
        on ESXi (Fujitsu Primergy TX150 S8).
        WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

        Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

        Comment


          #5
          so how would you bypass it?
          maybe add a check to see if the hour is before 12AM, add +1 to the day?

          maybe add a date selection?

          open to any suggestions

          Comment


            #6
            At the moment "EventSetTimeTrigger" needs a complete date object. That's not a problem by itself. You can do something like this:
            Code:
            Dim myTime as Date = Now
            myTime.AddDays(1)
            myTime.Hour = 22
            myTime.Minute = 15
            to have it triggered at 22:15 tomorrow and do
            Code:
            hs.EventSetTimeTrigger(some_event_ref, myTime)
            ... but that will add the time AND the date to the trigger.

            That is not a problem, but the date isn't removed when you set the trigger next time. So after a couple of days your event will look like something like this:
            IF Time is 22:00:00
            AND Date is 07.09.2015
            AND Date is 06.09.2015
            AND Date is 05.09.2015
            ... and so on.

            Since the date cannot be both the 7th and the 6th at the same time, the event will never get triggered.
            HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
            Running on Windows 10 (64) virtualized
            on ESXi (Fujitsu Primergy TX150 S8).
            WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

            Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

            Comment


              #7
              Yes but i also use hs.DeleteAfterTrigger_Set(EvRef)
              so once it is triggered it will be deleted.
              i need this only once (so i can shut down the AC in the childrens room and open their shades at 2am. and the next day i will reschedule it again).

              Comment


                #8
                Originally posted by ez1976 View Post
                Yes but i also use hs.DeleteAfterTrigger_Set(EvRef)
                so once it is triggered it will be deleted.
                i need this only once (so i can shut down the AC in the childrens room and open their shades at 2am. and the next day i will reschedule it again).
                Ah, that will work. Then you just need to add the date parameter as well as described above and it should work.
                HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
                Running on Windows 10 (64) virtualized
                on ESXi (Fujitsu Primergy TX150 S8).
                WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

                Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

                Comment


                  #9
                  When i run this script:
                  Sub Main(Parm As Object)



                  Dim EvTime as date = Now



                  EvTime.AddDays(1)
                  EvTime.Hour = 22
                  EvTime.Minute = 15

                  hs.writelog ("Test9",EvTime)


                  End Sub




                  i get this:
                  Compiling script Schedule Action.vb: Visual Basic.Net Compiler version 0.0.0.5943 (Mono 3.8 - tarball) Copyright (C) 2004-2010 Rolf Bjarne Kvinge. All rights reserved. /tmp/4e38cd66/3cd23694.0.vb (2,16) : warning VBNC40056: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. vbnc : Command line : error VBNC99999: Unexpected error: The requested feature is not implemented. at vbnc.CecilHelper.GetCorrectMember (Mono.Cecil.MethodReference Member, Mono.Cecil.TypeReference Type, Boolean Emittable) [0x00000] in :0 at vbnc.PropertyAccessClassification.GenerateCode (vbnc.EmitInfo Info) [0x00000] in :0 at vbnc.AssignmentStatement.GenerateCode (vbnc.EmitInfo Info) [0x00000] in :0 at vbnc.CodeBlock.GenerateCode (vbnc.EmitInfo Info) [0x00000] in :0 at vbnc.CodeBlock.GenerateCode (IMethod Method) [0x00000] in :0 at vbnc.MethodBaseDeclaration.GenerateCode (vbnc.EmitInfo Info) [0x00000] in :0 at vbnc.MethodDeclaration.GenerateCode (vbnc.EmitInfo Info) [0x00000] in :0 at vbnc.SubDeclaration.GenerateCode (vbnc.EmitInfo Info) [0x00000] in :0 at vbnc.Helper.GenerateCodeCollection (IEnumerable Collection, vbnc.EmitInfo Info) [0x00000] in :0 at vbnc.BaseObjects`1[vbnc.IMember].GenerateCode (vbnc.EmitInfo Info) [0x00000] in :0 at vbnc.AssemblyDeclaration.Emit (vbnc.TypeDeclaration Type) [0x00000] in :0 at vbnc.AssemblyDeclaration.Emit () [0x00000] in :0 at vbnc.Compiler.Compile () [0x00000] in :0 Compilation took 00:00:00.9323130

                  Comment


                    #10
                    Okay... don't know why that is failing. Are you on a Zee1 or 2?

                    ... and I forgot a crucial thing: .AddDays is just a function, and adds it to the object, you need to do something assign the new object to something, like this: EvTime = EvTime.AddDays(1)



                    Anyway, you can try this instead:
                    Code:
                            Dim EvTime As Date = New Date(Now.Year, Now.Month, Now.Day, 22, 15, 0)
                            EvTime = EvTime.AddDays(1)
                            hs.Writelog("Test", EvTime.ToString)
                    (EDIT: I just tested this on my Zee1 and it works)
                    HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
                    Running on Windows 10 (64) virtualized
                    on ESXi (Fujitsu Primergy TX150 S8).
                    WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

                    Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

                    Comment


                      #11
                      Originally posted by Moskus View Post
                      Okay... don't know why that is failing. Are you on a Zee1 or 2?

                      ... and I forgot a crucial thing: .AddDays is just a function, and adds it to the object, you need to do something assign the new object to something, like this: EvTime = EvTime.AddDays(1)



                      Anyway, you can try this instead:
                      Code:
                              Dim EvTime As Date = New Date(Now.Year, Now.Month, Now.Day, 22, 15, 0)
                              EvTime = EvTime.AddDays(1)
                              hs.Writelog("Test", EvTime.ToString)
                      (EDIT: I just tested this on my Zee1 and it works)

                      Hey Everyone.
                      to enhance this script i added a count down option to the timer.
                      meaning my wife can either schedule an event for 4:30 tomorrow morning to close the AC or set 01:30 to the current time to close the AC.

                      that way she can just Select 01 Hours & 30 Minutes to device "Living Room AC", and have the script use the Now value and add 01 to Now.hours and 30 to Now.Minutes to calculate the time for the event.

                      but since my script kung fu is weak i tried doing this:


                      Dim EvTime As Date = New Date(Now.Year, Now.Month, Now.Day, Now.Hour + DevHours, Now.Minute + DevMins, 0)


                      DevHours and DevMins are values from a virtual device that will hold the hours and minutes (they work great).
                      what is the correct syntax to calculate the Date to have the Now.Hours and Now.minutes add the value of the virtual devices.


                      thanks

                      Comment


                        #12
                        Originally posted by ez1976 View Post
                        what is the correct syntax to calculate the Date to have the Now.Hours and Now.minutes add the value of the virtual devices.
                        See for reference: https://msdn.microsoft.com/en-us/lib...code-snippet-1

                        Try something like this:
                        Code:
                        Sub Main(ByVal Params As Object)
                        
                            Dim dblTimeToAdd As Double = 1.5 'in hours  so 1 hour 30 min = 1.5
                            Dim dtePresent As Date = NOW
                            Dim dteFuture As Date = dtePresent.AddHours(dblTimeToAdd)
                        
                            End Sub
                        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


                          #13
                          Originally posted by Uncle Michael View Post
                          See for reference: https://msdn.microsoft.com/en-us/lib...code-snippet-1

                          Try something like this:
                          Code:
                          Sub Main(ByVal Params As Object)
                          
                              Dim dblTimeToAdd As Double = 1.5 'in hours  so 1 hour 30 min = 1.5
                              Dim dtePresent As Date = NOW
                              Dim dteFuture As Date = dtePresent.AddHours(dblTimeToAdd)
                          
                              End Sub

                          Thanks
                          in the end i did something like this:


                          DevRefH = hs.GetDeviceRef("V901") -> a virtual device that holds the Hours value
                          DevRefM = hs.GetDeviceRef("V902") -> a virtual device that holds the Minutes value
                          DevHours = hs.DeviceString(DevRefH)
                          DevMins = hs.DeviceString(DevRefM)




                          hs.Writelog("Hours", DevHours)
                          hs.Writelog("Minutes", DevMins)
                          Dim EvTime As Date = New Date(Now.Year, Now.Month, Now.Day, DevHours, DevMins, 0)


                          hs.Writelog("Current Hour", Now.hour)
                          if (now.hour > DevHours ) Then
                          EvTime = EvTime.AddDays("1")
                          end if

                          the last IF is a weird bug in HS3. if you schedule an event via script, it will always add it to the same day. so if i it is 2 PM and i schedule something for 3 AM, it will schedule it for the same day at 3 AM (which has passed).

                          that way i check and see if the current hour (14:00) is bigger than the Hour value (03:00) - which is not and it will add a day to the event.

                          if the Hour value is set to 7 PM (19:00), the If statement is not correct and it will add it to the same day.


                          thanks for all your help

                          Comment

                          Working...
                          X