itchaboy
(Itchaboy)
August 3, 2017, 10:33am
6
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
jmart518
(JT Martinez)
August 4, 2017, 12:57am
7
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?
itchaboy
(Itchaboy)
August 4, 2017, 3:40am
8
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… weird urls. For example the cold/flu one only works with “extended” while the pollen one only works with “current”. So who knows. I’ll see if I can dig up where this was first mentioned.
1 Like
itchaboy
(Itchaboy)
August 4, 2017, 4:01am
9
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
jmart518
(JT Martinez)
August 4, 2017, 7:56pm
12
Way to go! Huge thanks to @NotoriousBDG , @Wheezy , and @itchaboy . Working great here
1 Like
itchaboy
(Itchaboy)
August 4, 2017, 9:10pm
13
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
Wheezy
August 6, 2017, 4:44pm
15
Happy to help, dudes. Though we can’t forget @arsaboo , who supplied the code that got my setup working.
2 Likes
jwelter
(John Welter)
August 17, 2017, 1:19am
16
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.
bachya
(Aaron Bach)
January 9, 2018, 6:57pm
18
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?
jwelter
(John Welter)
January 9, 2018, 7:43pm
19
I saw the same errors. An official component would be great.
bachya
(Aaron Bach)
January 9, 2018, 10:07pm
20
Great! Hacked together a quick library: https://github.com/bachya/pypollencom – will start working on the sensors themselves tonight.
2 Likes
itchaboy
(Itchaboy)
January 10, 2018, 12:30am
21
Nice! This would be greatly appreciated.
bachya
(Aaron Bach)
January 10, 2018, 5:13am
22
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
bachya
(Aaron Bach)
January 11, 2018, 2:46am
23
2 Likes
ikifar2015
(Matheson Steplock)
January 11, 2018, 3:15am
24
How can I do this in Canada?
I am new to Home Assistant
itchaboy
(Itchaboy)
January 12, 2018, 1:20pm
25
Bravo on the quick work! Thank you. Will you be doing the cold/flu sensors as well?