Page 10 of 13

Re: Regen monitor script

Posted: Sun Nov 07, 2010 10:24 pm
by Alexander
Mooi! Zonde van de tijd als er niets mee gedaan wordt. tnxs

Re: Regen monitor script

Posted: Mon Nov 08, 2010 5:16 pm
by phoenixb
Hier wordt hij ook nog gebruikt als trigger met in combinatie met een rv voeler in en buiten huis om de mechanische ventilatie te schakelen.

Re: Regen monitor script

Posted: Fri Nov 12, 2010 12:20 am
by RdP
Alexander wrote:Iemand nog in gebruik? Just curious.
Zeker weten !!!!

Re: Regen monitor script

Posted: Fri Nov 12, 2010 8:55 am
by Esteban
Hier ook nog steeds in gebruik, blijft handig. Thx

Re: Regen monitor script

Posted: Fri Dec 03, 2010 5:40 pm
by MBijker
Hallo allen,

Allereerst bedankt voor dit script.

Ik heb echter een probleempje met dit script.
Wanneer ik het uitvoer krijg ik de volgende foutmelding in homeseer:

12/4/2010 11:00:00 PM - 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 119

Iemand enig idee wat ik fout doe?
Ik voer het script als volgt uit: regenmonitor.vb("Main","4058290;V1;no;yes")


Alvast bedankt.

Gr,

Mark

Re: Regen monitor script

Posted: Mon Dec 06, 2010 1:13 pm
by MBijker
Niemand een idee?

Re: Regen monitor script

Posted: Mon Dec 06, 2010 4:54 pm
by AshaiRey
Heb je d laatste versie in gebruik?
http://www.domoticaforum.eu/viewtopic.p ... =75#p41041

Het enige verschil dat ik zie is dat ik 2x yes heb staan. Voor de rest is de aanroep gelijk.

Re: Regen monitor script

Posted: Mon Dec 06, 2010 5:38 pm
by MBijker
Gebruik inderdaad de laatste versie.
2x yes heb ik ook al geprobeerd help helaas ook niet.

Re: Regen monitor script

Posted: Mon Dec 06, 2010 6:38 pm
by AshaiRey
Je gebruik toch een ander script want als je naar de melding kijkt.
12/4/2010 11:00:00 PM - 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 119
fout met data2 in de bunctie transmit op regel 119

Data twee moet een integer zijn en trouwens alle parameters zijn vreemd. Buiten dat de functie transmit komt niet voor in het regenscript.

Re: Regen monitor script

Posted: Mon Dec 06, 2010 9:31 pm
by MBijker
Erg vreemd aangezien ik gewoon het script op pagina 6 gekopieerd en geplakt heb.
Ik krijg de volgende meldingen:

Code: Select all

12/7/2010 7:54:35 PM  - Info - Running script in background: regenmonitor.vb("Main","4058290;V1;yes;yes")

Code: Select all

12/7/2010 7:54:35 PM  - 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 97

Code: Select all

12/7/2010 7:54:35 PM  - SCR - Option Strict Offimports Schedulerimports SystemPublic Module scriptcode50#Region "Automatically generated code, do not modify"'Automatically generated code, do not modify'Event Sources Begin	<System.ContextStaticAttribute()> Public WithEvents hs As Scheduler.hsapplication	<System.ContextStaticAttribute()> Public WithEvents hsp As scheduler.hsp	<System.ContextStaticAttribute()> Public WithEvents hssystem As scheduler.phone0'Event Sources End'End of automatically generated code#End RegionSub 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 IfEnd SubFunction 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 IfEnd FunctionEnd Module
En dit is het script zelf:

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
Kan het misschien zijn dat ik een aanvulend software pakket ofzo nodig heb wat ik mis?
Iets anders kan ik namelijk zelf niet bedenken.

Alvast bedankt voor eventuele moeite.


Gr,
Mark

Re: Regen monitor script

