Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Home Assistant Ambee Pollen API
### Ambee Pollen
# Must be added in sensor.yml
# replace LAT, LONG and API-KEY with your values
- platform: rest
scan_interval: 3600
resource: https://api.ambeedata.com/latest/pollen/by-lat-lng?lat=LAT&lng=LONG
name: "Ambee Pollen"
headers:
content-type: "application/json"
x-api-key: "API-KEY"
json_attributes_path: "$.data.['Risk']"
json_attributes:
- tree_pollen
- grass_pollen
- weed_pollen
- platform: template
sensors:
ambee_pollen_tree:
icon_template: "mdi:tree-outline"
friendly_name: "tree"
value_template: >-
{% set state = state_attr('sensor.ambee_pollen', 'tree_pollen') %}
{% if state == "Low" %}Niedrig
{% elif state == "Moderate"%}Mittel
{% elif state == "High"%}Hoch
{% elif state == "Very High"%}Sehr hoch
{% else %}Unbekannt{% endif %}
- platform: template
sensors:
ambee_pollen_weed:
icon_template: "mdi:nature"
friendly_name: "weed"
value_template: >-
{% set state = state_attr('sensor.ambee_pollen', 'weed_pollen') %}
{% if state == "Low" %}Niedrig
{% elif state == "Moderate"%}Mittel
{% elif state == "High"%}Hoch
{% elif state == "Very High"%}Sehr hoch
{% else %}Unbekannt{% endif %}
- platform: template
sensors:
ambee_pollen_grass:
icon_template: "mdi:grass"
friendly_name: "grass"
value_template: >-
{% set state = state_attr('sensor.ambee_pollen', 'grass_pollen') %}
{% if state == "Low" %}Niedrig
{% elif state == "Moderate"%}Mittel
{% elif state == "High"%}Hoch
{% elif state == "Very High"%}Sehr hoch
{% else %}Unbekannt{% endif %}
@awolkers

This comment has been minimized.

Copy link

@awolkers awolkers commented Apr 6, 2021

First of all thanks for the example. Did you actually got this to work? I needed to change the json path to this:
json_attributes_path: "$.data[0].Risk"

@michilehr

This comment has been minimized.

Copy link
Owner Author

@michilehr michilehr commented Apr 6, 2021

First of all thanks for the example. Did you actually got this to work? I needed to change the json path to this:
json_attributes_path: "$.data[0].Risk"

Yes. Should work for you, too.

[] , the subscript operator, finds all children matching by name or index.

With your code, you must be sure that the requested data is always on the given index.
With my version, I must be sure that there is no other child in the tree with the same name.

RESTful is using jsonpath 0.82 which did not change.

You can check it out on https://jsonpath.curiousconcept.com/ (select 0.8.2 by Stefan Goessner).

JSON Data/URL

{
   "message":"Success",
   "lat":"40.730610",
   "lng":"-73.935242",
   "data":[
      {
         "Count":{
            "grass_pollen":0,
            "tree_pollen":71,
            "weed_pollen":0
         },
         "Risk":{
            "grass_pollen":"Low",
            "tree_pollen":"Low",
            "weed_pollen":"Low"
         },
         "updatedAt":"2021-04-06T16:20:19.000Z"
      }
   ]
}

JSONPath Expression

$.data.['Risk']

JSONPath Result

[
   {
      "grass_pollen":"Low",
      "tree_pollen":"Low",
      "weed_pollen":"Low"
   }
]
@awolkers

This comment has been minimized.

Copy link

@awolkers awolkers commented Apr 7, 2021

Apparently I had this other issue going on with the config. I did checked both expressions by the way and they both work fine. The order within the array doesn't matter. Thanks anyway! Question about the scan_interval. You set it to 3600. That's in seconds right? The free plan of Embee only allows 100 call a months so you might want to bump that interval number. So calling the api once every 8 hours will be save

@michilehr

This comment has been minimized.

