'Weed' Issues :-)

Hi all,

See logbook details below:

Logger: homeassistant.helpers.template
Source: helpers/template.py:1862
First occurred: 15:45:57 (4122 occurrences)
Last logged: 21:31:57

* Template variable error: 'None' has no attribute 'Tree' when rendering '{{ state_attr("sensor.pollen_data", "Species").Tree.Plane }} /m³'
* Template variable error: 'None' has no attribute 'Weed' when rendering '{{ state_attr("sensor.pollen_data", "Species").Weed.Chenopod }} /m³'
* Template variable error: 'None' has no attribute 'Weed' when rendering '{{ state_attr("sensor.pollen_data", "Species").Weed.Mugwort }} /m³'
* Template variable error: 'None' has no attribute 'Weed' when rendering '{{ state_attr("sensor.pollen_data", "Species").Weed.Nettle }} /m³'
* Template variable error: 'None' has no attribute 'Weed' when rendering '{{ state_attr("sensor.pollen_data", "Species").Weed.Ragweed }} /m³'

There was something with float or something… finally wanna get rid of this issue… anyone got a clue ?

Codes as follows:

     pollen_onkruiden:
        friendly_name: Onkruiden
        icon_template: mdi:grass
        value_template: >-
          {% set state = state_attr("sensor.pollen_data", "Risk").weed_pollen %}
          {% if state == "Low" %} Weinig
          {% elif state == "Moderate"%} Matig
          {% elif state == "High"%} Hoog
          {% elif state == "Very High"%} Zeer hoog
          {% else %}Onbekend{% endif %}
        attribute_templates:
          Totaal: >-
            {{ state_attr("sensor.pollen_data", "Count").weed_pollen }} /m³
          Amaranten/Ganzenvoet: >-
            {{ state_attr("sensor.pollen_data", "Species").Weed.Chenopod }} /m³
          Bijvoet: >-
            {{ state_attr("sensor.pollen_data", "Species").Weed.Mugwort }} /m³
          Brandnetel: >-
            {{ state_attr("sensor.pollen_data", "Species").Weed.Nettle }} /m³
          Ambrosia: >-
            {{ state_attr("sensor.pollen_data", "Species").Weed.Ragweed }} /m³
 

Thx in advance,

Kr,

Bart

The error probably occur when you restart HA and it is because the values you have in your code have not been defined yet, when you use them first time.
With HA 2021.10 this returns an error.

You need to define defaults for your values.
Petro made a good post about it here:

1 Like

I suggest you define an availability_template to confirm sensor.pollen_data exists. If the sensor doesn’t exist, value_template and attribute_templates won’t be evaluated thereby avoiding error messages.

        availability_template: "{{ states('sensor.pollen_data') != none }}"

FWIW, the issue you are experiencing is not due to the requirement for defining default values. Your template doesn’t use any of the functions that require declaring a default value.