I’m trying to use a template to find if an attribute matches a particular string.
I can see how to get this to work except for nested values where after trying lots of different syntaxes I can’t get anything to work.
I’m trying to get an output of true, if the map name is “Kitchen-Lounge-Study”
but this gives an error
I’m well aware that the problem seems to be that is_state_attr doesn’t seem to recognise the “.name” part of the code, as this syntax works perfectly with any of the non-nested attributes above.
The whole quoted string last_loaded_map.name is taken as a first level attribute rather than interpreting it as a nested attribute. It expects one attribute and has not been coded to interpret multi-levels.
Sorry for asking you, but what is the different form your solution and these template (i just found these in another thread)? {{state_attr('vacuum.rockrobo', 'last_loaded_map').name == "Kitchen-Lounge-Study" }}
it is just for understanding because i’m a newbe in python Template
No difference. That format is also valid. There are some special cases where the square bracket notation has to be used though. e.g. in a restful sensor template with this resource:
“value” has a special meaning in this case in home assistant (the non json return of the restful resource) so you have use this format to get to the actual path:
Dot notation looks neater but there are situations where it cannot be used. Tom_I described the exception where the key name is value. Other exceptions (where bracket notation should be used) are:
When the key name begins with a number.
Use this: value_json["2021data"]
not this: value_json.2021data
There’s an example in the documentation for the case where the entity’s name begins with a number.
When the key name contains a space.
Use this: value_json["temperature data"]
not this: value_json.temperature data
There’s an example in the documentation at the bottom of this page.