Copy link
Owner Author

@michilehr michilehr commented Apr 7, 2021

100 API calls/day

See https://www.getambee.com/api/air-quality

The data can change within a day. So I've decided to pull new data every hour.

@miikalep

This comment has been minimized.

Copy link

@miikalep miikalep commented Apr 12, 2021

Cool work! I am total noob. How can I get HA to load this config file? I sort of got it by copying it to config.yaml and adding "sensor: " in front of it, but that is clearly bastardly of me and does not create correctly functional sensors.

@awolkers

This comment has been minimized.

Copy link

@awolkers awolkers commented Apr 13, 2021

Did you signed up at the ambee site and got the api key from them?

@miikalep

This comment has been minimized.

Copy link

@miikalep miikalep commented Apr 13, 2021

Yes! Ambee seems to work fine.

How to get HA to load this config? Maybe some !include ambee.yaml statement, but what is the top level "thing" where this is included? My noobness is showing here, but I am learning fast and using my best google-fu.

@awolkers

This comment has been minimized.

Copy link

@awolkers awolkers commented Apr 13, 2021

You might want to drop this in the HA community forum

@michilehr

This comment has been minimized.

Copy link
Owner Author

@michilehr michilehr commented Apr 13, 2021

I will write a tutorial later when I have some time.

@miikalep

This comment has been minimized.

Copy link

@miikalep miikalep commented Apr 13, 2021

I got it workin! I had translated some of the code to my language and broken some of the variables, my bad!

The information that I feel is missing here, is that this code describes sensors, so it needs to be classified as such in HA congif.

I have this copypasted in my configuration.yaml like this:

sensor:
### Ambee Pollen
# replace LAT, LONG and API-KEY with your values
  - platform: rest
    scan_interval: 3600
    ... and so on

There are other ways of telling this to HA, but the idea is the same. Thank you for your help!

@michilehr

This comment has been minimized.

Copy link
Owner Author

@michilehr michilehr commented Apr 13, 2021

I got it workin! I had translated some of the code to my language and broken some of the variables, my bad!

The information that I feel is missing here, is that this code describes sensors, so it needs to be classified as such in HA congif.

I have added a comment in line 3.

Thank you for clearing that up!

So no tutorial :)

@Quintin1009

This comment has been minimized.

Copy link

@Quintin1009 Quintin1009 commented Apr 16, 2021

it is failing on my dashboard..

{"message":"lat should be integer","data":[]}

Can somebody help me?

@michilehr

This comment has been minimized.

Copy link
Owner Author

@michilehr michilehr commented Apr 16, 2021

You need to replace LAT and LONG with your location data in line 8.

@Quintin1009

This comment has been minimized.

Copy link

@Quintin1009 Quintin1009 commented Apr 16, 2021

You need to replace LAT and LONG with your location data in line 8.

{"message":"Success","lat":(BLURD)"lng":(BLURD),"data":[{"Count":{"grass_pollen":0,"tree_pollen":246,"weed_pollen":1},"Risk":{"grass_pollen":"Low","tree_pollen":"High","weed_pollen":"Low"},"updatedAt":"2021-04-16T16:17:12.000Z"}]}
Tree pollen
High
Grass pollen
Low
Weed pollen
Low

Oke and now this.. Sorry. No visual on the overview

@michilehr

This comment has been minimized.

Copy link
Owner Author

@michilehr michilehr commented Apr 16, 2021

@huizebruin

This comment has been minimized.

Copy link

@huizebruin huizebruin commented May 4, 2021

i made with your file and a little help an dutch version with a little more information.
https://github.com/huizebruin/Home-Assistant-Config/blob/main/sensors/ambee-nl.yaml

ambee-hooikoort-homeassistant

@michilehr

This comment has been minimized.

Copy link
Owner Author

@michilehr michilehr commented May 5, 2021

@huizebruin: Great! Thanks for sharing! Didn't know about the secret usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment