Parsing Pollen information from Deutscher Wetterdienst

Hi all,

I’m trying to parse the Pollen API from Deutscher Wetterdienst, which is openly available: https://opendata.dwd.de/climate_environment/health/alerts/s31fg.json

I’m getting an error with sensor.templates, so I must have done some formatting wrong:

  - platform: rest
    name: dwd_pollenflug
    scan_interval: 60
    resource: https://opendata.dwd.de/climate_environment/health/alerts/s31fg.json
    value_template: "{{value_json.content[16].partregion_name}}" 
    json_attributes:
      - content    
  - platform: template
    sensors:
      pollen_graeser:
        friendly_name: 'Graeser'
        entity_id: dwd_pollenflug
        value_template: '{{states.sensor.dwd_pollenflug.attributes.content[16].partregion_name}}'

Can somebody help me figure out what I’m doing wrong? The sensor.pollenflug shows the correct value for the same value_template.

First, if you’re getting errors, it’s helpful to post what they are because they often give clues to what is wrong.

Next, why do you have two sensors that give the same value? If these worked, it looks like they would both be extracting the same values.

It simply says, sensor.template is not properly configured without any details.

Yes, they would show the same value – this is for testing purposes. I want to get this running first before I parse actual values.

Oh, wait, I see the problem. entity_id should be sensor.dwd_pollenflug. (You’re missing the “sensor.” part.) Actually, you don’t even need entity_id, because it will figure it out automatically from the value_template.

This is the working configuration:

sensor:
  - platform: rest
    name: dwd_pollenflug
    scan_interval: 3600
    resource: https://opendata.dwd.de/climate_environment/health/alerts/s31fg.json
    value_template: "{{value_json.content[16].partregion_name}}" 
    json_attributes:
      - content    
  - platform: template
    sensors:
      pollen_graeser:
        friendly_name: 'Gräser'
        value_template: '{{states.sensor.dwd_pollenflug.attributes.content[16]["Pollen"]["Graeser"]["today"]}}'
      pollen_birke:
        friendly_name: 'Birke'
        value_template: '{{states.sensor.dwd_pollenflug.attributes.content[16]["Pollen"]["Birke"]["today"]}}'
      pollen_erle:
        friendly_name: 'Erle'
        value_template: '{{states.sensor.dwd_pollenflug.attributes.content[16]["Pollen"]["Erle"]["today"]}}'

You have to exchange the [16] for the id of your region. Take a look at the json raw file to find this out.

This is my working config for pollen from dwd. In my setup the files are split, so this is the “main”:

platform: template
sensors:
  pollen_121_graeser_today:
    friendly_name: 'Gräser Heute'
    value_template: >
      {{ states('sensor.pollen_121_graeser')
           |regex_findall_index("'today': '[-0-9]+'")
           |regex_findall_index("[-0-9]+")
           |regex_replace("-[-0-9]", ".5") }}
    entity_id:
     - sensor.pollen_121_graeser
  pollen_121_graeser_tomorrow:
    friendly_name: 'Gräser Morgen'
    value_template: >
      {{ states('sensor.pollen_121_graeser')
           |regex_findall_index("'tomorrow': '[-0-9]+'")
           |regex_findall_index("[-0-9]+")
           |regex_replace("-[-0-9]", ".5") }}
    entity_id:
     - sensor.pollen_121_graeser
  pollen_121_birke_today:
    friendly_name: 'Birke Heute'
    value_template: >
      {{ states('sensor.pollen_121_birke')
           |regex_findall_index("'today': '[-0-9]+'")
           |regex_findall_index("[-0-9]+") 
           |regex_replace("-[-0-9]", ".5") }}
    entity_id:
     - sensor.pollen_121_birke
  pollen_121_birke_tomorrow:
    friendly_name: 'Birke Morgen'
    value_template: >
      {{ states('sensor.pollen_121_birke')
           |regex_findall_index("'tomorrow': '[-0-9]+'")
           |regex_findall_index("[-0-9]+")
           |regex_replace("-[-0-9]", ".5") }}
    entity_id:
     - sensor.pollen_121_birke
  pollen_121_hasel_today:
    friendly_name: 'Hasel Heute'
    value_template: >
      {{ states('sensor.pollen_121_hasel')
           |regex_findall_index("'today': '[-0-9]+'")
           |regex_findall_index("[-0-9]+")
           |regex_replace("-[-0-9]", ".5") }}
    entity_id:
     - sensor.pollen_121_hasel
  pollen_121_hasel_tomorrow:
    friendly_name: 'Hasel Morgen'
    value_template: >
      {{ states('sensor.pollen_121_hasel')
           |regex_findall_index("'tomorrow': '[-0-9]+'")
           |regex_findall_index("[-0-9]+")
           |regex_replace("-[-0-9]", ".5") }}
    entity_id:
     - sensor.pollen_121_hasel

And this is one of the actual sensors:

platform: rest
scan_interval: 10800 
resource: https://opendata.dwd.de/climate_environment/health/alerts/s31fg.json
name: pollen_121_birke
value_template: '{% for region in value_json.content -%}{%- if region.partregion_id == 121 %}{{region.Pollen.Birke}}{% endif -%}{%- endfor %}'
json_attributes:
  - next_update

I also did change the values from dwd “1-2” into “1.5” so I can use gauges in lovelace.