bouwew
(Bouwe)
April 11, 2021, 6:46pm
8
I’d suggest adding an if-statement in another place, the error is caused by states.sensor.supervisor_updates.attributes.addons
.
I’ve just added the 2 lines, you can add the correct formatting yourself.
- type: markdown
title: Updates Available
content: |
<ha-icon icon="mdi:home-assistant"></ha-icon> Add-ons needing update: {{ states('sensor.supervisor_updates') | default(None) }}
if states('sensor.supervisor_updates') != None
> {% for addon in states.sensor.supervisor_updates.attributes.addons %}
> {{ addon.name }} {{ addon.version }} -> {{ addon.version_latest }}
> {% endfor %}
endif
Anwen
April 11, 2021, 7:02pm
9
Still not working. Card:
- type: markdown
title: Updates Available
content: |
<ha-icon icon="mdi:home-assistant"></ha-icon> Add-ons needing update: {{ states('sensor.supervisor_updates') | default(None) }}
{% if states('sensor.supervisor_updates') != None %}
> {% for addon in states.sensor.supervisor_updates.attributes.addons %}
> {{ addon.name }} {{ addon.version }} -> {{ addon.version_latest }}
> {% endfor %}
{% endif %}
Errors:
2021-04-11 14:51:15 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'None' has no attribute 'attributes' when rendering '<ha-icon icon="mdi:home-assistant"></ha-icon> Add-ons needing update: {{ states('sensor.supervisor_updates') | default(None) }}
> {% for addon in states.sensor.supervisor_updates.attributes.addons %}
> {{ addon.name }} {{ addon.version }} -> {{ addon.version_latest }}
> {% endfor %}'
2021-04-11 14:51:15 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'None' has no attribute 'attributes' when rendering '<ha-icon icon="mdi:home-assistant"></ha-icon> Add-ons needing update: {{ states('sensor.supervisor_updates') | default(None) }}
> {% for addon in states.sensor.supervisor_updates.attributes.addons %}
> {{ addon.name }} {{ addon.version }} -> {{ addon.version_latest }}
> {% endfor %}'
2021-04-11 14:51:15 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'None' has no attribute 'attributes' when rendering '<ha-icon icon="mdi:home-assistant"></ha-icon> Add-ons needing update: {{ states('sensor.supervisor_updates') | default(None) }}
> {% for addon in states.sensor.supervisor_updates.attributes.addons %}
> {{ addon.name }} {{ addon.version }} -> {{ addon.version_latest }}
> {% endfor %}'
2021-04-11 14:51:15 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'None' has no attribute 'attributes' when rendering '<ha-icon icon="mdi:home-assistant"></ha-icon> Add-ons needing update: {{ states('sensor.supervisor_updates') | default(None) }}
{% if states('sensor.supervisor_updates') != None %}
> {% for addon in states.sensor.supervisor_updates.attributes.addons %}
> {{ addon.name }} {{ addon.version }} -> {{ addon.version_latest }}
> {% endfor %}
{% endif %}'
2021-04-11 14:51:16 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'None' has no attribute 'attributes' when rendering '<ha-icon icon="mdi:home-assistant"></ha-icon> Add-ons needing update: {{ states('sensor.supervisor_updates') | default(None) }}
{% if states('sensor.supervisor_updates') != None %}
> {% for addon in states.sensor.supervisor_updates.attributes.addons %}
> {{ addon.name }} {{ addon.version }} -> {{ addon.version_latest }}
> {% endfor %}
{% endif %}'
petro
(Petro)
April 11, 2021, 8:20pm
10
access the attributes safely
state_attr('sensor.supervisor_updates', 'addons')
1 Like
Anwen
April 11, 2021, 10:28pm
11
Thank you so much, Petro, that’s fixed it! I still don’t understand why the if statements didn’t work,
but I will just accept I’m above my pay grade here, and keep on learning
For reference, if anyone comes across this and is interested, here’s my final working card that throws no errors on HA startup:
- type: markdown
title: Updates Available
card_mod:
style: |
:host {
--card-mod-icon-color: #42a5f5;
font-size: 1.1em;
}
content: |
<ha-icon icon="mdi:home-assistant"></ha-icon> Add-ons needing update: {{ states('sensor.supervisor_updates') | default }}
> {% for addon in state_attr('sensor.supervisor_updates', 'addons') %}
> {{ addon.name }} {{ addon.version }} -> {{ addon.version_latest }}
> {% endfor %}
<ha-icon icon="hacs:hacs"></ha-icon> HACS updates available: {{ states('sensor.hacs') | default }}
> {% for repo in state_attr('sensor.hacs', 'repositories') %}
> {{ repo.display_name }} {{ repo["installed_version"] }} -> {{ repo["available_version"] }}
> {% endfor %}
| | Current | | Latest |
|--- |:---: |:---: |:---: |
| **Supervisor** | {{ state_attr('sensor.supervisor_updates', 'current_version') }} | | {{ state_attr('sensor.supervisor_updates', 'newest_version') }} |
| **Audio** | {{ states.sensor.updater_audio.attributes.current_version }} | | {{ states.sensor.updater_audio.attributes.newest_version }} |
| **CLI** | {{ states.sensor.updater_cli.attributes.current_version }} | | {{ states.sensor.updater_cli.attributes.newest_version }} |
| **DNS** | {{ states.sensor.updater_dns.attributes.current_version }} | | {{ states.sensor.updater_dns.attributes.newest_version }} |
| **Multicast** | {{ states.sensor.updater_multicast.attributes.current_version }} | | {{ states.sensor.updater_multicast.attributes.newest_version }} |
| **Observer** | {{ states.sensor.updater_observer.attributes.current_version }} | | {{ states.sensor.updater_observer.attributes.newest_version }} |
which looks like this at the moment:
Edited to add: Sensors created with the help of this thread:
Update notifications! Core, HACS, Supervisor and Addons - Share your Projects! - Home Assistant Community (home-assistant.io)
Romquenin
(Romquenin)
August 15, 2021, 10:48pm
12
Hello everyone. I receive a template sensor error with a markdown card
Here is my code located in the decluttering_templates.yaml card:
summary:
card:
type: markdown
card_mod:
style: |
ha-card {
background: none;
box-shadow: none;
font-family: Quicksand;
margin-bottom: -0.9em;
text-align: center
}
content: |
{{ states("sensor.date_fr") | default }}, nous fêtons les {{ states("sensor.nameday_fr") | default }}
{{ states.sensor.summary.attributes.text }}
And here is the error:
Template variable error: ‘None’ has no attribute ‘attributes’ when rendering ‘{{ states(“sensor.date_fr”) | default }}, nous fêtons les {{ states(“sensor.nameday_fr”) | default }} {{ states.sensor.summary.attributes.text }}’
I hope someone can help me solve it.
Thanks.
koying
(Chris B)
August 16, 2021, 8:37am
13
Just from the message, it would seem sensor.summary
does not exist
Romquenin
(Romquenin)
August 16, 2021, 8:57am
14
The sensor exist with the text as attribute:
bschatzow
(Bill Schatzow)
October 16, 2021, 9:19am
15
I am now getting the following errors in the logs after the October update:
Template variable error: 'None' has no attribute 'attributes' when rendering '<ha-icon icon="mdi:home-assistant"></ha-icon> **Add-ons needing update:** {{ states.sensor.supervisor_updates.state }} > {% for addon in states.sensor.supervisor_updates.attributes.addons %} > {{ addon.name }} {{ addon.installed }} -> {{ addon.version }} > {% endfor %} <ha-icon icon="hacs:hacs"></ha-icon> **HACS updates available:** {{ states.sensor.hacs.state }} > {% for repo in states.sensor.hacs.attributes.repositories %} > **{{ repo.display_name }}** _{{ repo["installed_version"] }}_ -> _{{ repo["available_version"] }}_ > {% endfor %} --- | | Current | Latest | |--- |:---: |:---: | | **Supervisor** | {{ states.sensor.supervisor_updates.attributes.current_version }} | {{ states.sensor.supervisor_updates.attributes.newest_version }} |'
petro
(Petro)
October 16, 2021, 9:50am
16
Because you’re not using state_attr, you’re using the long form for getting attributes. That’s prone to issues when the entities don’t exist
bschatzow
(Bill Schatzow)
October 16, 2021, 9:53am
17
I see your answer above state_attr(‘sensor.supervisor_updates’, ‘addons’) but I am confused with the braces and bracket placement.
I have {% for addon in states.sensor.supervisor_updates.attributes.addons %}
does this change to {% for addon in state_attr(‘sensor.supervisor_updates’, ‘addons’) %}
?
petro
(Petro)
October 16, 2021, 10:17am
18
All you have to understand is that you should replace all instances of
states.abc.xyz.attributes.ijk
with
state_attr('abc.xyz', 'ijk')
bschatzow
(Bill Schatzow)
October 16, 2021, 10:44am
19
Thank you. I’m getting there!
What does   mean?
petro
(Petro)
October 16, 2021, 10:46am
20
Non breaking space
That’s html not templating
bschatzow
(Bill Schatzow)
October 16, 2021, 11:43am
21
Lots of different codes allowed in markdown cards. A lot to learn.
Got most of my warning (thanks to yours and 123’s help).errors cleared up.
Another one I see sometimes:
Logger: homeassistant.helpers.template
Source: helpers/template.py:1612
First occurred: 6:45:03 AM (32 occurrences)
Last logged: 6:45:03 AM
Template variable warning: 'dict object' has no attribute 'installed' when rendering '<ha-icon icon="mdi:home-assistant"></ha-icon> **Add-ons needing update:** {{ states.sensor.supervisor_updates.state }} > {% for addon in states.sensor.supervisor_updates.attributes.addons %} > {{ addon.name }} {{ addon.installed }} -> {{ addon.version }} > {% endfor %} <ha-icon icon="hacs:hacs"></ha-icon> **HACS updates available:** {{ states.sensor.hacs.state }} > {% for repo in states.sensor.hacs.attributes.repositories %} > **{{ repo.display_name }}** _{{ repo["installed_version"] }}_ -> _{{ repo["available_version"] }}_ > {% endfor %} --- | | Current | Latest | |--- |:---: |:---: | | **Supervisor** | {{ states.sensor.supervisor_updates.attributes.current_version }} | {{ states.sensor.supervisor_updates.attributes.newest_version }} |'
From a marked down card.
bschatzow
(Bill Schatzow)
October 19, 2021, 3:04pm
22
When I run the same code that you posted, mine shows Add-ons needing update: 16 this is all of the items, then it lists them all. Does this seem like my template is wrong or my markdown is wrong?
Anwen
October 19, 2021, 4:30pm
23
It seems like you either didn’t copy the markdown correctly, or your sensor is wrong. Do you have any addons needing an update (and which ones) if you look at the Supervisor dashboard? If you look in Developer Tools → States, what is the value of sensor.supervisor_updates
(including attributes)? Mine is currently 0 so there is nothing listed under the attribute addons
:
Markdown card:
My sensor is defined as
platform: command_line
name: Supervisor updates
command: 'curl http://supervisor/supervisor/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''{"newest_version":.data.version_latest,"current_version":.data.version,"update_available":.data.update_available,"addons":[.data.addons[] | select(.update_available)]}'''
value_template: "{{ value_json.addons | length }}"
unit_of_measurement: pending update(s)
json_attributes:
- update_available
- newest_version
- current_version
- addons
Hope that helps…
bschatzow
(Bill Schatzow)
October 19, 2021, 6:46pm
24
I was missing the update_available line. Not sure how I missed it. Thanks.
1 Like
bschatzow
(Bill Schatzow)
October 20, 2021, 12:08am
25
All of the top works great.
Anything after supervisor on the bottom fails.
Must be another template issue. Do you mind sharing yours?
| **Supervisor** | {{ state_attr('sensor.supervisor_updates', 'current_version') }} | | {{ state_attr('sensor.supervisor_updates', 'newest_version') }} |
Anything below cause the card to show just updates available.
| **Audio** | {{ states.sensor.updater_audio.attributes.current_version }} | | {{ states.sensor.updater_audio.attributes.newest_version }} |
| **CLI** | {{ states.sensor.updater_cli.attributes.current_version }} | | {{ states.sensor.updater_cli.attributes.newest_version }} |
| **DNS** | {{ states.sensor.updater_dns.attributes.current_version }} | | {{ states.sensor.updater_dns.attributes.newest_version }} |
| **Multicast** | {{ states.sensor.updater_multicast.attributes.current_version }} | | {{ states.sensor.updater_multicast.attributes.newest_version }} |
| **Observer** | {{ states.sensor.updater_observer.attributes.current_version }} | | {{ states.sensor.updater_observer.attributes.newest_version }} |
Anwen
October 20, 2021, 1:17am
26
All of those sensors can be found in this post - let me know if you still have an issue after you look at that.
bschatzow
(Bill Schatzow)
October 20, 2021, 1:29am
27
I just spotted my error. The sensor in the opening post was changed. I now found the correct ones. Hopefully I will have it corrected shortly. All working. Thanks for everyone’s help getting me through this.
1 Like