Open erkr opened 4 months ago
Your template seems fine to me in a markdown card:
Your template seems fine to me in a markdown card:
Thanks for verifying, but it only fails for entities where the device class is missing.
Yes I see what you mean. It seems markdown card subscribes its template with an additional argument strict: true
, and developer tools does not.
Related: https://github.com/home-assistant/frontend/pull/17824
So it seems that strict
mode for devtools was replaced with an option report_errors
, but report_errors
seems to catch less things than strict mode.
Perhaps that should be reported as a core bug, that report_errors should be able to report everything that strict mode would catch. I assume that was its intention but I don't know.
@karwosts Nice it seems your identifiers the source of this issue. But one remark. Rejectattr and selectattr should not raise errors when those attributes don't exist (to my knowledge)?! They will simply not be selected or rejected (like dev tools and template sensors). That is why I raised the issue here.
Rejectattr and selectattr should not raise errors when those attributes don't exist (to my knowledge)?! They will simply not be selected or rejected (like dev tools and template sensors).
My first experiments with selectattr / rejectattr were on 2021 - and on that time I learned that I must check for an attribute existence before using selectattr/rejectattr.
My first experiments with selectattr / rejectattr were on 2021 - and on that time I learned that I must check for an attribute existence before using selectattr/rejectattr.
I agree it is not very robust, But How to do that in filter expressions?! When I lookup a value with state_attr(), I have to check, but in a filter I want to include/exclude entities that match. I checked several places where I can execute templates (dev tools, template sensors, state switch card etc) and the same filtering works for all, except the markdown card.
Update: @ildar170975 thanks for your hint. This combo of filters works in the markdown as well:
selectattr('attributes.device_class', 'defined') |selectattr('attributes.device_class','eq','connectivity')
It complicates my full template, as I also want the entity's that don't have a device_class attribute (so need to merge two lists). But it's a workaround. Still hope the issue gets solved though.
Other simple example:
{% set entities = states | rejectattr('attributes.device_class','ne','connectivity')| map(attribute='entity_id') | list -%}
{{ entities }}
auto entities card works fine: Markdown card with the same template fails:
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
Bump
Checklist
Describe the issue you are experiencing
I have a simple template that filters on the 'device_class' attribute of an entity. That template works fine in e.g dev tools or as an template sensor, but fails in the markdown card for entities that don't have a 'device_class'.
Describe the behavior you expected
Template works the same as in Dev Tools or in the template integration. I also verified a number of other cards that support templates, and there it works fine. So it seems a markdown card specific issue.
Steps to reproduce the issue
What version of Home Assistant Core has the issue?
Core 2024.5.4
What was the last working version of Home Assistant Core?
No response
In which browser are you experiencing the issue with?
Chrome, Safari
Which operating system are you using to run this browser?
Win11 aan iOS 17
State of relevant entities
No response
Problem-relevant frontend configuration
No response
Javascript errors shown in your browser console/inspector
No response
Additional information
No response