This is my vbscript for incrementing the cooling set point for one of my A/C units. This code seemed to quit working after the HS4 upgrade. It worked perfectly for 2+ years prior to that. Forgive the logging and the verbose extra code. I have been trying to debug this for a while now. (Also, I am a c,c++, c# guy, so the vbscript is not really my cup of tea, so it is not optimized).
Here is the code:
Public Sub Main(ByVal param As String)
hs.WriteLog("Starting ","incMainCoolSetPoint")
Dim CoolSetPoint as Integer
Dim newCoolSetPoint as Integer
Dim deviceID as Integer
Dim statusDeviceID as Integer
deviceID = 324
statusDeviceID = 667
CoolSetPoint = hs.DeviceValue(deviceID)
hs.WriteLog("Current Cool setpoint ", CoolSetPoint)
newCoolSetPoint = CoolSetPoint +1
Dim results = SetDeviceByControlValue(deviceID, newCoolSetPoint)
Dim statusString as String
newCoolSetPoint = hs.DeviceValue(deviceID)
If newCoolSetPoint = CoolSetPoint Then
statusString = "Cool SetPoint did not change"
Else
statusString = "New Cool SetPoint: " & newCoolSetPoint
End If
hs.SetDeviceString(statusDeviceID, statusString, True)
hs.WriteLog("Status",statusString)
hs.WriteLog("CAPI results ", results)
End Sub
Function SetDeviceByControlValue(ByVal intDevRef As Integer, ByVal ctlValue As Integer) As CAPIControlResponse
' Sets this device (refID) by Control Value [CAPI: ControlValue] - e.g. 0 = off, 1 = Cool, 2 = Cool...
SetDeviceByControlValue = CAPIControlResponse.Indeterminate
For Each objCAPIControl As CAPIControl In hs.CAPIGetControl(intDevRef)
'hs.WriteLog("Control Value: ", LCase(objCAPIControl.ControlValue))
If LCase(objCAPIControl.ControlValue) = ctlValue Then
SetDeviceByControlValue = hs.CAPIControlHandler(objCAPIControl)
Exit For
End If
Next
End Function
From my log file:
Script
CAPI results
0
Script
Status
Cool SetPoint did not change
Script
Current Cool setpoint
72
Script
Starting
incMainCoolSetPoint
Here is the code:
Public Sub Main(ByVal param As String)
hs.WriteLog("Starting ","incMainCoolSetPoint")
Dim CoolSetPoint as Integer
Dim newCoolSetPoint as Integer
Dim deviceID as Integer
Dim statusDeviceID as Integer
deviceID = 324
statusDeviceID = 667
CoolSetPoint = hs.DeviceValue(deviceID)
hs.WriteLog("Current Cool setpoint ", CoolSetPoint)
newCoolSetPoint = CoolSetPoint +1
Dim results = SetDeviceByControlValue(deviceID, newCoolSetPoint)
Dim statusString as String
newCoolSetPoint = hs.DeviceValue(deviceID)
If newCoolSetPoint = CoolSetPoint Then
statusString = "Cool SetPoint did not change"
Else
statusString = "New Cool SetPoint: " & newCoolSetPoint
End If
hs.SetDeviceString(statusDeviceID, statusString, True)
hs.WriteLog("Status",statusString)
hs.WriteLog("CAPI results ", results)
End Sub
Function SetDeviceByControlValue(ByVal intDevRef As Integer, ByVal ctlValue As Integer) As CAPIControlResponse
' Sets this device (refID) by Control Value [CAPI: ControlValue] - e.g. 0 = off, 1 = Cool, 2 = Cool...
SetDeviceByControlValue = CAPIControlResponse.Indeterminate
For Each objCAPIControl As CAPIControl In hs.CAPIGetControl(intDevRef)
'hs.WriteLog("Control Value: ", LCase(objCAPIControl.ControlValue))
If LCase(objCAPIControl.ControlValue) = ctlValue Then
SetDeviceByControlValue = hs.CAPIControlHandler(objCAPIControl)
Exit For
End If
Next
End Function
From my log file:
8/19/2020 5:32:33 PM
Script
CAPI results
0
8/19/2020 5:32:33 PM
Script
Status
Cool SetPoint did not change
8/19/2020 5:32:33 PM
Script
Current Cool setpoint
72
8/19/2020 5:32:33 PM
Script
Starting
incMainCoolSetPoint
Comment