Melbourne Pollen Forecast Scrape Sensor and Lovelace "Card"

Not sure what’s up with the Thunderstorm Asthma forecast for this season.

Also at time of publishing one day of forecast seemed to be missing (from the API).

Will monitor that.

image

1 Like

I’ve also noticed that the API and the webpage can report different results.

image

The webpage is also consistent with the app.

Possibly they use different versions of the API or have different update intervals.

Not sure “who is right”…

Mine’s broken again lol. Stay tuned…

And so hilariously this has now changed back to lower case and so I’ll revert back to previous code. If it happens again I might do something smarter…

Updated solution post.

Sorry - accidentally turned off all email notifications from the forum so just saw your replies. It actually started working again miraculously - likely due to them reverting the change to case. Will circle back here if it happens again! Thanks for looking into it though :slight_smile:

1 Like

I wonder what other data is lurking around in other app/api versions.

Edit:
I think this one is for Melbourne
https://api.pollenforecast.com.au/app/json/app_data.php?app=1&version=5
I think this one is for Canberra
https://api.pollenforecast.com.au/app/json/app_data.php?app=2&version=4
I think this one is for Sydney
https://api.pollenforecast.com.au/app/json/app_data.php?app=3&version=4

I’ve noticed that the pollen forecasts via the API are not consistent with what’s in the app. And so am becoming skeptical as to whether the data source we are using for this is still valid.

1 Like

Can you please confirm if the code snippets are the latest? Not working for me and I see there was a breaking change around capitalisation in the API but that’s not in the code snippets?

For me, that issue changed, and then changed back!

But mine has also changed yet again so it looks like the breaking change has returned…

Fix will be confirmed soonish… It is expected to be as per config snippet in this post.

I’ve built an intial handle for the intermittent breaking change where the api fllips between upper and title case.

The main solution post has bee updated and the change noted at the bottom. It should be working again and a bit more reliable now.

The change is in this part.

          melbourne_6day_pollen_forecast: >-
            {% set forecastpageHTML = states.sensor.melbourne_pollen_api_html.attributes.forecastpage %}
            {% set LowerForecastpageHTML = forecastpageHTML|lower  %}
            {{ 
            '{\n' +
            LowerForecastpageHTML
            |replace('monday', 'Mon')
            |replace('tuesday', 'Tue')
            |replace('wednesday', 'Wed')
            |replace('thursday', 'Thu')
            |replace('friday', 'Fri')
            |replace('saturday', 'Sat')
            |replace('sunday', 'Sun')
            |replace('melbourne pollen forecast', '"days": [')
            |replace('<h2 ', '*nl*{*nl*"day_short_name":"<h1 ')
            |replace('</h2>', '</h2>",*nl* ')
            |replace('<p', '"date":"<p')
            |replace('p>', '<\/p>",*nl* ')
            |replace('<div class="pollen-forecast-level', '"pollen_level":"<<div class="pollen-forecast-level')
            |replace('low', 'Low"},')
            |replace('moderate', 'Moderate"},')
            |replace('high', 'High"},')
            |replace('extreme', 'Extreme"},')
            |striptags
            |replace('*nl*', '\n') + ']\n}'
            }} 

I’m still not convinced the API is giving us valid forecasts this year, but that’s another matter…

FYI I think the card widget code also may need updating to have flexibility in the uppercase/sentence case values coming through. I tested with a simple || addition and seemed to fix it.

EDIT: Sorry just saw that you already mentioned thunderstorm asthma alerts aren’t working via the API :slight_smile:

e.g.:
((states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[1].pollen_level == 'LOW') || (states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[1].pollen_level == 'Low'))

I think it should be ok. Because I now process upper or title case to be title case. So the upstream card doesn’t need adjusting.

I just validated this against the app. So maybe forecasts are still ok.
image

Dropping back from version 5 to 4 appears to bring back the thunderstorm asthma forecast.
I’ll update the main solution in a sec.
If poeple could keep an eye on it vs the webpage and let me know if they spot any issues that would be tops.

Use:
https://api.pollenforecast.com.au/app/json/app_data.php?app=1&version=4
Not:
https://api.pollenforecast.com.au/app/json/app_data.php?app=1&version=5

