I believe this happens because the values are None when HA is started
Should there be a fix for it or is it okay to receive them?
any news for this problem? i have the same error
Ultimately I don’t know if there should be a fix but I have found that I receive these at startup and they do not cause any problems. My understanding is that this displays because the template (or maybe zwave?) hasn’t yet initialized. Once it has these errors stop and the template displays correctly in the UI.
They are initialization errors at startup and can be safely ignored unless they persist. They are caused by the fact that template sensors are initialized pretty quickly but if they rely on ZWave values, those may not be available for a minute or more as your ZWave network slowly initializes itself. In the meantime you may get hundreds of these errors. Annoying but not harmful.
For what it’s worth, it seems you can get rid of the warning WARNING:homeassistant.components.sensor.template:UndefinedError: 'None' has no attribute 'attributes'
. The templating doc here contains the following example:
{% if states.device_tracker.paulus %}
{{ states.device_tracker.paulus.attributes.battery }}
{% else %}
??
{% endif %}
I tried it myself by changing my value_template from
{{ states.binary_sensor.living_area_door_sensor_2.attributes.battery_level }}
to
{% if states.binary_sensor.living_area_door_sensor_2 %}
{{ states.binary_sensor.living_area_door_sensor_2.attributes.battery_level }}
{% else %}
n/a
{% endif %}
and so far, I’m not seeing the warnings anymore after restarting HASS.
Great find! Thanks for sharing! Now my log file is much cleaner
Definitely going to give that a try - thanks!
Noice! I thought I’d just have to live with these, which is a problem since I have so many templated sensors.
Thanks!
@fanaticDavid, Can I use in my configuration file while defining the sensor itself like below?
sensor:
- platform: template
sensors:
thermostat_downstairs_current_status:
value_template: '{{ states.climate.downstairs.attributes.operation }}'
thermostat_downstairs_current_status_fan:
value_template: '{{ states.climate.downstairs.attributes.fan }}'
thermostat_downstairs_away_mode:
value_template: '{{ states.climate.downstairs.attributes.away_mode }}'
Thanks
I’m sorry but I’m not quite understanding your question. I’m also not familiar with the climate component.
I know this thread is old, but it fits my question
I have a zwave
motion sensor that gives me several sensor nodes and a zwave.node_name
entity, that shows up in the front-end:
How can I access the battery level with a value template?
That would look something like this:
- platform: template
sensors:
hall_sensor_battery:
value_template: >-
{%- if states.zwave.hall_sensor_4 -%}
{{ states.zwave.hall_sensor_4.attributes.battery_level }}
{%- else -%}
n/a
{%- endif -%}
unit_of_measurement: '%'
entity_id: zwave.hall_sensor_4
Thank you for your very quick answer! It works
My pleasure
Wondering if anyone would know the answer to this, Prior to somewhere around release 0.39 or 0.40 when battery levels suddenly began to appear I was unable to get my Schlage zwave lock to show me a battery level through a template. I would get this message -> ‘Error rendering template: SecurityError: access to attribute ‘__32’ of ‘DomainStates’ object is unsafe.’
Release 0.39 or 0.40, I believe, began showing the battery levels and I didn’t need a template to have them show in the front end but with release 0.41 the battery levels disappeared again and I am back to having templates to show battery levels however just as prior to 0.39 I can not get my Schlage lock to show me a battery level.
Does anyone know of a solution to this message? -> Error rendering template: SecurityError: access to attribute ‘__32’ of ‘DomainStates’ object is unsafe. (zwave.__32 is the entitiy id of my lock, also I did set it up with a network key and it works as expected, just unable to show the battery level on the front end)
Thanks!
Try this for a template:
states.zwave["32"].attributes.battery_level
I tried this in the Dev Tools but received this error message -> “Error rendering template: TemplateSyntaxError: expected name or number”
{% if states.zwave.[“32”] %}
{{ states.zwave.[“32”].attributes.battery_level }}
{%- else -%}
n/a
{%- endif -%}
Since it’s a syntax error I am thinking it’s a typo or it doesn’t like the [“32”] for the name?
Remove the period between zwave and [“32”]. I didn’t put one there
Good catch, unfortunately that didn’t do it either. Sorry, one thing I failed to mention is that there is 2 underscores prior to the node number of 32 as shown below. If I do not use the underscores the message reads "Error rendering template: UndefinedError: ‘None’ has no attribute ‘attributes’.
“{{ states.zwave[”__32"].attributes.battery_level }}" in the Dev Tool the message it still displays -> “Error rendering template: SecurityError: access to attribute ‘__32’ of ‘DomainStates’ object is unsafe.”.