PV Logger (solar power)

Forum over Homeseer scripts (DUTCH forum)

Moderators: TANE, Ruud

Post Reply
AshaiRey
Senior Member
Senior Member
Posts: 1310
Joined: Mon Feb 02, 2009 5:27 pm
Location: Netherlands
Contact:

PV Logger (solar power)

Post by AshaiRey »

Hi,
I am using the PV Logger board (fp4all.com/index.php?main_page=product_ ... cts_id=188) in my Chint 2.8 converter. It's a very good product, plug and play, made in Holland and reasonable priced. However HomeSeer can't read the data directly. Atleast not yet because support is very actief for this product and they are listening very well to their customers.

Anyway, i made this script to import data from the logger into HomeSeer. It's a quick and dirty script so not much optimisation. On the other side there isn't that much happening inside the script anyway.

This script wil create 5 devices for you starting at the devicecode given at the commandline. This data was what i was interested in. If you look at the script then you will see it's easy to understand and commented to add other data or to remove mine.

Please note:
I have installed the PowerTrigger plugin (Free via the update tool in HomeSeer). This plug in have also the ability to write data to a CSV file for logging. I use this to log the data for power en temp for later processing if needed.

Latest version

Code: Select all

' AZ_PVLogger.vb
' Version : 1.1
' By A.A. van Zoelen
'
'Usage:
'
'AZ_PVLogger("Main","<DeviceCode>")
'Example : 'AZ_PVLogger("Main","W37")
'
'
' Remark : Four extra devices are created (w37 to W41)
'          Order of devices are:
'          Power
'          Temp
'          Total today
'          Lifetime energy
'          Lifetime savings

' History
' v1.1 - 28-05-2012
' - Changed how the device values are written to get
'   also the decimals
' - Value of power will now be set to the device correctly
'
' v1.0
' 25-05-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 = "Monitoring" 
  Dim strDeviceType As String = "PV Logger Monitoring"
  Dim strDeviceFloor As String = "Systeem"
  Dim URL   = "http://pvlogger/status.htm"
  Dim URL2  = "http://pvlogger/index.htm"
  Dim LogID = "PVLogger"


