Regen monitor script
Re: Regen monitor script
De devices worden niet aangemaakt met de string ingevuld. Dat gebeurd nadat de devices aangemaakt zijn (of overgeslagen als ze al bestaan).
Ik heb de code nogmaals aangepast. Stom stond "\" ipv "/" in de path. Wellicht dat dit het oplost.
Ik heb de code nogmaals aangepast. Stom stond "\" ipv "/" in de path. Wellicht dat dit het oplost.
Alexander
Re: Regen monitor script
Voor wie het ook zoekt: laatste regel blok. (2x)
Je moet dus ook de plaatjes in de folder "RegenMonitor"zetten terwijl de UNZIP een "RainCheck" folder geeft......
Daarna werkt het.
Bedankt allebei.
Bastiaan
Je moet dus ook de plaatjes in de folder "RegenMonitor"zetten terwijl de UNZIP een "RainCheck" folder geeft......
Daarna werkt het.
Bedankt allebei.
Bastiaan
Last edited by Bastiaan on Fri Jul 23, 2010 6:44 pm, edited 1 time in total.
Re: Regen monitor script
De regels in de functie WeertType onderaan het script. Staan \'s ipv /'s
Alexander
Re: Regen monitor script
Ik heb het script nu ook draaien, werkt tot nu toe prima, geen rare dingen tegengekomen. Nice work.
Nu nog een keer flink wat regen, hoewel ik toch niet hoop dat het vandaag zover komt.
Nu nog een keer flink wat regen, hoewel ik toch niet hoop dat het vandaag zover komt.

Re: Regen monitor script
Ik begrijp het zip verhaal niet, tenzij je met "RainCheck" de zip van Rien bedoelt, maar dan nog, die heeft een andere naam als map. Ik heb wel de zip file van Rien weggegooid uit zijn post om "problemen" te voorkomen.Bastiaan wrote:Voor wie het ook zoekt: laatste regel blok. (2x)
Je moet dus ook de plaatjes in de folder "RegenMonitor"zetten terwijl de UNZIP een "RainCheck" folder geeft......
Daarna werkt het.
Bedankt allebei.
Bastiaan
Die tot 1 mm/uur = lichte regen moet nog wat preciezer, want bij mij staat het nu als 0,01 mm/uur, maar de zon schijnt hier volop. Volgens het script zou het nu licht regenen, dus ergens moet ik een vanaf een hogere waarde zeggen dat het licht regent ipv > 0,00 mm/uur.Esteban wrote:Ik heb het script nu ook draaien, werkt tot nu toe prima, geen rare dingen tegengekomen. Nice work.
Nu nog een keer flink wat regen, hoewel ik toch niet hoop dat het vandaag zover komt.
Alexander
-
- Starting Member
- Posts: 31
- Joined: Thu May 27, 2010 10:07 am
Re: Regen monitor script
de laatste werkt helaas ook niet
enig idee?
24-7-2010 17:47:34 Info Event Trigger "Regencheck"
24-7-2010 17:47:34 Info Running script in background: regenmonitor.vb("Main","4057605;v1;yes;yes")
24-7-2010 17:47:35 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 117
enig idee?
24-7-2010 17:47:34 Info Event Trigger "Regencheck"
24-7-2010 17:47:34 Info Running script in background: regenmonitor.vb("Main","4057605;v1;yes;yes")
24-7-2010 17:47:35 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 117
Re: Regen monitor script
Het is dat we geen sterren systeem hebben anders had je nu al er een paar gehad 

__________________
Re: Regen monitor script
Ik kom het ooit nog wel een keer op een andere manier opeisendjdive wrote:Het is dat we geen sterren systeem hebben anders had je nu al er een paar gehad


