Unfortunately, I’m one of the 1 in 41 people who suffer from hay fever as an adult, and this weekend gave me my first reminder that I needed to start taking my antihistamines. What annoyed me (other than the runny nose and slight burning in my eyes) was that, once again, I was unprepared for it. I already know that my issue is mainly tree pollen, and pollen season for trees starts earlier than what most people associate with ‘hay fever time.’ So I turned to Home Assistant, using a scraper with Kleenex’s data, and built a system to notify me every morning if the pollen level is above a certain value.

For my first attempt at building this system, I had planned to use the Tomorrow.io API (HA Forum Post). Unfortunately, the API returned 0 for all the values, so I needed to find a new source for the data. This could mean that the API is either inaccurate or doesn’t support the UK.

Rubbish data from Tomorrow.io

After searching the internet a bit more, I found that Kleenex offers a pollen count. Thankfully, the results from their site were much more promising.

Kleenex pollen overview

Now that we have a source for the data, we can use Home Assistant’s built in scrape sensor to retrieve the page and extract the relevant parts of the data to different sensors. Fortunately, I stumbled upon a helpful Home Assistant forum post that was similar to what I needed (HA Forum Post)

Updated 11/07/2023 I noticed that a lot of the calls to the Kleenex service were failing, I did some investigation and they’ve updated their site. Thankfully, I didn’t have to do a lot to update the scrape sensor below. If you’ve followed this post before, you’ll need to update the resource and payload


scrape:
  - resource: https://www.kleenex.co.uk/api/sitecore/Pollen/GetPollenContentCountryCity
    method: POST
    payload: "city=<POSTCODE>&country=uk
    headers:
      Content-Type: application/x-www-form-urlencoded; charset=UTF-8
    scan_interval: 3600
    sensor:
      - name: Pollen (grass)
        select: "li.day-container:nth-child(1) > button"
        unit_of_measurement: "PPM"
        state_class: measurement
        attribute: "data-grass-count"
        unique_id: pollen_grass
        value_template: {{ value.split(" ")[0] }}
      - name: Pollen (weeds)
        select: "li.day-container:nth-child(1) > button"
        unit_of_measurement: "PPM"
        state_class: measurement
        attribute: "data-weeds-count"
        unique_id: pollen_weeds
        value_template: {{ value.split(" ")[0] }}
      - name: Pollen (trees)
        select: "li.day-container:nth-child(1) > button"
        unit_of_measurement: "PPM"
        state_class: measurement
        attribute: "data-trees-count"
        unique_id: pollen_trees
        value_template: {{ value.split(" ")[0] }}

For my particular needs, I know that tree pollen is my arch-nemisis. So I need to build an automation that will send an alert to my phone in the morning when tree pollen levels are over x. I’ll have to tweak this value depending on how I’m feeling in the day compared to the alert that I receive.

alias: Mike - Pollen Alert
description: ""
trigger:
  - platform: time
    at: "07:00:00"
condition:
  - condition: numeric_state
    entity_id: sensor.pollen_trees
    above: 100
action:
  - service: notify.mobile_app_pixel_4_xl
    data:
      title: Pollen Alert
      message: Don't forget to take your antihistamine today, pollen levels look ugly!
mode: single

Hopefully this will be enough to remind me to take my antihistamines

If you found this content helpful, please consider sponsoring me on GitHub or alternatively buying me a coffee

Comments