'************************************************
'************************************************
'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>" + LogID + "</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>" + LogID + "</b>", "<b>Ongeldige DeviceCode!</b>")
           Exit Sub
   End If

   If Debug = true then hs.WriteLog("<b>" + LogID + "</b>", "2")

   If not (strHouseCode <> "") Then
           hs.WriteLog("<b>" + LogID + "</b>", "<b>Ongeldige HouseCode!</b>")
           Exit Sub
   End If
   If Debug = true then hs.WriteLog("<b>" + LogID + "</b>", "3")

   '********************************
   'Are the devices available?
   '********************************
   If hs.DeviceExistsRef(strHouseCode & strDeviceCode) = -1 Then
      Dim dv As Object
      dv = hs.GetDeviceByRef(hs.NewDeviceRef("PV Opbrengst"))
      dv.hc = strHouseCode
      dv.dc = strDeviceCode
      dv.misc = "&h10"
      dv.location = strDeviceRoom
      dv.location2 = strDeviceFloor
      dv.dev_type_string = strDeviceType
   End If

   If hs.DeviceExistsRef(strHouseCode & val(strDeviceCode) + 1) = -1 Then
      Dim dv As Object
      dv = hs.GetDeviceByRef(hs.NewDeviceRef("PV Temp"))
      dv.hc = strHouseCode
      dv.dc = val(strDeviceCode) + 1
      dv.misc = "&h10"
      dv.location = strDeviceRoom
      dv.location2 = strDeviceFloor
      dv.dev_type_string = strDeviceType
   End If

   If hs.DeviceExistsRef(strHouseCode & val(strDeviceCode) + 2) = -1 Then
      Dim dv As Object
      dv = hs.GetDeviceByRef(hs.NewDeviceRef("PV Vandaag"))
      dv.hc = strHouseCode
      dv.dc = val(strDeviceCode) + 2
      dv.misc = "&h10"
      dv.location = strDeviceRoom
      dv.location2 = strDeviceFloor
      dv.dev_type_string = strDeviceType
   End If

   If hs.DeviceExistsRef(strHouseCode & val(strDeviceCode) + 3) = -1 Then
      Dim dv As Object
      dv = hs.GetDeviceByRef(hs.NewDeviceRef("PV Totaal"))
      dv.hc = strHouseCode
      dv.dc = val(strDeviceCode) + 3
      dv.misc = "&h10"
      dv.location = strDeviceRoom
      dv.location2 = strDeviceFloor
      dv.dev_type_string = strDeviceType
   End If

   If hs.DeviceExistsRef(strHouseCode & val(strDeviceCode) + 4) = -1 Then
      Dim dv As Object
      dv = hs.GetDeviceByRef(hs.NewDeviceRef("PV Besparing"))
      dv.hc = strHouseCode
      dv.dc = val(strDeviceCode) + 4
      dv.misc = "&h10"
      dv.location = strDeviceRoom
      dv.location2 = strDeviceFloor
      dv.dev_type_string = strDeviceType
   End If

   If Debug = true then hs.WriteLog("<b>" + LogID + "</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>" + LogID + "</b>","<b>Connection to site failed due:" & ex.Message & "</b>")
     Exit Sub
   End Try


   '**********************************
   ' Controlleer of de pagina 
   ' beschikbaar is.
   '**********************************
   if Len(strWebPage) < 10 then
     hs.writelog("<b>" + LogID + "</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>" + LogID + "</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 strDetail As String

   'Show the info

   'Vermogen
   strDetail = GetValue(strWebPage, "PAC</td><td class=bCtr>", Debug)
   hs.setdevicestring(strDevice, strDetail )
   hs.setdevicevalue(strDevice, val(left(strDetail, instr(strDetail, " "))))
   hs.setdevicelastchange(strDevice, now)
   If Debug = true then hs.WriteLog("<b>" + LogID + "</b>", strDetail)

   'Temperatuur
   strDetail = GetValue(strWebPage, "TEMP</td><td class=bCtr>", Debug)
   hs.setdevicestring((strHouseCode & val(strDeviceCode) + 1), strDetail)
   hs.setdevicevalue((strHouseCode & val(strDeviceCode) + 1), val(left(strDetail, instr(strDetail, " "))) * 10)
   hs.setdevicelastchange((strHouseCode & val(strDeviceCode) + 1), now)
   If Debug = true then hs.WriteLog("<b>" + LogID + "</b>", strDetail)

   'The following informatie comes
   'from a different page
   strWebPage = getHtml(URL2)

   'Vandaag opbrengst
   strDetail = GetValue(strWebPage, "Todays generated energy</td><td><big>", Debug)
   hs.setdevicestring((strHouseCode & val(strDeviceCode) + 2), strDetail)
   hs.setdevicevalue((strHouseCode & val(strDeviceCode) + 2), val(left(strDetail, instr(strDetail, " "))) * 1000)
   hs.setdevicelastchange((strHouseCode & val(strDeviceCode) + 2), now)
   If Debug = true then hs.WriteLog("<b>" + LogID + "</b>", strDetail)

   'Totaal dag opbrengst
   strDetail = GetValue(strWebPage, "Lifetime generated energy</td><td><big>", Debug)
   hs.setdevicestring((strHouseCode & val(strDeviceCode) + 3), strDetail)
   hs.setdevicevalue((strHouseCode & val(strDeviceCode) + 3), val(left(strDetail, instr(strDetail, " "))))
   hs.setdevicelastchange((strHouseCode & val(strDeviceCode) + 3), now)
   If Debug = true then hs.WriteLog("<b>" + LogID + "</b>", strDetail)

   'Totaal besparing
   strDetail = GetValue(strWebPage, "Lifetime Earnings estimation</td><td><big>", Debug)
   hs.setdevicestring((strHouseCode & val(strDeviceCode) + 4), strDetail)
   hs.setdevicevalue((strHouseCode & val(strDeviceCode) + 4), val(left(strDetail, instr(strDetail, " "))))
   hs.setdevicelastchange((strHouseCode & val(strDeviceCode) + 4), now)
   If Debug = true then hs.WriteLog("<b>" + LogID + "</b>", strDetail)

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


Function GetValue(strWebPage, strValue, Debug) as String
   Dim strResult
   Dim strTemp as String
   Dim intStart As Integer
   Dim intEnd As Integer

   intStart = Instr(strWebPage, strValue) + Len(strValue) - 1
   strTemp = Right(strWebPage, Len(strWebPage) - intStart)
   intEnd = Instr(strTemp, "</") + 1
   strResult = Left(strTemp, intEnd)
   If Debug = True then hs.WriteLog("<b>PV Logger</b>", "strDetail=" + strResult)

   Return strResult
End Function
Here some info about the used event
2.gif
2.gif (12.04 KiB) Viewed 6292 times
3.gif
3.gif (9.58 KiB) Viewed 6292 times
Last edited by AshaiRey on Mon May 28, 2012 9:38 am, edited 1 time in total.
Bram
Wim2008
Advanced Member
Advanced Member
Posts: 718
Joined: Wed Aug 12, 2009 1:42 pm
Location: Eindhoven, Netherlands

Re: PV Logger (solar power)

Post by Wim2008 »

Look good the script. I will give it a try.

B.R. Wim :)
AshaiRey
Senior Member
Senior Member
Posts: 1310
Joined: Mon Feb 02, 2009 5:27 pm
Location: Netherlands
Contact:

Re: PV Logger (solar power)

Post by AshaiRey »

Updated to version 1.1 (see first post)

v1.1 - 28-05-2012
- Changed how the device values are written to get also the decimals
- Value of power will now be set to the device correctly
Bram
Post Reply

Return to “Homeseer Scripts Forum”