Hi all,
I want to scrape values from an HTML table on the webpages of my three Kostal PIKO inverters into individual HA sensors. I am successful with the Scrape Sensor integration and individual sensors per value e.g. the configuration for two examples looks like this:
- platform: scrape
name: Kostal PIKO 3.6 - Leistung aktuell
resource: http://192.168.12.102
username: <*username*>
password: <*password*>
select: td
index: 14
value_template: "{{ 0 | float if value.strip() == 'x x x ' else value | float }}"
unit_of_measurement: W
- platform: scrape
name: Kostal PIKO 3.6 - Gesamtenergie
resource: http://192.168.12.102
username: <*username*>
password: <*password*>
select: td
index: 17
value_template: '{{ value | float }}'
unit_of_measurement: kWh
However, this is not ideal, since it requires one HTTP request including a userid/password login per sensor value update and since I have three inverters and multiple sensor values per inverter it would be quite a few requests and quite a few logins. Therefore the better approach would be the RESTful sensor integration where I can download the entire page with all values per inverter with just one HTTP request and then parse the HTML data into individual sensor values. Unfortunately I have no experience with the RESTful integration and since I could not find an equivalent to the select: td
and index: 14
or index: 17
command I use in the Scrape sensor in the RESTful integration to access - in this case - the data of the 14th of 17th table cell of the HTML table. I am wondering if someone has experience with this and could help me map this to something like this and fill in the ???:
- authentication: basic
resource: http://192.168.12.102
method: GET
username: <*username*>
password: <*password*>
scan_interval: 60
sensor:
- name: Kostal PIKO 3.6 - Leistung aktuell
???
- name: Kostal PIKO 3.6 - Gesamtenergie
???
I copied the HTML code below, in case that helps, the two example cells that the Scrape Sensor integration would scrape with select: td and index: 14 and index: 17 are the ones with the values 1234 and 123456. Obviously once I figured those two out, I can do all the remaining sensors on this page and then also for the other inverters.
Thanks a bunch!
<!DOCtype HTML PUBLIC "-//W3C//Dtd HTML 4.0 Transitional//EN">
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<meta name="Generator" CONTENT="ChrisB">
<title>PV Webserver</title>
</head>
<body nof="(MB=(DefaultMasterborder, 65, 60, 150, 10), L=(HomeLayout, 700, 600))" bgcolor="#EAF7F7" text="#000000" link="#0033CC" vlink="#990099" alink="#FF0000" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
<form method="post" action="">
<table cellspacing="0" cellpadding="0" width="770" nof="ly">
<tr><td height="5"></td></tr>
<tr><td width="190" height="55"></td>
<td width="400">
<font face="Arial,Helvetica,Geneva,Sans-serif,sans-serif" size="+3">
Kostal PIKO 3.6
</font>
</td>
<td><img alt="Logo" height="42" width="130" src="KSE.gif"></td>
</tr>
</table>
<font face="Arial,Helvetica,Geneva,Sans-serif,sans-serif">
<table Border="0" width="100%"><tr>
<td width="150"></td>
<td> <hr> </td>
</tr></table>
<table cellspacing="0" cellpadding="0" width="770">
<tr><td></td></tr>
<tr>
<td width="190"></td>
<td colspan="2">
<b>AC-Leistung</b></td>
<td> </td>
<td>
<b>Energie</b></td></tr>
<tr><td height="10"></td></tr>
<tr>
<td width="190"></td>
<td width="100">
aktuell</td>
<td width="70" align="right" bgcolor="#FFFFFF">
1234
</td>
<td width="140">  W</td>
<td width="100">
Gesamtenergie</td>
<td width="70" align="right" bgcolor="#FFFFFF">
123456
</td>
<td width="50">  kWh</td>
<td> </td></tr>
<tr height="2"><td></td></tr>
<tr>
<td width="190"></td>
<td width="100">
 </td>
<td width="70" align="right">
 </td>
