Hi all,
I would like to scrape data (temperature 2m above terrain) from this website
https://www.chmi.cz/files/portal/docs/uoco/web_generator/aqindex_slide3h3/mp_TCTNA_GB.html
My config sensor select doesnt work.
select: “#tooltipMap_T2m > area:nth-child(1)”
Ty for hint
In the absence of what you’ve set up, I created a scrape entity like this:
- resource: https://www.chmi.cz/files/portal/docs/uoco/web_generator/aqindex_slide3h3/mp_TCTNA_GB.html
sensor:
- name: MB Test Scrape
select: "#tooltipMap_T2m > area"
attribute: onmouseover
I don’t believe the nth-child(1)
is required, because scrape defaults to getting the first.
I imagine this is similar to what you’ve got, and the result is … nothing. However, if you change ‘onmouseover’ to ‘shape’, then it correctly gets the value “poly”. So the selector is correct, it just isn’t getting the attribute you want. The page is completely static, so it’s not as if the mouse over event is dynamically attached. This made me suspicious, so I looked in the log and found this:
Invalid state encountered for entity ID: sensor.mb_test_scrape_1. State max length is 255 characters.
Aha! So ensuring I only got a subsection (it looks like the first 79 character never change size), and then getting the part before the space:
- resource: https://www.chmi.cz/files/portal/docs/uoco/web_generator/aqindex_slide3h3/mp_TCTNA_GB.html
sensor:
- name: MB Test Scrape
select: "#tooltipMap_T2m > area"
attribute: onmouseover
value_template: "{{ value[80:90].split(' ')[0] }}"
This gives me:
-4.9
Woohoo!
Thank you Michael very much. I’m a beginner with HA now. I had value template like this:
value_template: ‘{{ value.split(“UTC”)[1].split(" ")[0]}}’
and missing “attribute :onmouseover” like your solution.