UK (and worldwide) Pollen Count using tomorrow.io API

I see there are a few topics about pollen count but nothing really up to date. I did look at Pollen (again) but for the UK which uses Tado but I wasnt familiar with Tado and there were some comments to say it had stopped working for people.

Therefore, I set about finding a reliable and free API thats available in the UK which seemed to be a stumbling block for a few people previously.

I found https://www.tomorrow.io which has pretty extensive API at Weather API ☀ Get the Tomorrow.io Free Weather API Now

The free account is more than enough for me and allows 500 calls per day which for a pollen count I only intend to call every hour or so. There is a limit of 25 calls per hour which did casue my initial testing issues but now ive set everything up its working fine

After getting your API key from tomorrow, the resource URL ive used is

https://api.tomorrow.io/v4/timelines?location=<LATITUDE>,-<LONGATUDE>&timesteps=1d&units=metric&apikey=<API KEY>&fields=treeIndex,grassIndex,weedIndex

I have set up my sensors using the “1d” timestep which gives me daily readings and I am pulling in the treeIndex, grassIndex and weedIndex which gives me 3 types of pollen count. You may want to adjust this for your needs by reviewing the api docs.

Ive then set up a rest sensor to pull the infomration from the end point into 5 sensors (today, tomorrow, today+2 etc) with the grass pollen rating as the main sensor but also attributes for the weed and tree pollen.

rest:
 - resource: !secret tomorrowio_pollen_api
   scan_interval: 600
   sensor:
   ### Pollen - Tree Index
     - name: "Pollen - Grass Index - Day 0"
       value_template: "{{ value_json.data.timelines[0].intervals[0]['values']['grassIndex'] }}"
       json_attributes_path: "$.data.timelines[0].intervals[0].values"
       json_attributes:
         - treeIndex
         - weedIndex
         - temperature
     - name: "Pollen - Grass Index - Day 1"
       value_template: "{{ value_json.data.timelines[0].intervals[1]['values']['grassIndex'] }}"
       json_attributes_path: "$.data.timelines[0].intervals[1].values"
       json_attributes:
         - treeIndex
         - weedIndex
         - temperature
     - name: "Pollen - Grass Index - Day 2"
       value_template: "{{ value_json.data.timelines[0].intervals[2]['values']['grassIndex'] }}"
       json_attributes_path: "$.data.timelines[0].intervals[2].values"
       json_attributes:
         - treeIndex
         - weedIndex
         - temperature
     - name: "Pollen - Grass Index - Day 3"
       value_template: "{{ value_json.data.timelines[0].intervals[3]['values']['grassIndex'] }}"
       json_attributes_path: "$.data.timelines[0].intervals[3].values"
       json_attributes:
         - treeIndex
         - weedIndex
         - temperature
     - name: "Pollen - Grass Index - Day 4"
       value_template: "{{ value_json.data.timelines[0].intervals[4]['values']['grassIndex'] }}"
       json_attributes_path: "$.data.timelines[0].intervals[4].values"
       json_attributes:
         - treeIndex
         - weedIndex
         - temperature         

This gives me all the information I need in HA, but ive then created a template sensor for each the tree, grass and weed pollen counts with todays count as the main value and then attributes for today, tomorrow, today+2 etc as this just means it displays a bit better for me in my usecase,

template:
  - sensor:
      - name: Pollen - Grass
        unique_id: sensor.pollen_grass
        state: "{{ states('sensor.pollen_grass_index_day_0') }}"
        icon: 'mdi:grass'
        attributes:
          Today: "{{ states('sensor.pollen_grass_index_day_0') }}"
          Tomorrow: "{{ states('sensor.pollen_grass_index_day_1') }}"
          Today + 2: "{{ states('sensor.pollen_grass_index_day_2') }}"
          Today + 3: "{{ states('sensor.pollen_grass_index_day_3') }}"
          Today + 4: "{{ states('sensor.pollen_grass_index_day_4') }}"
      - name: Pollen - Tree
        unique_id: sensor.pollen_tree
        state: "{{ state_attr('sensor.pollen_grass_index_day_0', 'treeIndex') }}"
        icon: 'mdi:tree'
        attributes:
          Today: "{{ state_attr('sensor.pollen_grass_index_day_0', 'treeIndex') }}"
          Tomorrow: "{{ state_attr('sensor.pollen_grass_index_day_1', 'treeIndex') }}"
          Today + 2: "{{ state_attr('sensor.pollen_grass_index_day_2', 'treeIndex') }}"
          Today + 3: "{{ state_attr('sensor.pollen_grass_index_day_3', 'treeIndex') }}"
          Today + 4: "{{ state_attr('sensor.pollen_grass_index_day_4', 'treeIndex') }}"
      - name: Pollen - Weed
        unique_id: sensor.pollen_weed
        state: "{{ state_attr('sensor.pollen_grass_index_day_0', 'weedIndex') }}"
        icon: 'mdi:spa'
        attributes:
          Today: "{{ state_attr('sensor.pollen_grass_index_day_0', 'weedIndex') }}"
          Tomorrow: "{{ state_attr('sensor.pollen_grass_index_day_1', 'weedIndex') }}"
          Today + 2: "{{ state_attr('sensor.pollen_grass_index_day_2', 'weedIndex') }}"
          Today + 3: "{{ state_attr('sensor.pollen_grass_index_day_3', 'weedIndex') }}"
          Today + 4: "{{ state_attr('sensor.pollen_grass_index_day_4', 'weedIndex') }}"

