I am pulling hourly temperatures for a set period and wanting to change a device's value based on the lowest value in that period. I thought I would run an event to trigger the script whenever the hourly temps updated.
Since my VB skills are pretty rudimentary, I thought I would put my code on here for feedback to both a) see if it will even work and b) see if there is a better way to accomplish this.
I'd appreciate any feedback y'all want to give.
Since my VB skills are pretty rudimentary, I thought I would put my code on here for feedback to both a) see if it will even work and b) see if there is a better way to accomplish this.
I'd appreciate any feedback y'all want to give.
Code:
Sub Temps(parms As Object) ' Get Hourly Temps from Devices Dim Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8, Temp9, Temp10 as Integer Temp0 = hs.DeviceValueEx(889) Temp1 = hs.DeviceValueEx(894) Temp2 = hs.DeviceValueEx(38) Temp3 = hs.DeviceValueEx(904) Temp4 = hs.DeviceValueEx(909) Temp5 = hs.DeviceValueEx(914) Temp6 = hs.DeviceValueEx(919) Temp7 = hs.DeviceValueEx(924) Temp8 = hs.DeviceValueEx(929) Temp9 = hs.DeviceValueEx(935) Temp10 = hs.DeviceValueEx(939) ' Put Hourly Temps into Array Dim Temps(11) {Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8, Temp9, Temp10} ' Find minimum temp Dim Temp_min as Integer Temp_min = 100 For i = 0 to 11 If Temp_min > Temps(i) Then Temp_min = Temps(i) End If Next ' Set virtual device value based on min temp If Temp_min < 0 Then hs.SetDeviceValueByRef(885, 10, False) ElseIf Temp_min < 10 Then hs.SetDeviceValueByRef(885, 11, False) ElseIf Temp_min < 20 Then hs.SetDeviceValueByRef(885, 12, False) ElseIf Temp_min < 30 Then hs.SetDeviceValueByRef(885, 13, False) ElseIf Temp_min < 40 Then hs.SetDeviceValueByRef(885, 14, False) ElseIf Temp_min < 50 Then hs.SetDeviceValueByRef(885, 15, False) Else hs.SetDeviceValueByRef(885, 0, False) End If End Sub
Comment