Scrape sensor help to read pollution data

I’m trying to take read on-line pollution data from a spanish website … but I don’t know how to “select” the correct info for the nice Scrape Sensor.

For example, I tried to “read” the blue color value and using “How to find the css selector in chrome” ( I have this string:

#contenido_aplicacion > table > tbody > tr:nth-child(3) > td:nth-child(1) > table > tbody > tr:nth-child(2) > td:nth-child(2)

… but it’s not right for the HA :frowning:


I have made a lot of trials (using Jupyter notebook too) without any success.

HELP ME, please!

The documentation of the scrape sensor contains a link to the details about the CSS selection. If you want to use nth, try something like 'td:nth-of-type(16)'.

Thank you! It works … but only to “read” one data

It is possible to use something like ‘table:nth-of-type(4)’ to read a table (with less than 255 char) amd using a template take more than one data?

Perhaps it would be better to use ‘tr:nth-of-type(16)’ to have description and value. But how is would be possible to read two or three row in just one sensor?

With the scrape sensor no. I designed the sensor to extract one value per sensor to support unit of measurement and naming. Well, it could be possible to do more complicated things with a template but I haven’t tested that. Keep in mind that with a custom component such things are easy possible.

Again, with a custom component you could read the whole table and create a sensor for every entry. Here is an example:

got the same problem (SOLVED below), data from solar inverter are in td table but mine is not able to read but it just extract empty values.
I can extract words “Status” and “set” from middle line

just by defining this sensor with index 18

 - platform: scrape
    select: "td"
    index: 18
    unit_of_measurement: "kW"
    name: "aaaaa1"

/developer-tools/state returns:

[sensor.aaaaa1] Status unit_of_measurement: kW friendly_name: aaaaa1

but with the index 21 (W) or 22 (kWh) which should work for the bottom line it just gives empty value
whats wrong here?

> <tr><td width="150"><span data-locale="sn">SN.</span></td>
> 	<td width="120"><span data-locale="pacw">Pac(W)</span></td>
> 	<td width="150"><span data-locale="etoday">E_Today(KWh)</span></td>
> 	<td width="130"><span data-locale="status">Status</span></td>	<- this is  index 18
> 	<td width="60"><span data-locale="set">Set</span></td></tr>     <- this is  index 19
> <tr style="">
> 	<td>AW00056012080037</td>    <- should be 20 ?
> 	<td>914</td>                 <- should be 21 ?
> 	<td>7.80</td>
> 	<td class="ok"></td>


Solution to my case was: yep this is a java script that fills the table.
With some help i was able to find that java stores it in a raw text file and…
a single line command extracts them perfectly:

   - platform: command_line 
    name: "energia_pv" 
    command: "curl | sed -n 12p"

12p represents 12 row in the file, simple as that :slight_smile:
maybe this will help someone.