<td width="140"> </td>
<td width="100">
Tagesenergie</td>
<td width="70" align="right" bgcolor="#FFFFFF">
0.92</td>
<td width="50">  kWh</td>
<td> </td></tr>
<tr height="5"><td></td></tr>
<tr>
<td width="190"></td>
<td width="100">
Status</td>
<td colspan="4">
Einspeisen MPP</td>
<td> </td></tr>
<tr height="8"><td></td></tr>
<tr><td colspan="7">
<table align="top" width="100%"><tr>
<td width="182"></td>
<td><hr size="1"></font></td></tr>
<tr><td height="5"></td></tr></table>
</td></tr>
<tr>
<td width="190"></td>
<td colspan="2">
<b>PV-Generator</b></td>
<td width="140"> </td>
<td colspan="2">
<b>Ausgangsleistung</b></td>
<td width="30"> </td>
<td> </td></tr>
<tr><td height="10"></td></tr>
<tr>
<td width="190"></td>
<td width="100">
<u>String 1</u></td>
<td width="70"> </td>
<td width="140"> </td>
<td width="95">
<u>L1</u></td>
<td width="70"> </td>
<td width="30"> </td>
<td> </td></tr>
<tr>
<td width="190"></td>
<td width="100">
Spannung</td>
<td width="70" align="right" bgcolor="#FFFFFF">
419</td>
<td width="140">  V</td>
<td width="100">
Spannung</td>
<td width="70" align="right" bgcolor="#FFFFFF">
228</td>
<td width="30">  V</td>
<td> </td></tr>
<tr height="2"><td></td></tr>
<tr valign="top" align="left">
<td width="190"> </td>
<td width="100">
Strom</td>
<td width="70" align="right" bgcolor="#FFFFFF">
1.23</td>
<td width="140">  A</td>
<td width="100">
Leistung</td>
<td width="70" align="right" bgcolor="#FFFFFF">
456</td>
<td width="30">  W</td>
<td> </td></tr>
<tr height="22"><td></td></tr>
<tr>
<td width="190"></td>
<td width="100">
<u>String 2</u></td>
<td width="70"> </td>
<td width="140"> </td>
<td width="100">
<u> </u></td>
<td width="70"> </td>
<td width="30"> </td>
<td> </td></tr>
<tr>
<td width="190"></td>
<td width="100">
Spannung</td>
<td width="70" align="right" bgcolor="#FFFFFF">
419</td>
<td width="140">  V</td>
<td width="100">
</td>
<td width="70" align="right" bgcolor="#EAF7F7">
</td>
<td width="30">  </td>
<td> </td></tr>
<tr height="2"><td></td></tr>
<tr valign="top" align="left">
<td width="190"> </td>
<td width="100">
Strom</td>
<td width="70" align="right" bgcolor="#FFFFFF">
0.01</td>
<td width="140">  A</td>
<td width="100">
</td>
<td width="70" align="right" bgcolor="#EAF7F7">
</td>
<td width="30">  </td>
<td> </td></tr>
<tr height="22"><td></td></tr>
<tr>
<td width="190"></td>
<td width="100">
<u> </u></td>
<td width="70"> </td>
<td width="140"> </td>
<td width="100">
<u> </u></td>
<td width="70"> </td>
<td width="30"> </td>
<td> </td></tr>
<tr>
<td width="190"></td>
<td width="100">
</td>
<td width="70" align="right" bgcolor="#EAF7F7">
</td>
<td width="140"> 
</td>
<td width="95">
</td>
<td width="70" align="right" bgcolor="#EAF7F7">
</td>
<td width="30">  </td>
<td> </td></tr>
<tr height="2"><td></td></tr>
<tr valign="top" align="left">
<td width="190"> </td>
<td width="95">
</td>
<td width="70" align="right" bgcolor="#EAF7F7">
</td>
<td width="140"> 
</td>
<td width="95">
</td>
<td width="70" align="right" bgcolor="#EAF7F7">
</td>
<td width="30">  </td>
<td> </td></tr>
<tr><td height="15"></td></tr>
<tr><td colspan="7">
<table align="top" width="100%">
<tr><td width="182"></td>
<td><hr size="1"></font></td>
</tr><tr><td height="5"></td></tr></table>
</td></tr></table>
<table cellspacing="0" cellpadding="0" width="770">
<tr><td width="190"></td>
<td><font face="Arial,Helvetica,Geneva,Sans-serif">
<b>RS485 Kommunikation</b></td></tr>
<tr><td height="8"></td></tr>
<tr><td width="190"></td>
<td><font face="Arial,Helvetica,Geneva,Sans-serif">
Wechselrichter 
<input type="Text" name="edWrNr" value="255" size="3" maxlength="3">
<input type="submit" value="Anzeigen/Aktualisieren">
</td></tr><tr><td height="10"></td></tr>
</table>
</td></tr></table></font>
<hr>
<table cellspacing="0" cellpadding="0" width="770">
<tr><td height="5"></td></tr>
<tr><td width="190"></td>
<td width="330">
<font face="Arial,Helvetica,Geneva,Sans-serif,sans-serif">
<a href="LogDaten.dat">Historie</a>
     
<a href="Info.fhtml">Infoseite</a></font></td>
<td align="right">
<font face="Arial,Helvetica,Geneva,Sans-serif,sans-serif">
<a href="Solar2.fhtml">Einstellungen</a></font></td>
<td width="50"></td>
</tr></table></font>
</form>
</body>
</html>