image

This also validates against the app. So all good.
image

I think the code for the dashboard tiles is wrong in your master solution post. Icons weren’t working.

Here’s my code and the icons seem to be ok. Using V4 API.

type: horizontal-stack
show_name: true
show_icon: true
show_state: true
title: Pollen Count and Forecast
cards:
  - type: custom:button-card
    entity: sensor.melbourne_pollen_forecast_api
    state_display: >
      [[[return
      (states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level);]]]
    label: |
      [[[return 'Pollen Today';]]]
    icon: |
      [[[
        if ((states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'LOW') || (states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'Low'))
          return "mdi:emoticon-happy";
        if ((states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'MODERATE') || (states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'Moderate'))
          return "mdi:emoticon-neutral";
        if ((states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'HIGH') || (states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'High'))
          return "mdi:emoticon-sad";
        if ((states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'EXTREME') || (states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'Extreme'))
          return "mdi:emoticon-angry";
        else
          return "mdi:help-circle";
      ]]]
    show_label: true
    show_state: true
    show_name: false
    size: 70%
    aspect_ratio: 2/1
    layout: icon_state
    styles:
      name:
        - font-weight: bold
        - font-size: 0.5vw
        - color: grey
      icon:
        - color: |
            [[[
              if ((states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'LOW') || (states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'Low'))
                return 'lime';
              if ((states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'MODERATE') || (states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'Moderate'))
                return 'yellow';
              if ((states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'HIGH') || (states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'High'))
                return 'orange';
              if ((states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'EXTREME') || (states['sensor.melbourne_pollen_forecast_api'].attributes.melbourne_6day_pollen_forecast.days[0].pollen_level == 'Extreme'))
                return 'red';
              else
                return 'grey';
            ]]]
      label:
        - font-weight: bold
        - font-size: 0.8vw
        - color: white
  - type: custom:button-card
    entity: sensor.melbourne_pollen_forecast_api
    state_display: >
      [[[return
      (states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0]);]]]
    label: |
      [[[return 'Thunderstorm Asthma Today';]]]
    icon: |
      [[[
        if ((states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'low') || (states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'LOW'))
          return "mdi:emoticon-happy";
        if ((states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'moderate') || (states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'MODERATE'))
          return "mdi:emoticon-neutral";
        if ((states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'high') || (states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'HIGH'))
          return "mdi:emoticon-sad";
        if ((states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'extreme') || (states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'EXTREME'))
          return "mdi:emoticon-angry";
        else
          return "mdi:help-circle";
      ]]]
    show_label: true
    show_state: true
    show_name: false
    size: 70%
    aspect_ratio: 2/1
    layout: icon_state
    styles:
      name:
        - font-weight: bold
        - font-size: 0.5vw
        - color: grey
      icon:
        - color: |
            [[[
              if ((states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'low') || (states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'LOW'))
                return 'lime';
              if ((states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'moderate') || (states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'MODERATE'))
                return 'yellow';
              if ((states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'high') || (states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'HIGH'))
                return 'orange';
              if ((states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'extreme') || (states['sensor.melbourne_pollen_forecast_api'].attributes.my_district_asthma_forecast_today[0] == 'EXTREME'))
                return 'red';
              else
                return 'grey';
            ]]]
      label:
        - font-weight: bold
        - font-size: 0.8vw
        - color: white
      state:
        - text-transform: uppercase

Mine are working fine. Perhaps I made changes and forgot to update the post, but I don’t think so.

Thanks for reporting. I’ll take a closer look soonish and try to clarify what’s happening.

This week if looking a bit grim.

I prob should optimize the text size for mobile too.

I’ve dropped in a fresh copy of my working lovelace config and added an update note to that solution post about whats going on (in summary, no clue, quite possibly my bad version management when i do slap-dash fixes.).

Thanks for letting me know. Hopefully it’s ok now for other users…

Just found this topic - what a great idea - have been struggling with pollen and storm asthma for a couple of weeks now, so will be interesting to see if I can correlate the forecasting with how I’m feeling - awesome bit of coding!

1 Like

It’s really ramping up this week!