Announcement

Collapse
No announcement yet.

How can I set a time + x

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

  • sparkman
    replied
    Looks great, I would do something like this:

    Code:
    Sub Main(ByVal Parms As Object)
    	Dim Immersun As Double
    	Immersun = hs.DeviceValueEx(68)
    	Dim dateValue As Date = #21:55#
    	Dim Evref as Integer
    	dim Ok as Boolean 
    	dim CC as CAPIControl
    	dim DeviceRef As Integer = 228  'deviceref of the device I want to control
    	Dim StopDateTime As Date
     
    	Select Case Immersun
    		Case < 1
    			StopDateTime = dateValue.AddMinutes(39)
    		Case 1.0 To 1.5
    			StopDateTime = dateValue.AddMinutes(30)
    		Case 1.5 To 2
    			StopDateTime = dateValue.AddMinutes(20)
    		Case 2.0 To 2.5
    			StopDateTime = dateValue.AddMinutes(15)
    		Case 2.5 To 3
    			StopDateTime = dateValue.AddMinutes(10)
    	End Select
     
    	If Immersun <= 3 Then 
    		Evref = hs.NewEventEx("Testevent", "Test","")
    		' set the trigger time of the event 
    		Ok = hs.EventSetTimeTrigger(Evref, CStr(StopDateTime))
    		' set the event to delete itself after it runs
    		hs.DeleteAfterTrigger_Set(Evref)
    		' add a device action to the event
    		CC = hs.CAPIGetSingleControlByUse(DeviceRef, ePairControlUse._Off)
    		hs.AddDeviceActionToEvent(Evref, CC)
    		hs.EnableEventByRef(Evref)  
    	End If
    End Sub
    Cheers
    Al

    Leave a comment:


  • mikee123
    replied
    Well thanks to your help I might have got it. Tested it and no errors in the log, but I will only see over the next few days if it does what I want. By just running the script, none of the cases is true, it creates an empty event with just if the time is 21.55 (as delay is 0)
    So last thing I need to do is enter a case > 3, which then jumps to the end, so does not create the event. How do I do that jump or end the script before the event creation ?

    This is the (nearly) finished script

    Code:
    Sub Main(ByVal Parms As Object)
             Dim Immersun As Double
            Immersun = hs.DeviceValueEx(68)
            Dim dateValue As Date = #21:55#
            dim Evref as Integer
     dim Delay as Integer   
     dim Ok as Boolean 
     dim CC as CAPIControl
     dim DeviceRef As Integer = 228  'deviceref of the device I want to control
    Dim StopDateTime As Date = dateValue.AddMinutes(Delay)
     
            Select Case Immersun
    
                 Case < 1
                 StopDateTime = dateValue.AddMinutes(39)
                 Case 1.0 To 1.5
                StopDateTime = dateValue.AddMinutes(30)
                Case 1.5 To 2
                StopDateTime = dateValue.AddMinutes(20)
               Case 2.0 To 2.5
                StopDateTime = dateValue.AddMinutes(15)
               Case 2.5 To 3
                StopDateTime = dateValue.AddMinutes(10)
               
             End Select
       
             Evref = hs.NewEventEx("Testevent", "Test","")
     ' set the trigger time of the event 
     Ok = hs.EventSetTimeTrigger(Evref, CStr(StopDateTime))
     ' set the event to delete itself after it runs
     hs.DeleteAfterTrigger_Set(Evref)
     ' add a device action to the event
     CC = hs.CAPIGetSingleControlByUse(DeviceRef, ePairControlUse._Off)
     hs.AddDeviceActionToEvent(Evref, CC)
     hs.EnableEventByRef(Evref)  
        End Sub

    Leave a comment:


  • sparkman
    replied
    Originally posted by mikee123 View Post
    This:
    CC = hs.CAPIGetSingleControlByUse(DeviceRef, ePairControlUse._Off)
    hs.AddDeviceActionToEvent(Evref, CC)
    will set my desired device to off in the created event ? So if I wanted 'on' I change ePairControlUse._Off to ePairControlUse._On ?

    if I understand it right my script should work. will give it a try later

    I do not use Event types (yet) for my events so I deleted that
    Correct. You'll likely need to specify "" for the Event Type rather than just deleting it as the help file does not indicate it's an optional parameter. As for your script, I would use the Case section to just set the Delay value and then have the event portion after the case section rather than copying it multiple times. Also, see my previous post about the Dim statement and that you can only have one per variable.

    Cheers
    Al

    Leave a comment:


  • mikee123
    replied
    Ok I think I understand it. This is what I've done

    Code:
    Sub Main(ByVal Parms As Object)
             Dim Immersun As Double
            Immersun = hs.DeviceValueEx(68)
            Dim dateValue As Date = #21:55#
            dim Evref as Integer
     
     dim Ok as Boolean 
     dim CC as CAPIControl
     dim DeviceRef As Integer = 1234  'deviceref of the device I want to control
     
            Select Case Immersun
    
                 Case < 1
    
                 dim Delay as Integer = 15
                  Dim newDateValue As Date = dateValue.AddMinutes(15) 
             Evref = hs.NewEventEx("Testevent", "Test")
     ' set the trigger time of the event 
     Ok = hs.EventSetTimeTrigger(Evref, CStr(newDateValue))
     ' set the event to delete itself after it runs
     hs.DeleteAfterTrigger_Set(Evref)
     ' add a device action to the event
     CC = hs.CAPIGetSingleControlByUse(DeviceRef, ePairControlUse._Off)
     hs.AddDeviceActionToEvent(Evref, CC)
     hs.EnableEventByRef(Evref)  
          
                 Case 1.0 To 1.5
    
                  dim Delay as Integer = 20
                  Dim newDateValue As Date = dateValue.AddMinutes(15) 
             Evref = hs.NewEventEx("Testevent", "Test")
     ' set the trigger time of the event 
     Ok = hs.EventSetTimeTrigger(Evref, CStr(newDateValue))
     ' set the event to delete itself after it runs
     hs.DeleteAfterTrigger_Set(Evref)
     ' add a device action to the event
     CC = hs.CAPIGetSingleControlByUse(DeviceRef, ePairControlUse._Off)
     hs.AddDeviceActionToEvent(Evref, CC)
     hs.EnableEventByRef(Evref)  
                
             End Select
       
        End Sub
    This:
    CC = hs.CAPIGetSingleControlByUse(DeviceRef, ePairControlUse._Off)
    hs.AddDeviceActionToEvent(Evref, CC)
    will set my desired device to off in the created event ? So if I wanted 'on' I change ePairControlUse._Off to ePairControlUse._On ?

    if I understand it right my script should work. will give it a try later

    I do not use Event types (yet) for my events so I deleted that
    Last edited by mikee123; August 1, 2016, 10:21 AM.

    Leave a comment:


  • sparkman
    replied
    Originally posted by mikee123 View Post
    Code:
                 Case < 1
                  Dim newDateValue As Date = dateValue.AddMinutes(15)  
                  
                 Case 1.0 To 1.5
                   Dim newDateValue As Date = dateValue.AddMinutes(20)
    Note that you can't "Dim" the same variable multiple times. You'd have to do it like this:

    Code:
     Dim newDateValue As Date
                 Case < 1
                  newDateValue = dateValue.AddMinutes(15)  
                  
                 Case 1.0 To 1.5
                  newDateValue = dateValue.AddMinutes(20)

    Leave a comment:


  • sparkman
    replied
    What you want to do then is have the script create an event that runs at the required time and then deletes itself. I do something similar in one of my scripts. Here's a code snippet that creates an event to turn a device off:

    Code:
    	dim Evref as Integer
    	dim Delay as Integer = 15
    	dim Ok as Boolean 
    	dim CC as CAPIControl
    	dim DeviceRef As Integer = 1234
    
    	Dim StopDateTime As Date = DateTime.Now.AddMinutes(Delay)
    
    	Evref = hs.NewEventEx("Event Name", "Event Group", "Event Type")
    	' set the trigger time of the event 
    	Ok = hs.EventSetTimeTrigger(Evref, CStr(StopDateTime))
    	' set the event to delete itself after it runs
    	hs.DeleteAfterTrigger_Set(Evref)
    	' add a device action to the event
    	CC = hs.CAPIGetSingleControlByUse(DeviceRef, ePairControlUse._Off)
    	hs.AddDeviceActionToEvent(Evref, CC)
    	hs.EnableEventByRef(Evref)

    Leave a comment:


  • mikee123
    replied
    This is the sort of script I had in mind, with the line below just trying to show what I am trying to achieve

    at time Date hs.TriggerEvent("x1") or hs.setdevicevalue(123) to 0

    Code:
    Sub Main(ByVal Parms As Object)
             Dim Immersun As Double
            Immersun = hs.DeviceValueEx(68)
            Dim dateValue As Date = #21:55#
    
             Select Case Immersun
    
                 Case < 1
                  Dim newDateValue As Date = dateValue.AddMinutes(15)  
                  
                 Case 1.0 To 1.5
                   Dim newDateValue As Date = dateValue.AddMinutes(20) 
    
                 Case > 1.5 to 2
                    Dim newDateValue As Date = dateValue.AddMinutes(25)
    
                 Case > 2 to 2.5
                    Dim newDateValue As Date = dateValue.AddMinutes(30)
    
                 Case > 2.5 to 3
                    Dim newDateValue As Date = dateValue.AddMinutes(35)
    
             End Select
    
       at time Date hs.TriggerEvent("x1") or hs.setdevicevalue(123) to 0
    
         End Sub

    Leave a comment:


  • mikee123
    replied
    Originally posted by sparkman View Post
    Yes, a bit cryptic. Something like this should work:

    Dim dateValue As Date = #21:55#
    Dim newDateValue As Date = dateValue.AddMinutes(15)
    Now that is what you would hope to find in a manual, that makes it perfectly clear.
    Can I then use 'Date' either in a script to trigger a setdevicevalue action at the time 'Date', or if that's not possible use 'Date' in an event, to trigger an event at time 'Date'

    Leave a comment:


  • sparkman
    replied
    Yes, a bit cryptic. Something like this should work:

    Dim dateValue As Date = #21:55#
    Dim newDateValue As Date = dateValue.AddMinutes(15)
    Last edited by sparkman; July 31, 2016, 04:59 PM.

    Leave a comment:


  • mikee123
    replied
    Ok trying to read that I think that's written in Chinese. .. lol
    I think I might get it will have to have another look and try to understand it. Why can't they give simple examples... its so hard to understand.
    Anyway I noticed this isn't all I need to solve my problem, as I need the resulting time of that calculation (time + x) needs to be used to trigger a event or a device action. So I could either try to trigger an event from the script, or keep it all in a script and: at time + x setdevicevalue. ..
    I think I would prefer to keep it all in a script then it's all in one place. Unless it's going to be even more complicated than setting the time...

    Leave a comment:


  • sparkman
    replied
    You can use the vb.net AddMinutes method: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx.

    Cheers
    Al

    Leave a comment:


  • mikee123
    started a topic How can I set a time + x

    How can I set a time + x

    I want to use time + x minutes in a script. I have various cases, and depending on case I want to add a different amount of minutes to a set time. So in my first case it would be

    21:55 + 30 minutes

    Is that doable ? I know how to do the case, it's just the time + x which I don't know how to do
Working...
X