Ive then displayed this using a simple glance card using css mod to change the colours f my logos based on the height of the pollen count.

Screenshot from 2021-05-09 14-54-12

And clicking into a type of pollen shows me the forecast

Screenshot from 2021-05-09 14-55-55

I hope this can be helpful for others as we enter the hayfever season!
As mentioned at the start, i believe the tomorrow.io API covers the whole world so anyone should be able to use this implementation.

14 Likes

I’ve been using Tado via Node Red to get at their Pollen data and publish it to HA via MQTT, but I’ll certainly give your solution a try. Thanks!

Thanks for this, I just set it all up and then noticed tomorrow.io is the new name for Climacell. I installed the HA Climacell integration and that has the pollen entities in it. Has the same values as the tomorrow.io one (UK)
Only todays pollen though, no forecast, maybe that will be added in the future

Well that’s a bit annoying that there was already an integration to do more of the work!! Oh well, it was a well spent few hours anyway!!

1 Like

Yes, thanks for doing it, I’m still using it as it gives a forecast and the HA integration doesn’t

I just tried adding this integration however I am getting an invalid api key error when submitting. Did you do anything special to add the key (32 character api key) to the integration or just paste it in?

Its something to do with V3 and V4 API keys probably, the latest version of HA uses V4:

Ah, thanks!

Yeh, I just pasted it in. I wasn’t aware until after posting there were two APIs, but yeh my rest sensor is using the v4 version

I’ll add my thanks too.

Both for the integration itself, and also as a nice example of a modern style template sensor. I’m currently looking at moving a few of my legacy ones to the new style, and it’s nice to have something as a general guide :slight_smile:

1 Like

Another thanks from me too. Been searching for a Pollen integration for the last six months. I used your Rest code rather than the ClimaCell integration. Current Grass = 4, Tree = 5. Time to hibernate !! :slightly_smiling_face:

1 Like

Adding in the rest senor I get the following error and I’m not sure why?

Invalid config for [sensor.rest]: [sensors] is an invalid option for [sensor.rest]. Check: sensor.rest->sensors. (See ?, line ?). 

Hi Stuart

What is the code your trying to paste in?

The code above doesn’t generate any errors in my config.

It should be;

rest:
 - resource: !secret tomorrowio_pollen_api
   scan_interval: 600
   sensor:

Have you typed sensors: rather than sensor:?

Kind regards

Hi Craig,

Sorry yes I’ve tried sensor and sensors as I thought it was spelling mistake on your post, but neither work.
Here is my exact config;

  - platform: rest
    resource: !secret tomorrowio_api
    scan_interval: 600
    sensor:
    ### Pollen - Tree Index
      - name: "Pollen - Grass Index - Day 0"
        value_template: "{{ value_json.data.timelines[0].intervals[0]['values']['grassIndex'] }}"
        json_attributes_path: "$.data.timelines[0].intervals[0].values"
        json_attributes:
          - treeIndex
          - weedIndex
          - temperature
      - name: "Pollen - Grass Index - Day 1"
        value_template: "{{ value_json.data.timelines[0].intervals[1]['values']['grassIndex'] }}"
        json_attributes_path: "$.data.timelines[0].intervals[1].values"
        json_attributes:
          - treeIndex
          - weedIndex
          - temperature
      - name: "Pollen - Grass Index - Day 2"
        value_template: "{{ value_json.data.timelines[0].intervals[2]['values']['grassIndex'] }}"
        json_attributes_path: "$.data.timelines[0].intervals[2].values"
        json_attributes:
          - treeIndex
          - weedIndex
          - temperature
      - name: "Pollen - Grass Index - Day 3"
        value_template: "{{ value_json.data.timelines[0].intervals[3]['values']['grassIndex'] }}"
        json_attributes_path: "$.data.timelines[0].intervals[3].values"
        json_attributes:
          - treeIndex
          - weedIndex
          - temperature
      - name: "Pollen - Grass Index - Day 4"
        value_template: "{{ value_json.data.timelines[0].intervals[4]['values']['grassIndex'] }}"
        json_attributes_path: "$.data.timelines[0].intervals[4].values"
        json_attributes:
          - treeIndex
          - weedIndex
          - temperature

I think you’re trying to add a restful sensor in the sensor: config, rest has its own config as well, rest:

I assume you have yours in sensor: put it in rest: (as shown in the post above yours)

1 Like

I’ve tried to sign up for an account, but I get error message. Are they not accepting anymore accounts atm?? I have tried a few different email addresses as well.

Failed to sign-up

I registered a few minutes ago without any particular problems.
I also received an email from tomorrow.io that confirmed my registration (also offering me a paid plan).

@Craig_McGowan
Thanks for the valuable suggestions. The new sensors work perfectly.
Would you mind sharing the Lovelace card code?
I would appreciate it very much

yea. there was a glitch in their system of something. A few minutes later, I received email from all the accounts I created.

1 Like

Hey. I am using the custom_ui. This is what I have input in the customize.yaml file. You may need to reload the template and customizations configurations to see the changes.

sensor.pollen_tree:
  templates:
    icon_color: if ( state ===  '0' ) return 'rgb(178, 244, 187)'; 
     if ( state ===  '1' ) return 'rgb(115, 223, 130)'; 
     if ( state === '2' ) return 'rgb(72, 192, 89)'; 
     if ( state ===  '3' ) return 'rgb(55, 175, 72)'; 
     if ( state ===  '4' ) return 'rgb(44, 188, 65)'; 
     if ( state ===  '5' ) return 'rgb(27, 157, 44)'; 

2022-03-28_7-29-22