Last active
May 31, 2023 09:26
-
-
Save michilehr/7ce7431f97e82523336a120b50d0ebe2 to your computer and use it in GitHub Desktop.
Home Assistant Ambee Pollen API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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 %} |
@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);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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.