To scripts som logger verdier til flate tekstfiler, med tidspunktet og verdien eller statusen separert med tab. Kan da enkelt limes inn i f.eks. Excel.
LogValueToFile.vb
Sub Main(parm As Object)
Dim deviceRef As Integer = parm.ToString()
Dim out As String = Now.ToShortDateString & " " & Now.ToLongTimeString & vbTab & hs.DeviceValueEx(deviceRef).ToString("f1")
Try
My.Computer.FileSystem.WriteAllText(hs.GetAppPath & "\Logs\" & deviceRef & ".txt", out & vbNewLine, True)
Catch ex As Exception
hs.WriteLog("LogValueToFile ERROR", ex.Message)
End Try
End Sub
Å hente status kan være verre, for det er flere måter å gjøre det på.
LogStatusToFile.vb
Sub Main(parm As Object)
Dim deviceRef As Integer = parm.ToString()
Dim out As String = Now.ToShortDateString & " " & Now.ToLongTimeString & vbTab & GetDeviceString(deviceRef)
Try
My.Computer.FileSystem.WriteAllText(hs.GetAppPath & "\Logs\" & deviceRef & ".txt", out & vbNewLine, True)
Catch ex As Exception
hs.WriteLog("LogStatusToFile ERROR", ex.Message)
End Try
End Sub
Function GetDeviceString(ByVal DeviceRef As Integer) As String
'Henter device string fra HS
Dim devstring As String = hs.DeviceString(DeviceRef)
If devstring <> String.Empty Then Return devstring
'Henter devicestring directe fra CAPI-status, hvis den finnes
devstring = hs.CAPIGetStatus(DeviceRef).Status
If devstring <> String.Empty Then Return devstring
'Henter devicestring fra CAPI beskrivelse (basert på value)
devstring = GetCapiString(DeviceRef)
If devstring <> String.Empty Then Return devstring
'Henter devicestring fra device class
Dim dev As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(DeviceRef)
devstring = dev.devString(Nothing)
If devstring <> String.Empty Then Return devstring
Return "String not found for " & DeviceRef & ", value = " & hs.DeviceValueEx(DeviceRef)
End Function
Function GetCapiString(ByVal DeviceRef As Integer) As String
For Each CAPI As HomeSeerAPI.CAPIControl In hs.CAPIGetControl(DeviceRef)
If CAPI.ControlValue = hs.DeviceValue(DeviceRef) Then Return CAPI.Label.ToString
Next
Return String.Empty
End Function
Kalles med device Ref som parameter.