UndefinedError: 'None' has no attribute 'attributes'

Every time I reboot/restart HASS I get these warnings/errors. Everything seems to be working fine, so I assume these are not applicable. Is there a way to get rid of them? It’s making it hard to debug actual issue. I don’t have a clue where they are actually coming from. Any insight would be appreciated!

17-02-06 20:30:44 WARNING (MainThread) [homeassistant.components.sensor.template] UndefinedError: 'None' has no attribute 'attributes'
17-02-06 20:30:44 WARNING (MainThread) [homeassistant.components.sensor.template] UndefinedError: 'None' has no attribute 'attributes'
17-02-06 20:30:44 WARNING (MainThread) [homeassistant.components.sensor.template] UndefinedError: 'None' has no attribute 'attributes'
17-02-06 20:30:44 WARNING (MainThread) [homeassistant.components.sensor.template] UndefinedError: 'None' has no attribute 'attributes'
17-02-06 20:30:44 WARNING (MainThread) [homeassistant.components.sensor.template] UndefinedError: 'None' has no attribute 'attributes'
17-02-06 20:30:59 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'

Thanks!

Dan

2 Likes

I believe its just your template sensor starting before whatever it is linked to has a value. They should stop after everything initializes.

It does stop. Is there a way to eliminate the warnings though? I have no idea what’s actually throwing them.

Wrap the template attribute in an “if” statement that checks for the existence of the entity before rendering.

Like this:

value_template: '{% if states.remote.living_room.state %}{{ states.remote.living_room.attributes.current_activity }}{% endif %}'

9 Likes

How do I know which ones are throwing that warning? Or just wrap all of them like that?

You could do them one at a time, but the problem is that the sensors could load at different points in the bootstrap process so you don’t always see these errors all the time, or even with the same sensor. It’s easier just to wrap them all and make that your normal procedure for the future.

Or you can ignore them - since they don’t really signify an ‘error’ as much as a transient condition that’s quickly resolved.

1 Like

Cool, thanks. I know it’s not an error but it’s just annoying when I go looking for an actual error and the log is littered with those. I’ll just wrap them all and move on, appreciate it!

1 Like

Have a similar issue:

    sensors:
      last_motion:
        friendly_name: 'Last Motion'
        icon_template: 'mdi:motion-sensor'
        value_template: >
          {%- set pirs = [states.binary_sensor.kitchen_motion_sensor, states.binary_sensor.master_bedroom_motion_sensor, states.binary_sensor.master_closet_motion_sensor, states.binary_sensor.living_area_motion_sensor, states.binary_sensor.full_bath_motion_sensor, states.binary_sensor.half_bath_motion_sensor, states.binary_sensor.stairs_motion_sensor, states.binary_sensor.kids_room_motion_sensor, states.binary_sensor.play_room_motion_sensor] %}
          {% for pir in pirs %}
            {% if as_timestamp(pir.last_changed) == as_timestamp(pirs | map(attribute='last_changed') | max) %}
              {{ pir.name }}
            {% endif %}
          {% endfor %}```


I get this error: Error rendering template: UndefinedError: 'None' has no attribute 'last_changed'

Same problem…