Posted: Mon Dec 06, 2010 9:46 pm
by esschenk
Hallo,

Misschien heeft het iets te maken met het knippen en plakken .
Ik heb hier ook wat slechte ervaringen mee.
Je kunt het bestand ook downloaden van mijn systeem.
Inloggen met guest guest
Deze draait al maanden op mijn systeem zonder 1 enkel probleem

http://esschenk.dyndns.org/mydownloads.aspx


Ed

Re: Regen monitor script

Posted: Mon Dec 06, 2010 9:55 pm
by Alexander
@Bram: hs.Transmit komt wel voor.
@Mark: Doe eens regenmonitor.vb("Main","4058290;V1"). Overigens is 2.4 niet de laatste, maar 2.51 en ik zie dat ik deze nog niet gepost heb, dus bij deze:

Code: Select all

' RegenMonitor.vb script
' Auteur: Alexander
' Versie: 2.51
' Laatst gewijzigd: 26-07-2010 19:30

' Change Log:
' 1.0: Start
' 1.11:  - Functionaliteit: Script stopt zodra de webpagina een niet verwachte tekst terug geeft. Zodra dat gebeurd zal het device een status "unknown" krijgen.
'        - Functionaliteit: Als de webpagina zijn regenverwachting bijstelt, zal het event dat al aangemaakt is van de bijgestelde tijd worden voorzien.
'        - Functionaliteit: Als de regenverwachting in de webpagina eerder is dan de huidige tijd, wordt het device direct geschakeld en het eerder aangemaakte event verwijderd.
'        - Functionaliteit: Twee parameters moeten worden toegevoegd. De eerste is de gevraagde locatie voor weersverwachting en de tweede het device dat geschakeld moet worden.
'        - Bugfix: Als er regen was verwacht werd dit niet goed afgehandeld.
' 2.0:   - Functionaliteit: Andere url wordt nu gebruikt voor de weersverwachting.
' 2.1:   - Functionaliteit: De Status string van het device wordt nu ingevuld.
' 2.2:   - Functionaliteit: Multi Device wordt nu ondersteunt: Er worden 24 devices aangemaakt met een weersverwachting intervalverschil van 5 minuten.
' 2.31:  - Functionaliteit: Images van Rien worden niet in de Status String toegevoegd
'        - Functionaliteit: Device Location en Device Type worden nu ingevuld bij het aanmaken van device(s), bij afwezigheid, door het script
'        - Bugfix: Dubbele quotes waren niet meegenomen in het uitvoeren van de HS commando om de Device String bij te werken
' 2.41:  - Functionaliteit: De Last Update van het device wordt nu altijd bijgewerkt ongeacht de waarde van het device
'        - Bugfix: Bij gebruik van Multi Device werd alleen het eerste Device geupdate met het ON/OFF commando
' 2.51:  - Bugfix: Bij de parameter voor het device werd de derde karakter, indien aanwezig, genegeerd.
'        - Comment: Kommentaar toegevoegd en change log vertaalt naar het Nederlands.
'        - Functionaliteit: Extra checks toegevoegd

