Melbourne Pollen Forecast Scrape Sensor and Lovelace "Card"

The “card” for this still seems to work too. Just adjust the sensor and attribute names in the Lovelace config.

1 Like

Edit: in reference to the screen scraping approach

Since the Melbourne area has its own little carve out and isn’t in that large table, how would I grab the values from the first tile that appears on the page? I think it’s represented there?

Did you have a crack at this for it?

I have a whole new approach cooking but it probably won’t be ready to share for a few weeks.

Oh hang on, did you see this?

1 Like

Hey Guys, really well done on figuring this out!

Is there any chance you could please help me with scrapping data for Northern Country?

Thank you,

Sure. What have you tried so far?

well, I couldn’t figure out how
I’m not a web dev but to me, I thought this page was dynamic with js code to load first the city in the widget.

this is what I tried but I cant get it to work from the image to the side of the NORTHERN COUNTRY

sensor:
  - platform: rest
    resource: https://www.melbournepollen.com.au/ 
    name: Northern Country Pollen Level
    scan_interval: 3600 
    value_template: '{{ value_json.pollen_level }}'
    json_attributes:
      - pollen_level
    selector: "#district-pollen-div > div > div > div > div > div > div.uk-grid-match.uk-child-width-1-2\@s.uk-text-center.uk-grid-collapse.uk-grid > div:nth-child(2) > div:nth-child(6)"

Canberra version is working with just a change to resource, the site does not have a ‘last updated’ entry so I have commented that out.

I should have something fancy for you in the next few weeks. Stay tuned;)

I think you were close. I think this works. Give it a go…

multiscrape:
  - resource: https://www.melbournepollen.com.au/
    scan_interval: 3600 #3600 sec = 1 hr
    name: Pollen Forecast
    sensor:
      - unique_id: northern_country_forecast_today
        name: Pollen Forecast Today
        select: '#district-pollen-div > div > div > div > div > div > div.uk-grid-match.uk-child-width-1-2\@s.uk-text-center.uk-grid-collapse.uk-grid > div:nth-child(2) > div:nth-child(6) > div:nth-child(2) > div'
        value_template: '{{ value| trim}}'
        icon: >-
          {% if value == 'Low' %}
            mdi:emoticon-happy
          {% elif value == 'Moderate' %}
            mdi:emoticon-neutral
          {% elif value == 'High' %}
            mdi:emoticon-sad
          {% elif value == 'Extreme' %}
            mdi:emoticon-angry
          {% else %}
            mdi:help-circle
          {% endif %}

You do it like this…

that worked! thank you!

1 Like

Thanks I thought I was doing something wrong but it was as simple as making it
select: ‘#plevel

1 Like

If anyone wants to test my new custom integration, PM me for details once you’ve read the Github details. Cheers.

image

1 Like

I have tried to install on my test system and as the doco states the api is optional I left it blank and I get this error:

error

What should I put here ??

I suspect you need to remove the whole url_api rather than leave it blank. If you can confirm that is the case I’ll either clarfiy in the docs or make the code more forgiving.

Edit: I’ve updated the docs for now as I’m relatively sure that’s what’s happened…

I commented out that line and it passes the config check but I get this in the log:

My config is:

sensor:
  - platform: oz_poll
    url_website: https://www.canberrapollen.com.au/
#    url_api: 
    i_subscribe_and_support: false
2023-11-05 19:55:12.911 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up oz_poll platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 359, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/oz_poll/sensor.py", line 40, in setup_platform
add_entities([OzPollSensor(url_website, url_api, i_subscribe_and_support)])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/oz_poll/sensor.py", line 52, in __init__
self.update()
File "/config/custom_components/oz_poll/sensor.py", line 68, in update
).get_text(strip=True)
^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get_text'

OK, I think I missed a step in the installation but when I try to add the oz Poll integration I get this error:

error2

I think it may be due to you using the Canberra site. I didn’t actually do any testing for Canberra yet.
Could you please confirm if this works ok for you?
That should help confirm it’s just a related Canberra issue and then I’ll see what I can do.

sensor:
  - platform: oz_poll
    url_website: https://www.melbournepollen.com.au/
#    url_api:
    i_subscribe_and_support: false

I think it’s because it’s looking for some info that doesn’t exist on the Canberra page and it doesn’t handle that properly.

The Melbourne site works fine.

1 Like

Ok I think I know what’s going on. Just my crappy error handling. I should have time tommorrow or Tue to take a look at it. I’ll do more testing for Canberra. I’ll do a new release and ping you when it’s available.