Re: Regen monitor script
Posted: Wed Jul 21, 2010 11:35 pm
Klopt. In de nieuwe url staat ook niet de plaats. Dat was de eerste url die ik gebruikte. Kijk maar: http://www.weeronline.nl/Go/FlashCharts ... Id=4057886
Domotica - Home Automation Forum
https://domoticaforum.eu/
Code: Select all
' RegenMonitor.vb script
' Author: Alexander
' Version: 2.2
' Last Update: 21-07-2010 23:40
' ChangeLog:
' 1.0: Initial
' 1.1: - Added the ability to stop the script if the website doesn't return a known text, if that is the case the device will get the status unknown.
' - If the website would update the rain prediction to a lower time, the event that is already created will get the earlier condition.
' - If the time of the rain prediction is suddenly earlier that the current time, the device will be set instantly and earlier created event is deleted.
' - Parameters have to be added. Example ("Main","4057886;v7"). First is the geoAreaId and second is the device.
' - First code optimization
' - Code fault in handling if rain is predicted was not defined
' 2.0: - Script rewrite for other url
' 2.1: - Added DeviceStatusString
' 2.2: - Multi Devices & Rain measurement in text or number support. Activation by extra parameters like ("Main","4057886;v7;yes;yes")
Sub Main(ByVal Params As String)
Dim strGeoAreaId As String = hs.StringItem(Params, 1, ";")
Dim strDevice As String = hs.StringItem(Params, 2, ";")
Dim blRainInText As Boolean = hs.StringItem(Params, 3, ";") = "yes"
Dim blMultiDevice As Boolean = hs.StringItem(Params, 4, ";") = "yes"
Dim strData As String = hs.GetURL("www.weeronline.nl", "/Go/FlashCharts/RainImmediate?geoAreaId=" & strGeoAreaId, false, 80)
Dim i As Integer
If blMultiDevice Then
For i = 0 To 23
If hs.DeviceExistsRef(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = -1 Then
Dim dv As Object
dv = hs.GetDeviceByRef(hs.NewDeviceRef("Regen" & "-" & i+1))
dv.hc = GetChar(strDevice,1)
dv.dc = Val(GetChar(strDevice,2))+i
dv.misc = "&h10"
End If
Next
Else
If hs.DeviceExistsRef(GetChar(strDevice,1) & GetChar(strDevice,2)) = -1 Then
Dim dv As Object
dv = hs.GetDeviceByRef(hs.NewDeviceRef("Regen"))
dv.hc = GetChar(strDevice,1)
dv.dc = GetChar(strDevice,2)
dv.misc = "&h10"
End If
End If
If (Not InStr(strData, "?xml") > 0) Then
hs.SetDeviceString(strDevice, "Website weeronline.nl down")
hs.SetDeviceStatus(strDevice, 17)
hs.SetDeviceLastChange(strDevice, Now)
Else
Dim strArr() As String
Dim strDate(24) As String
Dim strTime(24) As String
Dim strValue(24) As String
strArr = strdata.split(chr(13))
Dim j As Integer
For i = 12 To strArr.Length - 1
If InStr(strArr(i), "<date>") > 0 Then
Dim a As Integer = InStr(strArr(i), "<date>")
Dim b As Integer = InStr(strArr(i), "</date>")
Dim c As Integer = InStr(strArr(i), "<date>")
Dim strTmp = strArr(i).SubString(a+5, b-c-6)
strDate(j) = Left(strTmp, InStr(strTmp, "T")-1)
strTime(j) = Mid(strTmp, InStr(strTmp, "T")+1)
Else If InStr(strArr(i), "<item") > 0 Then
Dim a As Integer = InStr(strArr(i), "value=")
Dim b As Integer = InStr(strArr(i), " />")
Dim c As Integer = InStr(strArr(i), "value=")
strValue(j) = strArr(i).SubString(a+6, b-c-8)
j +=1
End If
Next
For i = 0 To j - 1
Dim strEvent As String = strDate(i) & "_" & strTime(i)
If hs.EventExists(strEvent) Then hs.DeleteEvent(strEvent)
Dim lngValueCommand As Long = Math.Round((Left(strValue(i), InStr(strValue(i), " mm") - 1) * 100), 0)
Dim strValueCommand As String
If blMultiDevice Then
strValueCommand = "&hs.SetDeviceValue(" & GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i & ", " & lngValueCommand.toString() & ")"
Else
strValueCommand = "&hs.SetDeviceValue(" & strDevice & ", " & lngValueCommand.toString() & ")"
End If
If (DateTime.Compare(strTime(i), FormatDateTime(Now, 4)) <= 0) Then
If InStr(strValue(i), "0 mm/uur") > 0 Then
If blMultiDevice Then
If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 3 Then hs.Transmit(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, "off")
hs.SetDeviceValue(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, 0)
hs.SetDeviceString(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i))
Else
If Not hs.DeviceStatus(strDevice) = 3 Then hs.Transmit(strDevice, "off")
hs.SetDeviceValue(strDevice, 0)
hs.SetDeviceString(strDevice, WeerType(lngValueCommand, blRainInText))
End If
Else
If blMultiDevice Then
If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 2 Then hs.Transmit(strDevice, "on")
hs.SetDeviceValue(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, lngValueCommand.toString())
hs.SetDeviceString(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i))
Else
If Not hs.DeviceStatus(strDevice) = 2 Then hs.Transmit(strDevice, "on")
hs.SetDeviceValue(strDevice, lngValueCommand.toString())
hs.SetDeviceString(strDevice, WeerType(lngValueCommand, blRainInText))
End If
End If
Else If Not blMultiDevice Then
If (InStr(strValue(i), "0 mm/uur") > 0) And ((Not InStr(strValue(i-1), "0 mm/uur") > 0) or (i = 0)) Then
hs.NewTimeEvent(strEvent, strTime(i), "", 1, 1, 1, 1, 1, 1, 1, strDevice & ":off", 1, "", "")
hs.AddAction(hs.GetEventRefByName(strEvent), 5, strValueCommand)
hs.AddAction(hs.GetEventRefByName(strEvent), 5, "&hs.SetDeviceString(" & strDevice & ", " & WeerType(lngValueCommand, blRainInText) & ")")
hs.EnableEvent(strEvent)
Else If (Not InStr(strValue(i), "0 mm/uur") > 0) Then
hs.NewTimeEvent(strEvent, strTime(i), "", 1, 1, 1, 1, 1, 1, 1, strDevice & ":on", 1, "", "")
hs.AddAction(hs.GetEventRefByName(strEvent), 5, strValueCommand)
hs.AddAction(hs.GetEventRefByName(strEvent), 5, "&hs.SetDeviceString(" & strDevice & ", " & WeerType(lngValueCommand, blRainInText) & ")")
hs.EnableEvent(strEvent)
End If
Else
If InStr(strValue(i), "0 mm/uur") > 0 Then
If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 3 Then hs.Transmit(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, "off")
hs.SetDeviceValue(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, 0)
hs.SetDeviceString(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i))
Else
If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 2 Then hs.Transmit(strDevice, "on")
hs.SetDeviceValue(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, lngValueCommand.toString())
hs.SetDeviceString(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i))
End If
End If
'hs.writelog("RegenMonitor", strDate(i) & " - " & strTime(i) & " - " & strValue(i))
Next
End If
End Sub
Function WeerType(Value As Integer, blRainInText As Boolean) As String
If blRainInText Then
Select Case Value
Case 0
Return "Geen regen"
Case 1 To 100
Return "Lichte regen"
Case 101 To 500
Return "Matige regen"
Case 501 To 2500
Return "Zware regen"
Case Is > 2500
Return "Wolkbreuk"
End Select
Else
Return Math.Round(Value/100, 2).toString() & " mm/uur"
End If
End Function
Glad ijsAlexander wrote: Wat nog te doen:
- meerdere woonplaatsen checken zodat afhankelijk van de windrichting de logische woonplaats te gebruiken voor verwachting
Code: Select all
Function WeerType(Value As Integer, blRainInText As Boolean) As String
If blRainInText Then
Select Case Value
Case 0
Return "<img src='images\RainDetection\no_rain.png'> Geen regen"
Case 1 To 100
Return "<img src='images\RainDetection\light_rain.png'> Lichte regen"
Case 101 To 500
Return "<img src='images\RainDetection\medium_rain.png'> Matige regen"
Case 501 To 2500
Return "<img src='images\RainDetection\heavy_rain.png'> Zware regen"
Case Is > 2500
Return "<img src='images\RainDetection\thunderstorm.png'> Wolkbreuk"
End Select
Else
Return Math.Round(Value/100, 2).toString() & " mm/uur"
End If
End Function
Code: Select all
If blMultiDevice Then
For i = 0 To 23
If hs.DeviceExistsRef(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = -1 Then
Dim dv As Object
dv = hs.GetDeviceByRef(hs.NewDeviceRef("Regen" & "-" & i+1))
dv.hc = GetChar(strDevice,1)
dv.dc = Val(GetChar(strDevice,2))+i
dv.misc = "&h10"
dv.location = "Virtual - Monitoring"
dv.dev_type_string = "Expected Rain Monitoring"
End If
Next
Else
If hs.DeviceExistsRef(GetChar(strDevice,1) & GetChar(strDevice,2)) = -1 Then
Dim dv As Object
dv = hs.GetDeviceByRef(hs.NewDeviceRef("Regen"))
dv.hc = GetChar(strDevice,1)
dv.dc = GetChar(strDevice,2)
dv.misc = "&h10"
dv.location = "Virtual - Monitoring"
dv.dev_type_string = "Expected Rain Monitoring"
End If
End If
Code: Select all
23-7-2010 14:37:49 Info Event Trigger "Regencheck"
23-7-2010 14:37:49 Info Running script in background: regenmonitor.vb("Main","4057605;v1").)
23-7-2010 14:37:50 Error Script compile error: Argument not specified for parameter 'data2' of 'Public Function Transmit(code As String, cmd As String, dimval As Integer, data2 As Integer, wait As Boolean, [raw As Boolean = False], [update As Boolean = True], [out_interface As Integer = 0]) As Integer'.on line 104
23-7-2010 14:37:50 SCR Option Strict Offimports Schedulerimports SystemPublic Module scriptcode4#Region "Automatically generated code, do not modify"'Automatically generated code, do not modify'Event Sources Begin Public WithEvents hs As Scheduler.hsapplication Public WithEvents hsp As scheduler.hsp Public WithEvents hssystem As scheduler.phone0'Event Sources End'End of automatically generated code#End Region' RegenMonitor.vb script' Author: Alexander' Version: 2.2' Last Update: 21-07-2010 23:40' ChangeLog:' 1.0: Initial' 1.1: - Added the ability to stop the script if the website doesn't return a known text, if that is the case the device will get the status unknown.' - If the website would update the rain prediction to a lower time, the event that is already created will get the earlier condition.' - If the time of the rain prediction is suddenly earlier that the current time, the device will be set instantly and earlier created event is deleted.' - Parameters have to be added. Example ("Main","4057886;v7"). First is the geoAreaId and second is the device.' - First code optimization' - Code fault in handling if rain is predicted was not defined' 2.0: - Script rewrite for other url' 2.1: - Added DeviceStatusString' 2.2: - Multi Devices & Rain measurement in text or number support. Activation by extra parameters like ("Main","4057886;v7;yes;yes")Sub Main(ByVal Params As String) Dim strGeoAreaId As String = hs.StringItem(Params, 1, ";") Dim strDevice As String = hs.StringItem(Params, 2, ";") Dim blRainInText As Boolean = hs.StringItem(Params, 3, ";") = "yes" Dim blMultiDevice As Boolean = hs.StringItem(Params, 4, ";") = "yes" Dim strData As String = hs.GetURL("www.weeronline.nl", "/Go/FlashCharts/RainImmediate?geoAreaId=" & strGeoAreaId, false, 80) Dim i As Integer If blMultiDevice Then For i = 0 To 23 If hs.DeviceExistsRef(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = -1 Then Dim dv As Object dv = hs.GetDeviceByRef(hs.NewDeviceRef("Regen" & "-" & i+1)) dv.hc = GetChar(strDevice,1) dv.dc = Val(GetChar(strDevice,2))+i dv.misc = "&h10" End If Next Else If hs.DeviceExistsRef(GetChar(strDevice,1) & GetChar(strDevice,2)) = -1 Then Dim dv As Object dv = hs.GetDeviceByRef(hs.NewDeviceRef("Regen")) dv.hc = GetChar(strDevice,1) dv.dc = GetChar(strDevice,2) dv.misc = "&h10" End If End If If (Not InStr(strData, "?xml") > 0) Then hs.SetDeviceString(strDevice, "Website weeronline.nl down") hs.SetDeviceStatus(strDevice, 17) hs.SetDeviceLastChange(strDevice, Now) Else Dim strArr() As String Dim strDate(24) As String Dim strTime(24) As String Dim strValue(24) As String strArr = strdata.split(chr(13)) Dim j As Integer For i = 12 To strArr.Length - 1 If InStr(strArr(i), "") > 0 Then Dim a As Integer = InStr(strArr(i), "") Dim b As Integer = InStr(strArr(i), "") Dim c As Integer = InStr(strArr(i), "") Dim strTmp = strArr(i).SubString(a+5, b-c-6) strDate(j) = Left(strTmp, InStr(strTmp, "T")-1) strTime(j) = Mid(strTmp, InStr(strTmp, "T")+1) Else If InStr(strArr(i), " 0 Then Dim a As Integer = InStr(strArr(i), "value=") Dim b As Integer = InStr(strArr(i), " />") Dim c As Integer = InStr(strArr(i), "value=") strValue(j) = strArr(i).SubString(a+6, b-c-8) j +=1 End If Next For i = 0 To j - 1 Dim strEvent As String = strDate(i) & "_" & strTime(i) If hs.EventExists(strEvent) Then hs.DeleteEvent(strEvent) Dim lngValueCommand As Long = Math.Round((Left(strValue(i), InStr(strValue(i), " mm") - 1) * 100), 0) Dim strValueCommand As String If blMultiDevice Then strValueCommand = "&hs.SetDeviceValue(" & GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i & ", " & lngValueCommand.toString() & ")" Else strValueCommand = "&hs.SetDeviceValue(" & strDevice & ", " & lngValueCommand.toString() & ")" End If If (DateTime.Compare(strTime(i), FormatDateTime(Now, 4)) <= 0) Then If InStr(strValue(i), "0 mm/uur") > 0 Then If blMultiDevice Then If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 3 Then hs.Transmit(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, "off") hs.SetDeviceValue(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, 0) hs.SetDeviceString(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i)) Else If Not hs.DeviceStatus(strDevice) = 3 Then hs.Transmit(strDevice, "off") hs.SetDeviceValue(strDevice, 0) hs.SetDeviceString(strDevice, WeerType(lngValueCommand, blRainInText)) End If Else If blMultiDevice Then If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 2 Then hs.Transmit(strDevice, "on") hs.SetDeviceValue(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, lngValueCommand.toString()) hs.SetDeviceString(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i)) Else If Not hs.DeviceStatus(strDevice) = 2 Then hs.Transmit(strDevice, "on") hs.SetDeviceValue(strDevice, lngValueCommand.toString()) hs.SetDeviceString(strDevice, WeerType(lngValueCommand, blRainInText)) End If End If Else If Not blMultiDevice Then If (InStr(strValue(i), "0 mm/uur") > 0) And ((Not InStr(strValue(i-1), "0 mm/uur") > 0) or (i = 0)) Then hs.NewTimeEvent(strEvent, strTime(i), "", 1, 1, 1, 1, 1, 1, 1, strDevice & ":off", 1, "", "") hs.AddAction(hs.GetEventRefByName(strEvent), 5, strValueCommand) hs.AddAction(hs.GetEventRefByName(strEvent), 5, "&hs.SetDeviceString(" & strDevice & ", " & WeerType(lngValueCommand, blRainInText) & ")") hs.EnableEvent(strEvent) Else If (Not InStr(strValue(i), "0 mm/uur") > 0) Then hs.NewTimeEvent(strEvent, strTime(i), "", 1, 1, 1, 1, 1, 1, 1, strDevice & ":on", 1, "", "") hs.AddAction(hs.GetEventRefByName(strEvent), 5, strValueCommand) hs.AddAction(hs.GetEventRefByName(strEvent), 5, "&hs.SetDeviceString(" & strDevice & ", " & WeerType(lngValueCommand, blRainInText) & ")") hs.EnableEvent(strEvent) End If Else If InStr(strValue(i), "0 mm/uur") > 0 Then If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 3 Then hs.Transmit(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, "off") hs.SetDeviceValue(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, 0) hs.SetDeviceString(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i)) Else If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 2 Then hs.Transmit(strDevice, "on") hs.SetDeviceValue(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, lngValueCommand.toString()) hs.SetDeviceString(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i)) End If End If 'hs.writelog("RegenMonitor", strDate(i) & " - " & strTime(i) & " - " & strValue(i)) Next End IfEnd SubFunction WeerType(Value As Integer, blRainInText As Boolean) As String If blRainInText Then Select Case Value Case 0 Return "Geen regen" Case 1 To 100 Return "Lichte regen" Case 101 To 500 Return "Matige regen" Case 501 To 2500 Return "Zware regen" Case Is > 2500 Return "Wolkbreuk" End Select Else Return Math.Round(Value/100, 2).toString() & " mm/uur" End IfEnd FunctionEnd Module
Code: Select all
' RegenMonitor.vb script
' Author: Alexander
' Version: 2.3
' Last Update: 23-07-2010 17:52
' ChangeLog:
' 1.0: Initial
' 1.1: - Added the ability to stop the script if the website doesn't return a known text, if that is the case the device will get the status unknown.
' - If the website would update the rain prediction to a lower time, the event that is already created will get the earlier condition.
' - If the time of the rain prediction is suddenly earlier that the current time, the device will be set instantly and earlier created event is deleted.
' - Parameters have to be added. Example ("Main","4057886;v7"). First is the geoAreaId and second is the device.
' - First code optimization
' - Code fault in handling if rain is predicted was not defined
' 2.0: - Script rewrite for other url
' 2.1: - Added DeviceStatusString
' 2.2: - Multi Devices support
' 2.3: - Bugfix about the double quotes which didn't were added in setdevicestring commands
' - Added images from Rien and included those in the script for display
' - Added DeviceLocation and DeviceType option when created idea by Rien
Sub Main(ByVal Params As String)
' Customize this value if you want to change the new created device(s) if not already existing
Dim strDeviceLocation As String = "Virtual - Monitoring"
Dim strDeviceType As String = "Verwachte Regen Monitoring"
Dim strGeoAreaId As String = hs.StringItem(Params, 1, ";")
Dim strDevice As String = hs.StringItem(Params, 2, ";")
Dim blRainInText As Boolean = hs.StringItem(Params, 3, ";") = "yes"
Dim blMultiDevice As Boolean = hs.StringItem(Params, 4, ";") = "yes"
Dim strData As String = hs.GetURL("www.weeronline.nl", "/Go/FlashCharts/RainImmediate?geoAreaId=" & strGeoAreaId, false, 80)
Dim i As Integer
If blMultiDevice Then
For i = 0 To 23
If hs.DeviceExistsRef(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = -1 Then
Dim dv As Object
dv = hs.GetDeviceByRef(hs.NewDeviceRef("Regen" & "-" & i+1))
dv.hc = GetChar(strDevice,1)
dv.dc = Val(GetChar(strDevice,2))+i
dv.misc = "&h10"
dv.location = strDeviceLocation
dv.dev_type_string = strDeviceType
End If
Next
Else
If hs.DeviceExistsRef(GetChar(strDevice,1) & GetChar(strDevice,2)) = -1 Then
Dim dv As Object
dv = hs.GetDeviceByRef(hs.NewDeviceRef("Regen"))
dv.hc = GetChar(strDevice,1)
dv.dc = GetChar(strDevice,2)
dv.misc = "&h10"
dv.location = strDeviceLocation
dv.dev_type_string = strDeviceType
End If
End If
If (Not InStr(strData, "?xml") > 0) Then
hs.SetDeviceString(strDevice, "Website weeronline.nl down")
hs.SetDeviceStatus(strDevice, 17)
hs.SetDeviceLastChange(strDevice, Now)
Else
Dim strArr() As String
Dim strDate(24) As String
Dim strTime(24) As String
Dim strValue(24) As String
strArr = strdata.split(chr(13))
Dim j As Integer
For i = 12 To strArr.Length - 1
If InStr(strArr(i), "<date>") > 0 Then
Dim a As Integer = InStr(strArr(i), "<date>")
Dim b As Integer = InStr(strArr(i), "</date>")
Dim c As Integer = InStr(strArr(i), "<date>")
Dim strTmp = strArr(i).SubString(a+5, b-c-6)
strDate(j) = Left(strTmp, InStr(strTmp, "T")-1)
strTime(j) = Mid(strTmp, InStr(strTmp, "T")+1)
Else If InStr(strArr(i), "<item") > 0 Then
Dim a As Integer = InStr(strArr(i), "value=")
Dim b As Integer = InStr(strArr(i), " />")
Dim c As Integer = InStr(strArr(i), "value=")
strValue(j) = strArr(i).SubString(a+6, b-c-8)
j +=1
End If
Next
For i = 0 To j - 1
Dim strEvent As String = strDate(i) & "_" & strTime(i)
If hs.EventExists(strEvent) Then hs.DeleteEvent(strEvent)
Dim lngValueCommand As Long = Math.Round((Left(strValue(i), InStr(strValue(i), " mm") - 1) * 100), 0)
Dim strValueCommand As String
If blMultiDevice Then
strValueCommand = "&hs.SetDeviceValue(" & GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i & ", " & lngValueCommand.toString() & ")"
Else
strValueCommand = "&hs.SetDeviceValue(" & strDevice & ", " & lngValueCommand.toString() & ")"
End If
If (DateTime.Compare(strTime(i), FormatDateTime(Now, 4)) <= 0) Then
If InStr(strValue(i), "0 mm/uur") > 0 Then
If blMultiDevice Then
If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 3 Then hs.Transmit(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, "off")
hs.SetDeviceValue(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, 0)
hs.SetDeviceString(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i))
Else
If Not hs.DeviceStatus(strDevice) = 3 Then hs.Transmit(strDevice, "off")
hs.SetDeviceValue(strDevice, 0)
hs.SetDeviceString(strDevice, WeerType(lngValueCommand, blRainInText))
End If
Else
If blMultiDevice Then
If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 2 Then hs.Transmit(strDevice, "on")
hs.SetDeviceValue(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, lngValueCommand.toString())
hs.SetDeviceString(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i))
Else
If Not hs.DeviceStatus(strDevice) = 2 Then hs.Transmit(strDevice, "on")
hs.SetDeviceValue(strDevice, lngValueCommand.toString())
hs.SetDeviceString(strDevice, WeerType(lngValueCommand, blRainInText))
End If
End If
Else If Not blMultiDevice Then
If (InStr(strValue(i), "0 mm/uur") > 0) And ((Not InStr(strValue(i-1), "0 mm/uur") > 0) or (i = 0)) Then
hs.NewTimeEvent(strEvent, strTime(i), "", 1, 1, 1, 1, 1, 1, 1, strDevice & ":off", 1, "", "")
hs.AddAction(hs.GetEventRefByName(strEvent), 5, strValueCommand)
hs.AddAction(hs.GetEventRefByName(strEvent), 5, Chr(34) & "&hs.SetDeviceString(" & strDevice & ", " & Chr(34) & WeerType(lngValueCommand, blRainInText) & Chr(34) & ")")
hs.EnableEvent(strEvent)
Else If (Not InStr(strValue(i), "0 mm/uur") > 0) Then
hs.NewTimeEvent(strEvent, strTime(i), "", 1, 1, 1, 1, 1, 1, 1, strDevice & ":on", 1, "", "")
hs.AddAction(hs.GetEventRefByName(strEvent), 5, strValueCommand)
hs.AddAction(hs.GetEventRefByName(strEvent), 5, Chr(34) & "&hs.SetDeviceString(" & strDevice & ", " & Chr(34) & WeerType(lngValueCommand, blRainInText) & Chr(34) & ")")
hs.EnableEvent(strEvent)
End If
Else
If InStr(strValue(i), "0 mm/uur") > 0 Then
If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 3 Then hs.Transmit(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, "off")
hs.SetDeviceValue(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, 0)
hs.SetDeviceString(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i))
Else
If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 2 Then hs.Transmit(strDevice, "on")
hs.SetDeviceValue(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, lngValueCommand.toString())
hs.SetDeviceString(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i))
End If
End If
'hs.writelog("RegenMonitor", strDate(i) & " - " & strTime(i) & " - " & strValue(i))
Next
End If
End Sub
Function WeerType(Value As Integer, blRainInText As Boolean) As String
If blRainInText Then
Select Case Value
Case 0
Return "<img align='absmiddle' src='images/RegenMonitor/no_rain.png'> Geen regen"
Case 1 To 100
Return "<img align='absmiddle' src='images/RegenMonitor/light_rain.png'> Lichte regen"
Case 101 To 500
Return "<img align='absmiddle' src='images/RegenMonitor/medium_rain.png'> Matige regen"
Case 501 To 2500
Return "<img align='absmiddle' src='images/RegenMonitor/heavy_rain.png'> Zware regen"
Case Is > 2500
Return "<img align='absmiddle' src='images/RegenMonitor/heavy_rain.png'> Wolkbreuk"
End Select
Else
Dim strTmp As String
Select Case Value
Case 0
strTmp = "<img align='absmiddle' src='images/RegenMonitor/no_rain.png'>"
Case 1 To 100
strTmp = "<img align='absmiddle' src='images/RegenMonitor/light_rain.png'>"
Case 101 To 500
strTmp = "<img align='absmiddle' src='images/RegenMonitor/medium_rain.png'>"
Case 501 To 2500
strTmp = "<img align='absmiddle' src='images/RegenMonitor/heavy_rain.png'>"
Case Is > 2500
strTmp = "<img src='images/RegenMonitor/heavy_rain.png'>"
End Select
Return strTmp & " " & Math.Round(Value/100, 2).toString() & " mm/uur"
End If
End Function
Jouw submit was net eerder dan die van mijBastiaan wrote:Misschien wil je nog even het complete script met eventueel de veranderingen van Rien hier zetten?
Draaien we allemaal hetzelfde ipv van deeltjes copy pasten?
gr Bastiaan