Pollen-Sensor (Austria) - json_attributes

Hi Rene!

Let’s stay in english - since this is an international forum.
To be honest - that’s not very special. Just put the configuration from above somewhere in your config-file and you’re good to go.

Take the config from the second post. Do you get any error messages in your HA logfile about the rest-sensors?

Cheers mate

Hi

it tried to add your code from the 2nd post in my configuration.yaml (as Sensor), restarted HA but I don’t get any data from polleninformation.at
I didn’t change something (also the coordinates still yours). Do I have to change something more?
Can you please help me?

Thanks
Markus

In the meanwhile I could solve this by my self.
It wat was a user error, i was looking at a attribute that is not active now.

Now I’m looking for a solution to get a overall number for the actual day, like on the homepage.
Can some one help me with this?
Is this also in the answer from the homepage? Do i hace tho calculate it?

Please some support
Thanke
Markus

I’m not sure what do you mean. What kind of number do you expect?

thx Florian

Thank you for asking.

I am referring to the key figure (allergy risk) that is displayed at the top of https://www.polleninformation.at/.
I am not sure whether it is a rounded average or the maximum value of all allergy substances.

Maybe I can calculate it yourself with a template sensor. Unfortunately, I’m not that good at it.

I would like to display this key figure in a dashboard and then open the detailed view by clicking on it.

We are all allergy sufferers in my household, so the information would be very interesting.

Thank you very much
Markus

Hi Markus,

unfortunately I can not answer that yet - since I don’t know how this value (i guess you mean this one? →

) is calculated. Unfortunately currently I do not have the time to install a intercepting-proxy to check.

Maybe I’ll have time later on.

sorry mate :frowning:

Cheers Flo

I’m not entirely certain if this is the correct value, but I am assuming it is. Below is the additional rest-template sensor that can be used to retrieve the forecast data.

If my interpretation is correct, this should display the daily average of the allergy risk.

- name: pollen_report_klagenfurt_dayrisk
  unique_id: 'e0279661-35cc-43ae-931b-8d7af59b8e80'
  resource: 'https://www.polleninformation.at/index.php?eID=appinterface&pure_json=1&lang_code=de&lang_id=0&action=getFullContaminationData&type=gps&value[latitude]=46.628&value[longitude]=14.309&country_id=1&personal_contamination=false&sensitivity=0&country=AT&sessionid='
  platform: rest
  icon: mdi:flower-pollen-outline
  scan_interval: 600
  value_template: >
    {% set dayrisk = value_json.result.additionalForecastData[0].dayrisk %}
    {% if dayrisk == 0 %} Keine
    {% elif dayrisk == 1 %} Niedrig
    {% elif dayrisk == 2 %} Mittel
    {% elif dayrisk == 3 %} Hoch
    {% else %} Unbekannt
    {% endif %}
  json_attributes_path: "$.result.additionalForecastData[0]"
  json_attributes:
    - dayrisk
    - air_quality
    - asthma_weather
    - ozone
    - particulate_matter
    - sulphur_dioxide
    - nitrogen_dioxide

this will result in:

Cheers Flo

There is also this data in the Json

    "hourlyLoadData": {
      "total": [3, 3, 3, 3],
      "dayrisk_personalized": false,
      "hourly": [
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3],
        [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3],
        [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
        [3, 3, 1, 1, 1, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
      ]
    },

which I interpret as hourly allergy risk. The correct rest-sensor to fetch this data would be

- platform: rest
  name: "pollen_data_klagenfurt"
  unique_id: '648d2575-31af-455d-9866-bcfafd68d892'
  icon: mdi:flower-pollen-outline
  resource: "https://www.polleninformation.at/index.php?eID=appinterface&pure_json=1&lang_code=de&lang_id=0&action=getFullContaminationData&type=gps&value[latitude]=46.628&value[longitude]=14.309&country_id=1&personal_contamination=false&sensitivity=0&country=AT&sessionid="
  method: GET
  scan_interval: 600
  value_template: "{{ value_json.success }}"
  json_attributes_path: "$.result.hourlyLoadData"
  json_attributes:
    - hourly

also you would need an template sensor to interpret this data for homeassistant

- platform: template
  sensors:
    pollen_risk_current_hour:
      friendly_name: "Pollenrisiko Aktuelle Stunde"
      value_template: >
        {% set current_hour = now().hour %}
        {% set hourly_risks = state_attr('sensor.pollen_data_klagenfurt', 'hourly') %}
        {% if hourly_risks is not none and current_hour < hourly_risks[0] | length %}
          {{ hourly_risks[0][current_hour] }}
        {% else %}
          unknown
        {% endif %}
      icon_template: "mdi:flower-pollen"

pps: this is my updated pollen-auto-entities-card:

type: custom:auto-entities
card:
  square: false
  type: grid
  columns: 1
card_param: cards
filter:
  include:
    - entity_id: "*pollen_report*"
      options:
        type: custom:mushroom-template-card
        primary: "{{ state_attr(config.entity, 'poll_title') }}"
        secondary: "{{ states(config.entity) }}"
        icon: mdi:flower-pollen-outline
        tap_action: none
        icon_color: |
          {% set contamination = state_attr(config.entity, 'contamination_2') %}
          {% if contamination == 4 %}
            red
          {% elif contamination == 3 %}
            orange
          {% elif contamination in [2, 1] %}
            yellow
          {% else %}
            default
          {% endif %}
  exclude:
    - state: unknown
    - state: Keine
    - entity_id: sensor.pollen_report_hourly_klagenfurt
    - entity_id: sensor.pollen_report_dayrisk_klagenfurt
sort:
  method: attribute
  attribute: contamination_2
  reverse: true

Hello Flo

that was exactly what I meant. Thank you for being able to implement it so quickly.

I have implemented your code and get a value for Dayrisk with your coordinates. However, if I set the coordinates to my home town (also the nearest large city - Graz) I get the, actually invalid, value 5 back.

The individual pollen values are read out correctly with my coordinates.

Do you have any idea why this could be?

Thanks again for the quick implementation
Markus

sure you put in the correct URL?

if I put this into the url instead of mine for Klagenfurt

https://www.polleninformation.at/index.php?eID=appinterface&pure_json=1&lang_code=de&lang_id=0&action=getFullContaminationData&type=gps&value[latitude]=47.073&value[longitude]=15.400&country_id=1&personal_contamination=false&sensitivity=0&country=AT&sessionid=

it produces valid data for Graz …

PS: I’m not sure if this is even available for each and every city. I guess it’s maybe just for capitals?

I dunno

Cheers

Yes, the individual pollen seem to provide valid data.

The Dayrisk value is somewhat peculiar. Perhaps it is not rated from 0-4 as on the homepage, but goes up to 10.
In the forcast for Graz I see values up to 9.

I think I will simply adapt your code accordingly.

Thanks also for the rest of the new code. Let’s see how I can process it further :smiley:

Thanks
Markus