Sub Main(ByVal Params As String)
    ' Vervang deze waarden als je andere omschrijvingen wilt hebben, zodra de device(s) wordt/worden aangemaakt.
    Dim strDeviceLocation As String = "Virtual - Monitoring" ' Sla deze waarde op in de variabele strDeviceLocation
    Dim strDeviceType As String = "Verwachte Regen Monitoring" ' Sla deze waarde op in de variabele strDeviceType

    Dim strGeoAreaId As String = hs.StringItem(Params, 1, ";") ' Haal de waarde van de eerste parameter op en sla deze op
    Dim strDevice As String = hs.StringItem(Params, 2, ";") ' Haal de waarde van de tweede parameter op en sla deze op
    Dim strHouseCode As String = GetChar(strDevice,1) ' Pak de eerste karakter van de variabele strDevice en sla deze op
    dim strDeviceCode As String = strDevice.subString(1) ' Pak de tekst op vanaf de tweede positie van de variabele strDevice en sla deze op
    Dim blRainInText As Boolean = hs.StringItem(Params, 3, ";") = "yes" ' Haal de waarde van de derde parameter op en als deze "yes" als waarde heeft, dan is de variabele blRainInText WAAR anders ONWAAR
    Dim blMultiDevice As Boolean = hs.StringItem(Params, 4, ";") = "yes" ' Haal de waarde van de vierde parameter op en als deze "yes" als waarde heeft, dan is de variabele blMultiDevice WAAR anders ONWAAR
    Dim strData As String = hs.GetURL("www.weeronline.nl", "/Go/FlashCharts/RainImmediate?geoAreaId=" & strGeoAreaId, false, 80) ' Haal de tekst van de webpagina op en deze in de variabele strData opslaan
    Dim i As Integer

    If not ((Val(strDeviceCode)>=1) And (Val(strDeviceCode)<=128)) Then
        hs.WriteLog("RegenMonitor", "Ongeldige DeviceCode! Uitvoeren script gestopt...")
        Exit Sub
    End If

    If not (strHouseCode <> "") Then
        hs.WriteLog("RegenMonitor", "Ongeldige HouseCode! Uitvoeren script gestopt...")
        Exit Sub
    End If

    If (Not InStr(strData, "?xml") > 0) Then
        hs.SetDeviceString(strDevice, "Website weeronline.nl down", True)
        hs.SetDeviceStatus(strDevice, 17)
        Exit Sub
    End If

    If blMultiDevice Then
        For i = 0 To 23
           If hs.DeviceExistsRef(strHouseCode & Val(strDeviceCode)+i) = -1 Then
              Dim dv As Object
              dv = hs.GetDeviceByRef(hs.NewDeviceRef("Regen" & "-" & i+1))
              dv.hc = strHouseCode
              dv.dc = Val(strDeviceCode)+i
              dv.misc = "&h10"
              dv.location = strDeviceLocation
              dv.dev_type_string = strDeviceType
           End If
        Next
    Else
        If hs.DeviceExistsRef(strHouseCode & strDeviceCode) = -1 Then
           Dim dv As Object
           dv = hs.GetDeviceByRef(hs.NewDeviceRef("Regen"))
           dv.hc = strHouseCode
           dv.dc = strDeviceCode
           dv.misc = "&h10"
           dv.location = strDeviceLocation
           dv.dev_type_string = strDeviceType
        End If
    End If

    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)
        ElseIf 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(" & strHouseCode & Val(strDeviceCode) + 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(strHouseCode & Val(strDeviceCode) + i) = 3 Then
                        hs.Transmit(strHouseCode & Val(strDeviceCode) + i, "off")
                        hs.SetDeviceValue(strHouseCode & Val(strDeviceCode) + i, 0)
                        hs.writelog("RegenMonitor", "1-" & i.toString() & " - " & strTime(i) & " - device: " & strHouseCode & Val(strDeviceCode) + i & " - value: 0")
                    End If
                    hs.SetDeviceString(strHouseCode & Val(strDeviceCode) + i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i), True)
                Else
                    If Not hs.DeviceStatus(strDevice) = 3 Then 
                        hs.Transmit(strDevice, "off")
                        hs.SetDeviceValue(strDevice, 0)
                    End If
                    hs.SetDeviceString(strDevice, WeerType(lngValueCommand, blRainInText), True)
                    hs.writelog("RegenMonitor", "2-" & i.toString() & " - " & strTime(i) & "- device: " & strDevice & " - value: 0")
                End If
            Else
                If blMultiDevice Then
                    If Not hs.DeviceStatus(strHouseCode & Val(strDeviceCode) + i) = 2 Then hs.Transmit(strHouseCode & Val(strDeviceCode) + i, "on")
                    hs.SetDeviceValue(strHouseCode & Val(strDeviceCode) + i, lngValueCommand.toString())
                    hs.SetDeviceString(strHouseCode & Val(strDeviceCode) + i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i), True)
                    hs.writelog("RegenMonitor", "3-" & i.toString() & " - " & strTime(i) & "- device: " & strHouseCode & Val(strDeviceCode) + i & " - value: " & lngValueCommand.toString())
                Else
                    If Not hs.DeviceStatus(strDevice) = 2 Then hs.Transmit(strDevice, "on")
                    hs.SetDeviceValue(strDevice, lngValueCommand.toString())
                    hs.SetDeviceString(strDevice, WeerType(lngValueCommand, blRainInText), True)
                    hs.writelog("RegenMonitor", "4-" & i.toString() & " - " & strTime(i) & "- device: " & strDevice & " - value: " & lngValueCommand.toString())
                End If
            End If
        ElseIf Not blMultiDevice Then
            If (InStr(strValue(i), "0 mm/uur") > 0) and (i>0) Then
                If Not (InStr(strValue(i - 1), "0 mm/uur") > 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)
                End If
            ElseIf (InStr(strValue(i), "0 mm/uur") > 0) and (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
                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(strHouseCode & Val(strDeviceCode) + i) = 3 Then
                    hs.Transmit(strHouseCode & Val(strDeviceCode) + i, "off")
                    hs.SetDeviceValue(strHouseCode & Val(strDeviceCode) + i, 0)
                End If
                hs.SetDeviceString(strHouseCode & Val(strDeviceCode) + i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i), True)
                hs.writelog("RegenMonitor", "5-" & i.toString() & " - " & strTime(i) & "- device: " & strHouseCode & Val(strDeviceCode) + i & " - value: 0")
            Else
                If Not hs.DeviceStatus(strHouseCode & Val(strDeviceCode) + i) = 2 Then hs.Transmit(strHouseCode & Val(strDeviceCode) + i, "on")
                hs.SetDeviceValue(strHouseCode & Val(strDeviceCode) + i, lngValueCommand.toString())
                hs.SetDeviceString(strHouseCode & Val(strDeviceCode) + i, WeerType(lngValueCommand, blRainInText) & " om " & strTime(i), True)
                hs.writelog("RegenMonitor", "6-" & i.toString() & " - " & strTime(i) & "- device: " & strHouseCode & Val(strDeviceCode) + i & " - value: " & lngValueCommand.toString())
            End If
        End If
        'hs.writelog("RegenMonitor", strDate(i) & " - " & strTime(i) & " - " & strValue(i))
    Next
End Sub

Function WeerType(Value As Integer, blRainInText As Boolean) As String
    If blRainInText Then
       Select Case Value 
           Case 0 To 1
               Return "<img align='absmiddle' src='images/RegenMonitor/no_rain.png'> Geen regen"
           Case 2 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 To 1
               strTmp = "<img align='absmiddle' src='images/RegenMonitor/no_rain.png'>"
           Case 2 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
Voor iedereen dus.. Hoe heeft het sneeuw eigenlijk gedaan. Ik heb niet gemonitord of dit weergegeven werd.

Re: Regen monitor script

Posted: Mon Dec 06, 2010 10:07 pm
by Akatar
sneeuw werd als regen weergegeven

Re: Regen monitor script

Posted: Mon Dec 06, 2010 10:15 pm
by Alexander
Ja als afbeelding bedoel je denk ik. Volgens mij doet weeronline ook symbolen van sneeuw... Dat wordt even actief monitoren zodra het zover is. Maken we er maar weersvoorspelling of neerslag monitor van ofzo ;-)

Re: Regen monitor script

Posted: Mon Dec 06, 2010 10:18 pm
by AshaiRey
@Alexander
Aha, ik zie hem nu.
Ik zocht op 'Function Transmit' vandaar' :(