-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template error in Template Editor while it works fine as custom template sensor #71360
Comments
Same problem here:
Template sensor working fine, returning the entity_id of last called alexa media player. Developer tools return the error:
|
Also not working in mushroom template card anymore. I know, thats not HA/core! Just for info! |
Also not working ... |
Same Problem here... Version | core-2022.5.4 |
Same Issue with my RFS Fire Listings in Template & custom:mushroom-template-card ADVICE UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'type' |
Same issue here Home Assistant Core 2022.5.5 |
This can be solved by first checking if the attributes are defined for the entity. For instance:
Now you won't get this error anymore |
Well, it seems much better to do that, and it works!! However, the behaviour in the template editor and in the custom template sensor should be the same. |
I had to remove state_class defined & state_class measurement to show my iphone battery, but other than that it now works for me.
BATTERIES |
Same issue here running 2022.6 |
The issue it seems is that you need to check if the attribute actually “is defined” before you try & test it’s value. |
That is correct. See my code above. |
I don't see the bug in this issue report? The given template is iterating over all entities and tries to access the |
We agree that the behaviour may be correct. The issue, in my opinion, is that the template editor has a different behaviour than the template sensors.
If one of the entities doesn't have the specified attribute, the sensor will works fine (ignoring that entity and filtering the others), but the template editor will fail to render. In previous versions, both rendered without errors. Anyway, it is good to check if the attribute exists before using it for filtering. |
template documentation |
Hey there @PhracturedBlue, @tetienne, @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration ( |
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. |
This is still an issue on 2022.8.2. |
Why does this frontend error in the dev-tools templating section even exist? Every time trying to access Instead of forcing everyone over the world to add a pre-check if e. g. Came here because of
|
Still an issue in 2022.9.7 |
Still an issue in 2022.10.3 |
Still an issue in 2022.11.1 |
In my case, it gives a fatal error… |
Still an issue in version 2022.12.8 |
Why has this not been fixed? Developer tools is useless to test loops with "selectattr"! |
Still an issue in version 2023.1.1. |
Still exists. No one (able to fix) cares. New features more important. What a pity. |
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. |
Not stale |
Rather than just triage this ticket every month or so, is there a possibility that we could get some feedback from the developers please? I'm quite happy to keep bumping this every time it goes into the closed down phase, but it would be nice to know if anything can be be done to resolve this issue. |
The answer we keep getting is finger-pointing. Both think each other is wrong. So it remains broken. |
Seems like Frenck should step in and resolve this! |
Definitely Frenck is some kind of (well-known) HA super guru and I understand many are asking for him sooner or later - but his day probably has 24 hours only, too. There are many other skilled experts around too. I just don't get why this issue did not get any traction so far - because the impact on a productive use on a daily basis is not that massive maybe? |
I've tested some examples in Developer Tools without any issues. |
I think there's some conflation of issues.
Regarding (1):
@frenck gave the answer above and I believe it resolves that point. @smarthomejunkie's later response confirmed it, as did some other posts after that. Basically, you need to check if it's defined before accessing it:
Mind this though, to highlight the 2nd issue:
At this point I need to clarify my own comment: The use of templates should be consistent everywhere. Perhaps what's needed is for the original post to be updated, or a new one should be logged specifically for the second issue. I'm not sure what the core team's preference would be. I just want to clarify that I haven't tested this recently, so I'm not stating for a fact (2) is still an issue: I'm saying, if it is, then this issue should be cleaned up or a new one logged with the necessary info. Perhaps to ask directly: @pedolsky when you say you've tested with 2024.1.5, are you referring to (2)? |
The issue isn't that there is no workaround. The workaround has been discussed for a while. |
It's not a workaround. It's the equivalent of a null pointer in programming: you're dereferencing something that doesn't exist. I quoted Frenck and his answer is pretty clear. What more do you want? |
You are stating the obvious. Try understanding why so many people are saying this isn't fixed. |
I refer to (2); that was (is?) an absolutely annoying behaviour in Developer Tools. Tested it again with
which return 0 and with
which returns []. |
This is soooooooooo annoying, creating confusion everywhere and making the dev-tools section useless for many templates as you simply can not trust it ❗ |
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. |
Ping |
Pretty sure macros return objects and lists in the developer tools but strings in run-time usages. Very confusing for people who do not understand that the template editor in dev tools is a cousin, not a clone of the behaviour they will experience after they move their Jinja into a real-world situation. I spend considerable time helping people navigate the inconsistencies. |
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. |
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. |
What was the reason again this obviously technically can't be fixed? 66 comments and no idea why it's still open. |
The problem
I hope this is the right place to report this.
I use this code in a template sensor which works fine in that template sensor. However, when I use this code in the Developer Tools->Template Editor I get an error.
The code is:
{% set sensors = states.sensor
| selectattr('attributes.device_class', '==', 'battery')
| selectattr('attributes.state_class', '==', 'measurement')
| rejectattr('state', 'in', ['unavailable', 'unknown'])
| list %}
The error is:
UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'device_class'
What version of Home Assistant Core has the issue?
Core 2022.5.0
What was the last working version of Home Assistant Core?
core-2022.4.6
What type of installation are you running?
Home Assistant Supervised
Integration causing the issue
No response
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
Anything in the logs that might be useful for us?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: