' does not YET support 1WIO syntax! ' this script reads data from TEMP08 and stores received sensor readings into HS virtual devices ' Created by Mitch Matteau 02-12-21 '============================================================= ' HS virtual devices used; ' r1 to r19 for DS18S20 sensors ' r20-29 for humidity sensor '============================================================= sub main(data) '============================================================= dim i dim result dim virt_device dim default_hc dim prev_result dim wind_dirn dim wind_spd dim wind_gust dim high_wind dim rain_history dim rain_today dim rain_absolute dim SwitchStatus dim SwitchNumber dim SwitchBase ' virtual device list default_hc = "r" wind_dirn = "z7" wind_spd = "z4" wind_gust ="z1" high_wind = "v6" rain_history = "v8" rain_today = "v7" rain_absolute = "v9" SwitchBase = "s" '============================================================= ' Check if the received data is from a temperature reading '============================================================= if mid(data,1,4)="Temp" then sensorid = mid(data,7,2) if left(sensorid,1) = "0" then sensorid=mid(sensorid,2,1) end if i = Instr(data,"=") result=trim(mid(data,i+1)) if right(result,1)="F" or right(result,1)="C" then result = left(result,(len(result)-1)) end if if CInt(sensorid)<=19 then virt_device=default_hc+sensorid prev_result=hs.DeviceString(virt_device) end if '============================================================= ' eliminate false readings ' false readings are replaced with the previous reading '============================================================= if left(result,3) = "???" then result = prev_result end if if left(result,3) = "185" then '185 is an indicator that the device is not connected result = prev_result end if '============================================================= ' Now save current readings into HomeSeer '============================================================= hs.SetDeviceString virt_device,result if result<>prev_result then hs.SetDeviceLastChange virt_device, Now() hs.SetDeviceValue virt_device,result end if end if '============================================================= ' Humidity Sensor Capture '============================================================= if left(data,10)="Humidity #" then i=Instr(data,"#") sensorid=mid(data,i+1,2) if left(sensorid,1) = "0" then sensorid=mid(sensorid,2,1) end if virt_device=default_hc+CStr(CInt(sensorid)+19) prev_result=hs.DeviceString(virt_device) i = Instr(data,"=") result = Trim(mid(data,i+1)) if result="???" then result=prev_result hs.Writelog "Humidity","Sensor error on #"+sensorid end if hs.SetDeviceString virt_device,result if result<>prev_result then hs.SetDeviceLastChange virt_device, Now() end if end if '============================================================= ' Version capture ' virtual device z17 used to capture the data '============================================================= if mid(data,1,6)="TEMP08" then version_id = "z17" hs.SetDeviceString version_id,data hs.SetDeviceLastChange version_id, Now() end if '============================================================= ' Relay Status capture ' virtual devices z31 through z38 used to capture the data '============================================================= if mid(data,1,5)="Relay" then i = Instr(data,"=") data = mid(data,i+1) for i=1 to 8 virt_device= "z3"+trim(CStr(i)) a = trim(hs.StringItem(data,i,",")) if a<>hs.DeviceString(virt_device) then hs.SetDeviceString virt_device,a hs.SetDeviceLastChange virt_device,Now() end if next end if '============================================================= ' Wind Direction capture '============================================================= if left(data,9)="Wind Dirn" then result = mid(data,10) position = InStr(result,"=") if position<>0 then a = mid(result,position+1) ' wind direction if a <>"???" then hs.SetDeviceString wind_dirn,a hs.SetDeviceValue wind_dirn,0 end if end if end if '============================================================= ' Wind Speed capture '============================================================= If left(data,10)="Wind Speed" Then result = mid(data,11) position = InStr(result,"=") If position<>0 then result = mid(result,position+1) a = hs.StringItem(result,1,",") 'wind speed a = Trim(replace(a,"MPH","")) If left(a,3)<>"???" then hs.SetDeviceString wind_spd,a hs.SetDeviceValue wind_spd,CInt(a) else a=0 end if b = hs.DeviceString(high_wind) if isnumeric(b) then b = CInt(hs.DeviceString(high_wind)) else b = 0 hs.SetDeviceString high_wind,"0" hs.SetDeviceLastChange high_wind, Now() end if if Cint(a) > CInt(b) then hs.SetDeviceString high_wind,CStr(a) hs.SetDeviceLastChange high_wind, Now() hs.WriteLog "HIGH WIND",a+" mph" hs.CreateVar("HWNDT") hs.SaveVar "HWNDT",Time() end if a = trim(replace(hs.StringItem(result,2,","),"Gust = ","")) hs.SetDeviceString wind_gust,a hs.SetDeviceValue wind_gust,CInt(a) End if end if '============================================================= ' Rain Counts '============================================================= if Left(data,4)="Rain" Then position=InStr(data,"=") If position<>0 then b = mid(data,position+1) ' rain count If left(b,3)<>"???" then b = trim(replace(b," Inch","")) ' remove units c = hs.DeviceString (rain_history) ' History Info a = hs.StringItem(c,7,",") ' Yesterday's count hs.SetDeviceString rain_absolute,b ' absolute rain count hs.SetDeviceLastChange rain_absolute, Now() If IsNumeric(b) then l = CSng(b) ' Value of Absolute count If Not IsNumeric(a) then k = l ' on error, assume no count Else k = CSng(a) ' Value of Yesterday's count End If If (l-k) > 10 then a = "0.00" ' can't do more than 9 inches in 1 cycle Else a = CStr(Round((l-k),2)) ' Result is today's count End If If IsNumeric(a) then hs.SetDeviceString rain_today,a ' Today's count hs.SetDeviceValue rain_today,CInt(a) d = "" For i = 1 to 7 d = d + hs.StringItem(c,i,",")+"," Next d = d + b hs.SetDeviceString rain_history,d ' Restore history info hs.SetDeviceLastChange rain_history, Now() End If End If End If End If End If '============================================================= ' Switch Status Capture and transfer '============================================================= if Left(data,6)="Switch" Then SwitchNumber = SwitchBase+mid(data,Instr(data,"#")+1,2) SwitchStatus = mid(data,Instr(data,"=")+1,3) if left(SwitchStatus,2)="On" then SwitchStatus="On" hs.execX10 SwitchNumber,SwitchStatus,0 end if end if '============================================================= ' use the following to debug your connection to TEMP08... hs.writelog "TEMP08 RECEIVED",data end Sub