-
-
Save michilehr/7ce7431f97e82523336a120b50d0ebe2 to your computer and use it in GitHub Desktop.
### 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 %} |
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
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.
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.
Did you signed up at the ambee site and got the api key from them?
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.
You might want to drop this in the HA community forum
I will write a tutorial later when I have some time.
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!
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 :)
it is failing on my dashboard..
{"message":"lat should be integer","data":[]}
Can somebody help me?
You need to replace LAT and LONG with your location data in line 8.
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
I have added a tutorial over here:
Feedback is very welcome :)
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
@huizebruin: Great! Thanks for sharing! Didn't know about the secret usage.
Thank you for this. Works perfectly! And I've extended it to pick up the air quality data from the Ambee API also, in the obvious way. This is all useful to have in a Home Assistant dashboard when the home in question has asthma sufferers in it.
This would be great to turn into a proper hass integration, but that's beyond my knowledge currently.
@steverumsby great! Feel free to fork it and add your extended version! A hass integration is on my list - but I don't have free time for this now.
i made a update for it.
https://github.com/huizebruin/Home-Assistant-Config/blob/main/sensors/ambee_pollen.yaml
Hi,
I'm getting this error in the server log "homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.ambee_pollen. State max length is 255 characters."
I suspect it's probably an error message being returned by Ambee, but I cant see what is being returned.
I've changed the Lat & Long .
I've added the API and can see the number of API calls going up on Ambee with every server restart.
I don't believe theres's anything wrong with the template section, as they are being created but the "State" is empty
Heres my config:
-
platform: rest
resource: https://api.ambeedata.com/latest/pollen/by-lat-lng?lat=...&lng=...
name: "Ambee Pollen"
scan_interval: 3600
headers:
content-type: "application/json"
x-api-key: "API has been added"
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') %}
ambee_pollen_weed:
icon_template: "mdi:nature"
friendly_name: "Weed"
value_template: >-
{% set state = state_attr('sensor.ambee_pollen', 'weed_pollen') %}
ambee_pollen_grass:
icon_template: "mdi:grass"
friendly_name: "Grass"
value_template: >-
{% set state = state_attr('sensor.ambee_pollen', 'grass_pollen') %}
ambee_pollen_last_updated:
icon_template: "mdi:clock"
friendly_name: "Last update"
device_class: timestamp
value_template:
"{{ state_attr('sensor.ambee.pollen', 'updatedAt') }}"
Thanks
@godfreym29 can you please paste the code via the "insert code" button :)
Thanks michilehr
Heres the offending code
I'm using a include_dir_merge_list as you suggested in your blog
### Ambee Pollen Count
- platform: rest
resource: https://api.ambeedata.com/latest/pollen/by-lat-lng?lat=52.651983&lng=0.779117
name: "Ambee Pollen"
scan_interval: 3600
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') %}
ambee_pollen_weed:
icon_template: "mdi:nature"
friendly_name: "Weed"
value_template: >-
{% set state = state_attr('sensor.ambee_pollen', 'weed_pollen') %}
ambee_pollen_grass:
icon_template: "mdi:grass"
friendly_name: "Grass"
value_template: >-
{% set state = state_attr('sensor.ambee_pollen', 'grass_pollen') %}
I've been updated it to get a lot more options.
I passed it on GitHub as well.
It's hase Dutch names. And information as well in dutch.
https://www.github.com/huizebruin/Home-Assistant-Config/tree/main/sensors%2Fambee_pollen.yaml
@godfreym29 you didn't output anything in your state.
Check out if this works
### Ambee Pollen Count
- platform: rest
resource: https://api.ambeedata.com/latest/pollen/by-lat-lng?lat=52.651983&lng=0.779117
name: "Ambee Pollen"
scan_interval: 3600
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: >-
{{ state_attr('sensor.ambee_pollen', 'tree_pollen') }}
ambee_pollen_weed:
icon_template: "mdi:nature"
friendly_name: "Weed"
value_template: >-
{{ state_attr('sensor.ambee_pollen', 'weed_pollen') }}
ambee_pollen_grass:
icon_template: "mdi:grass"
friendly_name: "Grass"
value_template: >-
{{ state_attr('sensor.ambee_pollen', 'grass_pollen') }}
@michilehr I've tried your suggestion but I'm still getting the same error in the log
File "/usr/src/homeassistant/homeassistant/core.py", line 906, in init raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.ambee_pollen. State max length is 255 characters.
@godfreym29 it is now integrated in Home Assistant
https://www.home-assistant.io/blog/2021/07/07/release-20217/#new-integrations
Hiiiiii! Can I ask if you know how to get this data in JS? For example, I would like to get the count of grass pollen like this
const grass_num = data.Count.grass_pollen
But I am having errors and I don't know how to deal with it 😭
{ "message": "success", "lat": 35.23373019999984, "lng": 129.07596150000015, "data": [ { "Count": { "grass_pollen": 46, "tree_pollen": 25, "weed_pollen": 18 }, "Risk": { "grass_pollen": "Moderate", "tree_pollen": "Low", "weed_pollen": "Low" }, "updatedAt": "2022-06-08T10:06:36.000Z" } ] }
Thank you for your time! Hope you will answer
@suyenish like this?
let res = '{ "message": "success", "lat": 35.23373019999984, "lng": 129.07596150000015, "data": [ { "Count": { "grass_pollen": 46, "tree_pollen": 25, "weed_pollen": 18 }, "Risk": { "grass_pollen": "Moderate", "tree_pollen": "Low", "weed_pollen": "Low" }, "updatedAt": "2022-06-08T10:06:36.000Z" } ] }';
let json = JSON.parse(res);
console.log('your data: ' + json.data[0].Count.grass_pollen);
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
JSONPath Expression
JSONPath Result