Pollen/Allergy Sensor

Boy I wish I had the slightest clue as to how to integrate this lol

Hello! I’m the author of that linked suggestion. It’s essentially using Benadryl’s “Social Pollen Count” API – A warning though, I don’t think this API is intended for public use…

My script (which though useful in itself, isn’t much use outside of that…) makes a request to the API like this:

https://socialpollencount.co.uk/api/forecast?location=[latitude, longitude]

So for example, to get the pollen level for Oxford, UK you might do:

https://socialpollencount.co.uk/api/forecast?location=[51.7546407,-1.2510746]

Hopefully that helps as a starting point!

1 Like

Not sure if that works in the US or not… But I’m actually currently using this method… for both allergies and cold/flu levels

# Pollen
  - platform: rest
    name: pollen_percentage
    resource: https://www.pollen.com/api/forecast/current/pollen/##### <--- ZIP CODE
    value_template: "{{value_json.Location.periods[1].Index}}"
    scan_interval: 21600
    headers:
       Referer: "https://www.pollen.com"
  - platform: template
    sensors:
      pollen_level:
        friendly_name: 'Pollen Level'
        value_template: >
          {% if states.sensor.pollen_percentage.state|float <= 2.4 %}Low
          {% elif states.sensor.pollen_percentage.state|float <= 4.8 %}Low to Medium
          {% elif states.sensor.pollen_percentage.state|float <= 7.2 %}Medium
          {% elif states.sensor.pollen_percentage.state|float <= 9.6 %}Medium to High
          {% elif states.sensor.pollen_percentage.state|float <= 12.0 %}High
          {% else %}Unknown
          {% endif %}

# Flu Sensor
  - platform: rest
    name: cold_flu_percentage
    resource: https://www.pollen.com/api/forecast/extended/cold/##### <--- ZIP CODE
    value_template: "{{value_json.Location.periods[1].Index}}"
    scan_interval: 21600
    headers:
       Referer: "https://www.pollen.com"
  - platform: template
    sensors:
      cold_flu_risk:
        friendly_name: 'Cold & Flu Risk'
        value_template: >
          {% if states.sensor.cold_flu_percentage.state|float <= 2.4 %}Low
          {% elif states.sensor.cold_flu_percentage.state|float <= 4.8 %}Low to Medium
          {% elif states.sensor.cold_flu_percentage.state|float <= 7.2 %}Medium
          {% elif states.sensor.cold_flu_percentage.state|float <= 9.6 %}Medium to High
          {% elif states.sensor.cold_flu_percentage.state|float <= 12.0 %}High
          {% else %}Unknown
          {% endif %}

I also have sensors for the months of the year to determine if it’s flu season or allergy season for use in automations.

4 Likes

Thanks for sharing this @itchaboy!

Something I’ve wanted for a long time and it works great in the US (I can finally ditch my pollen.com iFrame). Do you know by chance how to display the current “Top Allergens” as well as tomorrows forecast?

You’re welcome! I can’t take all the credit for the API discovery but I’m glad to share.

I would love to have access to those metrics as well… :confused: weird urls. For example the cold/flu one only works with “extended” while the pollen one only works with “current”. :unamused: So who knows. I’ll see if I can dig up where this was first mentioned.

1 Like

Here we go! This is were I originally found it. Pollen tracker in Wunderground plugin [solved]

1 Like

Thanks to you and @Wheezy for this great share.

Works great, never mind the names, quick put together, still working on best naming options

2 Likes

I did some digging around on their site and I’ve got tomorrow’s forecast, top allergens, and trend working. Expand the code block below to see my configuration. Make sure you replace ZIPCODE with your zip code.

Expand to see the code
homeassistant:
  customize:
    sensor.pollen_index:
      icon: mdi:flower
    sensor.pollen_level:
      icon: mdi:flower
    sensor.top_allergen_1:
      icon: mdi:flower
    sensor.top_allergen_2:
      icon: mdi:flower
    sensor.top_allergen_3:
      icon: mdi:flower
    sensor.pollen_trend:
      icon: mdi:flower
    sensor.pollen_outlook:
      icon: mdi:flower
    sensor.pollen_season:
      icon: mdi:flower
    sensor.pollen_index_forecast:
      icon: mdi:flower
    sensor.pollen_level_forecast:
      icon: mdi:flower
    sensor.cold__flu_percentage:
      icon: mdi:snowflake
    sensor.cold_flu_risk:
      icon: mdi:snowflake