Ik zal de parameters eens zelf proberen, want dit begrijp ik niet. Ik kom er snel op terug.ejdebruin1983 wrote:de laatste werkt helaas ook niet
enig idee?
24-7-2010 17:47:34 Info Event Trigger "Regencheck"
24-7-2010 17:47:34 Info Running script in background: regenmonitor.vb("Main","4057605;v1;yes;yes")
24-7-2010 17:47:35 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 117
Alexander
Re: Regen monitor script
Totaal geen probleem met jouw parameters. Ik heb wel van die "v1" een "h1" gemaakt, omdat ik al met de v reeks zit. Daarmee heb ik gelijk de volgende vraag: Je hebt toch geen v1 t/m v24 in gebruik he? En gebruik je ook de laatste versie van het script?
Alexander
Re: Regen monitor script
versie 2.3 is toch de laaste versie, of is er al weer een update,..
ik straks de laatste ook even proberen.
maar het blijft toch vreemd, het is mid zomer, en ik wacht op regen

ik straks de laatste ook even proberen.
maar het blijft toch vreemd, het is mid zomer, en ik wacht op regen

Re: Regen monitor script
Is het ook mogelijk om de "last change" tijd te laten updaten op de laatst geupdate waarde?
__________________
Re: Regen monitor script
2.3 is inderdaad de laatsteHarry wrote:versie 2.3 is toch de laaste versie, of is er al weer een update,..![]()
als de value anders is dan de vorige dan wordt de last update met de huidige tijd geupdate, anders niet. Of wil je dit juist wel?djdive wrote:Is het ook mogelijk om de "last change" tijd te laten updaten op de laatst geupdate waarde?
Alexander
Re: Regen monitor script
Ik ondersteun het verzoek om de last change to zetten op de laatste "check tijd" en niet op de laatst veranderde tijd.
Met de 'check tijd" heb je controle of het script ook gelopen heeft. Ik geen nuttig gebruik voor de tijd zoals die nu is.
Verder loopt het als een 'zonnetje' (wat momenteel letterlijk en figuurlijk is...)
Bastiaan
Met de 'check tijd" heb je controle of het script ook gelopen heeft. Ik geen nuttig gebruik voor de tijd zoals die nu is.
Verder loopt het als een 'zonnetje' (wat momenteel letterlijk en figuurlijk is...)
Bastiaan
Re: Regen monitor script
Ok. Ik kan mij nog een discussie, met ik dacht Digit, herinneren dat met die functie opgepast moet worden voor plugins die daar naar kijken.
Overigens werkt er nog iets niet, bij mij in ieder geval. Jullie niet in de log? (dan moet multi device wel aan staan)
Overigens werkt er nog iets niet, bij mij in ieder geval. Jullie niet in de log? (dan moet multi device wel aan staan)
Alexander
Re: Regen monitor script
en probleem gevonden. Update script naar 2.4 indien je multi-device optie gebruikt en/of Last Update geupdate hebben wilt ondanks of de device gewijzigd is of niet.
Code: Select all
' RegenMonitor.vb script
' Author: Alexander
' Version: 2.4
' Last Update: 25-07-2010 12:38
' 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
' 2.4: - Bugfix when multi-device selected. The on/off commands were transmitted only to the first device
' - When the string would be updated, the update time/date would only change when there really is an different string. Did set this to always update.
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", True)
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), True)
Else
If Not hs.DeviceStatus(strDevice) = 3 Then hs.Transmit(strDevice, "off")
hs.SetDeviceValue(strDevice, 0)
hs.SetDeviceString(strDevice, WeerType(lngValueCommand, blRainInText), True)
End If
Else
If blMultiDevice Then
If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 2 Then hs.Transmit(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, "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), True)
Else
If Not hs.DeviceStatus(strDevice) = 2 Then hs.Transmit(strDevice, "on")
hs.SetDeviceValue(strDevice, lngValueCommand.toString())
hs.SetDeviceString(strDevice, WeerType(lngValueCommand, blRainInText), True)
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) & "), True")
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) & ", True)")
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), True)
Else
If Not hs.DeviceStatus(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i) = 2 Then hs.Transmit(GetChar(strDevice,1) & Val(GetChar(strDevice,2))+i, "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), True)
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
Alexander