Announcement

Collapse
No announcement yet.

Creating and modifying events, CAPI

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

    Creating and modifying events, CAPI

    Hello. I did a fair amount of scripting many years ago on HS2. I'm now trying to write some scripts for HS3 and finding things have changed a lot (and IMO not for the better). Can anyone point me to example code for creating and modifying events? Also using CAPI? The docs have almost no examples, which makes it very hard to figure things out.

    In particular, what I'm trying to do right now is create an event, delay execution for X minutes, turn off a device, then have the event delete itself. I know you use NewEventEx to create an event and it has a property
    Flag_Delete_After_Trigger that will make it delete, but I don't know how to set that property or how to accomplish the delay.

    #2
    Originally posted by cormanaz View Post
    Hello. I did a fair amount of scripting many years ago on HS2. I'm now trying to write some scripts for HS3 and finding things have changed a lot (and IMO not for the better). Can anyone point me to example code for creating and modifying events? Also using CAPI? The docs have almost no examples, which makes it very hard to figure things out.

    In particular, what I'm trying to do right now is create an event, delay execution for X minutes, turn off a device, then have the event delete itself. I know you use NewEventEx to create an event and it has a property
    Flag_Delete_After_Trigger that will make it delete, but I don't know how to set that property or how to accomplish the delay.

    You need to check out tenhold's helpful programs
    http://www.tenholder.net/tenware2/homeseer.aspx
    They are awesome.

    Comment


      #3
      Originally posted by cormanaz View Post
      Hello. I did a fair amount of scripting many years ago on HS2. I'm now trying to write some scripts for HS3 and finding things have changed a lot (and IMO not for the better). Can anyone point me to example code for creating and modifying events? Also using CAPI? The docs have almost no examples, which makes it very hard to figure things out.

      In particular, what I'm trying to do right now is create an event, delay execution for X minutes, turn off a device, then have the event delete itself. I know you use NewEventEx to create an event and it has a property
      Flag_Delete_After_Trigger that will make it delete, but I don't know how to set that property or how to accomplish the delay.
      There are very little in the way of event scripting commands for events in HS3 compared to HS2 and some animated discussions about it and the reasons behind it.

      You won't be able to add a delay to an event but you might be able to use http://www.homeseer.com/support/home...imetrigger.htm if you were creative. I don't think you can set the delete after trigger either, you could use the hs.deleteevent though if you were again creative.

      Comment


        #4
        I think the Plugin Development documentation contains what you're after including some examples. I don't quite remember where I found it though.
        Real courage is not securing your Wi-Fi network.

        Comment


          #5
          @mrhappy So it's not just my imagination. Honestly, I regret changing over to HS3 and paying the $$ to do so. Scripting is less capable. The UI is poorly designed and confusing. It's more like a downgrade than an upgrade. I've never experienced a newer version where the software gets worse!

          Comment


            #6
            @jayman13 thanks I will check that out.

            Comment


              #7
              Originally posted by cormanaz View Post
              @mrhappy So it's not just my imagination. Honestly, I regret changing over to HS3 and paying the $$ to do so. Scripting is less capable. The UI is poorly designed and confusing. It's more like a downgrade than an upgrade. I've never experienced a newer version where the software gets worse!
              There some info here which might explain http://forums.homeseer.com/showthread.php?t=165610

              Comment


                #8
                Here's a script that I use to create delayed events and have the delete after running:

                Code:
                Sub Main(ByVal Parms As String)
                	'blockheater.vb
                	'Version 3.0 for HS3
                	'This script performs the following functions:
                	'	- creates events to turn two devices on and off with delays based on temperature (TemperatureDevice)
                	'	- increases duration of the on events at a certain time (StartTime)
                	'The intent is to run this script every 30 minutes
                	'The parameters right below can be modified to suit your requirements but can be left at default
                	Dim logName As String = "Block Heater"	'set log type for HS log
                	Dim Debug As Boolean = False				'set to True if the script give you errors and it will provide additional info in the HS3 log to help troubleshoot
                	Dim Temp0 = CInt(hs.GetINISetting ("Settings","Temp0","-10","blockheater.ini"))
                	Dim Temp1 = CInt(hs.GetINISetting ("Settings","Temp1","-15","blockheater.ini"))
                	Dim Temp2 = CInt(hs.GetINISetting ("Settings","Temp2","-25","blockheater.ini"))
                	Dim Temp3 = CInt(hs.GetINISetting ("Settings","Temp3","-35","blockheater.ini"))
                	Dim Temp1Minutes = CInt(hs.GetINISetting ("Settings","Temp1Minutes","5","blockheater.ini"))
                	Dim Temp2Minutes = CInt(hs.GetINISetting ("Settings","Temp2Minutes","10","blockheater.ini"))
                	Dim Temp3Minutes = CInt(hs.GetINISetting ("Settings","Temp3Minutes","14","blockheater.ini"))
                	Dim TempMinutes = CInt(hs.GetINISetting ("Settings","TempMinutes","10","blockheater.ini"))
                	Dim TemperatureDevice = CInt(hs.GetINISetting ("Settings","TemperatureDevice","519","blockheater.ini"))
                	Dim BlockHeater1 = Cint(hs.GetINISetting ("Settings","BlockHeater1","617","blockheater.ini"))
                	Dim BlockHeater2 = Cint(hs.GetINISetting ("Settings","BlockHeater2","618","blockheater.ini"))
                	Dim StartTime = Hour(TimeValue (hs.GetINISetting ("Settings","StartTime","8:00 AM","blockheater.ini")))
                
                	Dim OutsideTemp As Integer = hs.deviceValue(TemperatureDevice)
                		If Debug Then hs.writelog(logName,Cstr(OutsideTemp))
                		'OutsideTemp = -32   'used to override the actual temp for troubleshooting purposes
                
                	If OutsideTemp <= Temp0 Then
                		
                		Dim CurrentDateTime As Date = Now 
                		Dim CurrentDate As Date = CurrentDateTime.Date
                			If Debug Then hs.writelog(logName,Cstr(CurrentDate))
                		Dim CurrentHour As Integer = CurrentDateTime.Hour
                			If Debug Then hs.writelog(logName,Cstr(CurrentHour))
                		Dim CurrentMinute As Integer = CurrentDateTime.Minute
                			If Debug Then hs.writelog(logName,Cstr(CurrentMinute))
                		Dim CurrentTime As String = ""
                		Dim Delay As Integer = 0
                
                		If Math.Abs(StartTime-CurrentHour) <= 1 Then Delay = TempMinutes
                		If OutsideTemp <= Temp1 Then Delay = Temp1Minutes
                		If OutsideTemp <= Temp2 Then Delay = Temp2Minutes
                		If OutsideTemp <= Temp3 Then Delay = Temp3Minutes
                			If Debug Then hs.writelog(logName,Cstr(Delay))
                		
                		CurrentMinute = CurrentMinute + 5
                		If CurrentMinute >= 60 Then
                			CurrentMinute = CurrentMinute - 60
                			CurrentHour = CurrentHour + 1
                		End If
                
                		If CurrentHour >= 24 Then 
                			CurrentHour = CurrentHour - 24
                			CurrentDate = CurrentDateTime.AddDays(1)
                		End If
                
                		If CurrentMinute < 10 Then 
                			CurrentTime = CStr(CurrentHour) & ":0" & CStr(CurrentMinute)
                		Else 
                			CurrentTime = CStr(CurrentHour) & ":" & CStr(CurrentMinute)
                		End If 
                			If Debug Then hs.writelog(logName,CurrentTime)
                
                		'Create event for block heater 1
                		If Delay > 0 Then CreateEvent(CurrentTime, CurrentDate, Delay, BlockHeater1)
                
                		'Set Time for Block Heater 2 - Offset by 15 minutes from Block Heater 1
                		CurrentMinute = CurrentMinute + 15
                		If CurrentMinute >= 60 Then
                			CurrentMinute = CurrentMinute - 60
                			CurrentHour = CurrentHour + 1
                		End If
                
                		If CurrentHour >= 24 Then 
                			CurrentHour = CurrentHour - 24
                			CurrentDate = CurrentDateTime.AddDays(1)
                		End If
                
                		If CurrentMinute < 10 Then 
                			CurrentTime = CStr(CurrentHour) & ":0" & CStr(CurrentMinute)
                		Else 
                			CurrentTime = CStr(CurrentHour) & ":" & CStr(CurrentMinute)
                		End If 
                			If Debug Then hs.writelog(logName,CurrentTime)
                
                		'Create event for block heater 2
                		If Delay > 0 Then CreateEvent(CurrentTime, CurrentDate, Delay, BlockHeater2)
                
                		If Delay > 0 Then
                			hs.Writelog(logName,"Temperature is " & OutsideTemp & " °C.  Turning on Block Heaters for " & Delay & " minutes.")
                		Else
                			hs.Writelog(logName,"Too warm (" & OutsideTemp & " °C) to turn the block heaters on.")
                		End If
                
                	Else
                		hs.Writelog(logName,"Too warm (" & OutsideTemp & " °C) to turn the block heaters on.")
                		hs.CAPIControlHandler(hs.CAPIGetSingleControl(BlockHeater1,true ,"off",false,true))
                		hs.CAPIControlHandler(hs.CAPIGetSingleControl(BlockHeater2,true ,"off",false,true))
                	End If
                
                end sub
                
                
                Sub CreateEvent(StartTime,StartDate,Delay,DeviceName)
                	dim Evref as integer
                	dim Ok as Boolean 
                	dim CC as CAPIControl
                	Dim logName As String = "Block Heater Event Creation"	'set log type for HS log
                	Dim Debug As Boolean = True				'set to True if the script give you errors and it will provide additional info in the HS3 log to help troubleshoot
                
                	Dim StartDateTime As Date = CDate(StartDate & " " & StartTime)
                		If Debug Then hs.writelog(logName,CStr(StartDateTime))
                
                	' create a new event
                	Evref = hs.NewEventEx("Block Heater On " & Cstr(DeviceName), "Block Heaters", "Block Heaters")
                	' set the trigger time of the event 
                	Ok = hs.EventSetTimeTrigger(Evref, CStr(StartDateTime))
                	' set the event to delete itself after it runs
                	hs.DeleteAfterTrigger_Set(Evref)
                	' add a device action to the event
                	CC = hs.CAPIGetSingleControlByUse(DeviceName, ePairControlUse._On)
                	hs.AddDeviceActionToEvent(Evref, CC)
                	hs.EnableEventByRef(Evref)
                
                	Dim StopDateTime As Date = StartDateTime.AddMinutes(Delay)
                		If Debug Then hs.writelog(logName,CStr(StopDateTime))
                
                	' create a new event
                	Evref = hs.NewEventEx("Block Heater Off " & Cstr(DeviceName), "Block Heaters", "Block Heaters")
                	' 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(DeviceName, ePairControlUse._Off)
                	hs.AddDeviceActionToEvent(Evref, CC)
                	hs.EnableEventByRef(Evref)
                
                End Sub
                Cheers
                Al
                HS 4.2.8.0: 2134 Devices 1252 Events
                Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                Comment


                  #9
                  Thanks Al - by the looks of it hs.DeleteAfterTrigger_Set never managed to make it into the documentation either

                  Comment


                    #10
                    @sparkman, thanks. Just what I was looking for.

                    Comment

                    Working...
                    X