sensor:
  # Today's Pollen Index
  - platform: rest
    name: 'Pollen Index'
    resource: https://www.pollen.com/api/forecast/current/pollen/ZIPCODE
    value_template: "{{value_json.Location.periods[1].Index}}"
    scan_interval: 21600
    headers:
      Referer: "https://www.pollen.com"

  # Today's Pollen Level
  - platform: template
    sensors:
      pollen_level:
        friendly_name: 'Pollen Level'
        entity_id: sensor.pollen_index
        value_template: >-
          {%- if states.sensor.pollen_index.state|float <= 2.4 %}
              Low
          {%- elif states.sensor.pollen_index.state|float <= 4.8 %}
              Med/Low
          {%- elif states.sensor.pollen_index.state|float <= 7.2 %}
              Med
          {%- elif states.sensor.pollen_index.state|float <= 9.6 %}
              Med/High
          {%- elif states.sensor.pollen_index.state|float <= 12.0 %}
              High
          {% else %}
              Unknown
          {%- endif %}

  # Tomorrow's Pollen Index Forecast
  - platform: rest
    name: 'Pollen Index Forecast'
    resource: https://www.pollen.com/api/forecast/current/pollen/ZIPCODE
    value_template: "{{value_json.Location.periods[2].Index}}"
    scan_interval: 21600
    headers:
      Referer: "https://www.pollen.com"

  # Tomorrow's Pollen Level Forecast
  - platform: template
    sensors:
      pollen_level_forecast:
        friendly_name: 'Pollen Level Forecast'
        entity_id: sensor.pollen_index
        value_template: >-
          {%- if states.sensor.pollen_index_forecast.state|float <= 2.4 %}
              Low
          {%- elif states.sensor.pollen_index_forecast.state|float <= 4.8 %}
              Med/Low
          {%- elif states.sensor.pollen_index_forecast.state|float <= 7.2 %}
              Med
          {%- elif states.sensor.pollen_index_forecast.state|float <= 9.6 %}
              Med/High
          {%- elif states.sensor.pollen_index_forecast.state|float <= 12.0 %}
              High
          {% else %}
              Unknown
          {%- endif %}

  # Today's Top Allergen
  - platform: rest
    name: 'Top Allergen 1'
    resource: https://www.pollen.com/api/forecast/current/pollen/ZIPCODE
    value_template: >-
      {% if value_json.Location.periods[1].Triggers[0] %}
      {{ value_json.Location.periods[1].Triggers[0].PlantType }}
      {% else %}
      -
      {% endif %}
    scan_interval: 21600
    headers:
      Referer: "https://www.pollen.com"

  # Today's Second Allergen
  - platform: rest
    name: 'Top Allergen 2'
    resource: https://www.pollen.com/api/forecast/current/pollen/ZIPCODE
    value_template: >-
      {% if value_json.Location.periods[1].Triggers[1] %}
      {{ value_json.Location.periods[1].Triggers[1].PlantType }}
      {% else %}
      -
      {% endif %}
    scan_interval: 21600
    headers:
      Referer: "https://www.pollen.com"

  # Today's Third Allergen
  - platform: rest
    name: 'Top Allergen 3'
    resource: https://www.pollen.com/api/forecast/current/pollen/ZIPCODE
    value_template: >-
      {% if value_json.Location.periods[1].Triggers[2] %}
      {{ value_json.Location.periods[1].Triggers[2].PlantType }}
      {% else %}
      -
      {% endif %}
    scan_interval: 21600
    headers:
      Referer: "https://www.pollen.com"

  # Pollen Trend
  - platform: rest
    name: 'Pollen Trend'
    resource: https://www.pollen.com/api/forecast/outlook/ZIPCODE
    value_template: "{{value_json.Trend}}"
    scan_interval: 21600
    headers:
      Referer: "https://www.pollen.com"

  # Pollen Outlook
  - platform: rest
    name: 'Pollen Outlook'
    resource: https://www.pollen.com/api/forecast/outlook/ZIPCODE
    value_template: "{{value_json.Outlook}}"
    scan_interval: 21600
    headers:
      Referer: "https://www.pollen.com"

  # Pollen Season
  - platform: rest
    name: 'Pollen Season'
    resource: https://www.pollen.com/api/forecast/outlook/ZIPCODE
    value_template: "{{value_json.Season}}"
    scan_interval: 21600
    headers:
      Referer: "https://www.pollen.com"

  # Today's Cold/Flu Percentage
  - platform: rest
    name: 'Cold & Flu Percentage'
    resource: https://www.pollen.com/api/forecast/extended/cold/ZIPCODE
    value_template: "{{value_json.Location.periods[1].Index}}"
    scan_interval: 21600
    headers:
      Referer: "https://www.pollen.com"
    unit_of_measurement: "%"

  # Today's Cold/Flu Risk
  - platform: template
    sensors:
      cold_flu_risk:
        friendly_name: 'Cold & Flu Risk'
        entity_id: sensor.cold__flu_percentage
        value_template: >-
          {%- if states.sensor.cold__flu_percentage.state|float <= 2.4 %}
              Low
          {%- elif states.sensor.cold__flu_percentage.state|float <= 4.8 %}
              Med/Low
          {%- elif states.sensor.cold__flu_percentage.state|float <= 7.2 %}
              Med
          {%- elif states.sensor.cold__flu_percentage.state|float <= 9.6 %}
              Med/High
          {%- elif states.sensor.cold__flu_percentage.state|float <= 12.0 %}
              High
          {% else %}
              Unknown
          {%- endif %}
6 Likes

Way to go! Huge thanks to @NotoriousBDG, @Wheezy, and @itchaboy. Working great here

1 Like

Outstanding! Thank you so much for figuring this out.

1 Like

Just implemented this and it is awesome. Thank you for all the hard work.

1 Like

Happy to help, dudes. Though we can’t forget @arsaboo, who supplied the code that got my setup working.

2 Likes

Working great too!

One small improvement is on the template sensors you can add a entity_id: to indicate on what states to update the template sensors.

If not specified, like in the above examples; those template sensors will be processed on EVERY state change and not just the ones impacting those sensors.

2 Likes

Awesome tip. I updated my post above with your recommendation.

Hi gang. Great work by all.

FYI, last night, two of the sensors threw errors because the HTTP route returned full-on HTML. Makes me realize that we might benefit from an official sensor platform that uses this information and can do caching, recognition of invalid responses, etc. I’d be glad to take a stab at it. What do you think?

I saw the same errors. An official component would be great.

Great! Hacked together a quick library: https://github.com/bachya/pypollencom – will start working on the sensors themselves tonight.

2 Likes

Nice! This would be greatly appreciated.

Alrighty, folks – making great progress: I have the base platform in place. Will submit an official PR tomorrow; in the meantime, enjoy some screenshots!

2 Likes

Alrighty: PR completed and submitted. PRs:

Sensor Platform: https://github.com/home-assistant/home-assistant/pull/11573
Docs: https://github.com/home-assistant/home-assistant.github.io/pull/4392

2 Likes