[homeassistant.components.sensor.template] UndefinedError:

Folks,
I do see during restart:
WARNING (MainThread) [homeassistant.components.sensor.template] UndefinedError: ‘None’ has no attribute ‘attributes’

But my sensos are clean. Can anybody find the bad guy?
`# sensor:

  • platform: yr
  • platform: dht
    sensor: DHT22
    pin: ‘22’
    monitored_conditions:
    • temperature
    • humidity
  • platform: time_date
    display_options:
    - ‘time’
    - ‘date’
  • platform: worldclock
    time_zone: Etc/UTC
    name: ‘UTC’
    #####################################################

Sensore for Slider adjusted start time

Needed:

input_slider.time_lamp_on_hour

input_slider.time_lamp_on_minute

#####################################################

  • platform: time_date
    display_options:
    - ‘time’
  • platform: template
    sensors:
    time_lamp_on:
    friendly_name: “LED Birne an um”
    value_template: “{{ ‘%0.02d:%0.02d’ | format(states.input_slider.time_lamp_on_hour | int, states.input_slider.time_lamp_on_minute | int) }}”
    sun_up:
    value_template: ‘{{ states.sun.sun.attributes.elevation > 0}}’
    friendly_name: ‘Sun is up’
    motion_bad:
    friendly_name: ‘Bad Motion Detector’
    value_template: >-
    {%- if is_state(“sensor.vision_zp3111_multisensor_4in1_burglar_5_10”, “0”) -%}
    No
    {%- else -%}
    Yes
    {%- endif -%}`

sensor.vision_zp3111_multisensor_4in1_burglar_5_10 right now is not in the system. Might this casues the issue?

Please use preformatted text. What you’ve posted is unreadable without it.

I have the same “issue” with some ZWave template sensors.
This seems to be caused by the template sensors being set up before all the referenced entities are ready.
Looking at your code, the sensor is trying to access states.sun.sun.attributes.elevation when states.sun.sun is still undefined (i.e. None).
It seems to be just a cosmetic issue, since - at least for me - my template sensors work as expected as soon as the referenced entities are “up”.
I think it’s safe to ignore this warning message.

Sebastian

See the advise #4 here:

The next two statements result in same value if state exists. The second one will result in an error if state does not exist.

{{ states('device_tracker.paulus') }}
{{ states.device_tracker.paulus.state }}

That only seems to work with actual states, but not for attributes, i.e.
{{ states.sun.sun.attributes.elevation }} returns the elevation value, while
{{ states('sun.sun.attributes.elevation') }} returns unknown.

Sebastian

Theo default filter should work then

I’d have to look into that - until now, seeing that Jinja syntax kept me away successfully :wink:
However, in this case the warning is triggered by trying to access a not (yet) existing entity.
Adding a default value would not change that - it only would make sure that a sensible value is returned.
It should be possible to suppress these warnings using an {% if %} clause as suggested here:

I think though, that inside the if-statement, you’d have to strip the “.attributes.<whatever>” part, since the base entity is still undefined.

I got the same error as before when I tried exactly the suggested statement and then gave up trying and decided to live with the warning message… :wink:
But stripping the attributes part should do the trick.

Sebastian