Om deze kans niet te missen heb ik het volgende script gemaakt. Aan het device heb ik een event hangen dat alleen trigger als de kans op poollicht > 75%, na zonsondergang en voor 23:30. Je zou hier nog weer informatie aan kunnen koppelen door te kijken of het helder is.
[UPDATE] Script updated to v1.4
Code: Select all
' AZ_Poollicht.vb
' Version : 1.4
' By A.A. van Zoelen
'
'Usage:
'
'AZ_Poollicht("Main","<DeviceCode>")
'Example : 'AZ_NS_storingen("Main","W37")
'
'
' Remark : Search text is not case sensitive
'
' History
' v1.4
' 06-12-2013
' Message layout on website had changed
'
' v1.3
' 18-10-2012
' Message layout on website had changed
'
' v1.2
' 26-04-2012
' Some tags where adjusted on the webside.
' Added debugging
'
' v1.1
' 09-03-2012
' Trapped when the site is under heavy load
' Few cosmetic adjustments related to above.
'
' v1.0
' 13-02-2012 : First release
'===================================================================
Imports System.Net
Imports System.IO
Public Sub Main(ByVal Params As Object)
'*********************************************
' These variable must be set first
'*********************************************
Dim Debug as boolean
Debug = false
'*********************************************
' The next few variables might be alter if needed
' Use these values to create new device(s)
' If you also use the traffic jam script then
' this is a good moment to name then the same.
Dim strDeviceRoom As String = "Poollicht - Monitoring"
Dim strDeviceType As String = "Poollicht Monitoring"
Dim strDeviceFloor As String = "Systeem"
Dim URL = "http://www.poollicht.be/nl"
'************************************************
'************************************************
'Below this there is no real need for altering anything
'********************************
'Get the device code
'********************************
Dim strDevice As String = hs.StringItem(Params, 1, ";")
Dim strHouseCode As String = GetChar(strDevice,1)
Dim strDeviceCode As String = strDevice.subString(1)
If Debug = true then hs.WriteLog("<b>AZ_Poollicht_Info</b>", "1")
'********************************
'First do some checks
'Is the device and house code oke
'********************************
If not ((Val(strDeviceCode)>=1) And (Val(strDeviceCode)<=128)) Then
hs.WriteLog("<b>AZ_Poollicht_Info</b>", "<b>Ongeldige DeviceCode!</b>")
Exit Sub
End If
If Debug = true then hs.WriteLog("<b>AZ_Poollicht_Info</b>", "2")
If not (strHouseCode <> "") Then
hs.WriteLog("<b>AZ_NS_Poollicht</b>", "<b>Ongeldige HouseCode!</b>")
Exit Sub
End If
If Debug = true then hs.WriteLog("<b>AZ_Poollicht_Info</b>", "3")
'********************************
'Is the device available?
'********************************
If hs.DeviceExistsRef(strHouseCode & strDeviceCode) = -1 Then
Dim dv As Object
dv = hs.GetDeviceByRef(hs.NewDeviceRef("Poollicht"))
dv.hc = strHouseCode
dv.dc = strDeviceCode
dv.misc = "&h10"
dv.location = strDeviceRoom
dv.location2 = strDeviceFloor
dv.dev_type_string = strDeviceType
End If
If Debug = true then hs.WriteLog("<b>AZ_Poollicht_Info</b>", "4")
'**********************************
' We are ready to get the html page
'**********************************
Dim strWebPage As String
Try
strWebPage = getHtml(URL)
Catch ex As Exception
hs.setdevicestring(strDevice, URL + " onbereikbaar")
hs.setdevicevalue(strDevice, 0)
hs.setdevicelastchange(strDevice, now)
hs.writelog("<b>AZ_Poollicht</b>","<b>Connection to site failed due:" & ex.Message & "</b>")
Exit Sub
End Try
If Debug = true then hs.WriteLog("<b>AZ_Poollicht_Info</b>", "5")
'**********************************
' Controlleer of de pagina
' beschikbaar is.
'**********************************
if Len(strWebPage) < 100 then
hs.writelog("<b>AZ_Poollicht</b>","<b>" + URL + " onbereikbaar</b>")
hs.setdevicestring(strDevice, URL + "onbereikbaar")
hs.setdevicevalue(strDevice, 0)
hs.setdevicelastchange(strDevice, now)
Exit Sub
End If
If Debug = true then hs.WriteLog("<b>AZ_Poollicht_Info</b>", "6")
'**********************************
' Next we need to grab all the
' the info from the collected data
'**********************************
Dim intStart As Integer
Dim intEnd As Integer
Dim intValue As Integer
Dim strTemp As String
Dim strDetails As String
' Haal een stuk header tekst eraf omdat
' deze storende tekst bevat.
intStart = Instr(strWebPage, "alertbalk waarschuwing")
strWebPage = Right(strWebPage, Len(strWebPage) - intStart)
' Ga naar de live waardes voor de gemiddelde breedtgraad
' deze storende tekst bevat.
intStart = Instr(strWebPage, "Gemiddelde breedtegraad")
strWebPage = Right(strWebPage, Len(strWebPage) - intStart)
If Debug = true then hs.WriteLog("<b>AZ_Poollicht_Info</b>", "7")
' Vind de 'badge badge-success' class
intStart = Instr(strWebPage, "badge badge-success") + Len("badge badge-success")
'Verwijder ook het > teken
intStart = intStart + 1
' Remove everything till this sign
strWebPage = Right(strWebPage, Len(strWebPage) - intStart)
If Debug = true then hs.WriteLog("<b>AZ_Poollicht_Info</b>", "8")
' Next find the end of the class
intEnd = Instr(strWebPage, "</span") - 1
strTemp = Left(strWebPage, intEnd)
If Debug = true then hs.WriteLog("<b>AZ_Poollicht_Info</b>", strTemp)
strDetails = strTemp
strTemp = Trim(Replace(strTemp, "%", ""))
If Debug = true then hs.WriteLog("<b>AZ_Poollicht_Info</b>", "9")
If Debug = true then hs.WriteLog("<b>AZ_Poollicht_Info</b>", strTemp)
'Show the info
hs.setdevicestring(strDevice, strDetails)
hs.setdevicevalue(strDevice, Val(strTemp))
hs.setdevicelastchange(strDevice, now)
End Sub
'********************************
'********************************
' Additional functions and such
'********************************
'********************************
' Get the HTML code of the requested web site
Function getHtml(ByVal url As String) As String
Dim myWebRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)
myWebRequest.Method = "GET"
' make request for web page
Dim myWebResponse As HttpWebResponse = DirectCast(myWebRequest.GetResponse(), HttpWebResponse)
Dim myWebSource As New StreamReader(myWebResponse.GetResponseStream())
Dim myPageSource As String = String.Empty
myPageSource = myWebSource.ReadToEnd()
myWebResponse.Close()
return myPageSource
End Function