Ok, so this is where things get funky. You should familiarize yourself with home assistant state objects. This is what home assistant passes around when doing pretty much anything. These state objects contain 8 or so properties. Do not get these properties confused with the devices attributes.
These properties are:
Field | Description |
---|---|
state.state | String representation of the current state of the entity. Example off. |
state.entity_id | Entity ID. Format: .<object_id>. Example: light.kitchen. |
state.domain | Domain of the entity. Example: light. |
state.object_id | Object ID of entity. Example: kitchen. |
state.name | Name of the entity. Based on friendly_name attribute with fall back to object ID. Example: Kitchen Ceiling. |
state.last_updated | Time the state was written to the state machine. Note that writing the exact same state including attributes will not result in this field being updated. Example: 2017-10-28 08:13:36.715874+00:00. |
state.last_changed | Time the state changed. This is not updated when there are only updated attributes. Example: 2017-10-28 08:13:36.715874+00:00. |
state.attributes | A dictionary with extra attributes related to the current state. |
So whenever you use this function:
state_attr(entity_id, ‘attribute’), you are only getting items inside the state.attributes. When you look at the states page, you will only see things that are inside the state.attributes section. But ALL state objects in home assistant have the fields/properties that are listed above. And they are OUTSIDE the attributes field/property.
So how do you access them? Well the only way to access them is through the state object itself. There is no method that will get you these items.
{{ states.domain.object_id.<field> }}
So if you have a light, and it’s entity_id is light.living_room, access any of the properties outside the attributes (or state), would be:
{{ states.light.living_room.entity_id }} # for the entity_id 'light.living_room'
{{ states.light.living_room.domain }} # for the domain 'light'
{{ states.light.living_room.object_id }} # for the object_id 'living_room'
{{ states.light.living_room.name }} # for the friendly_name 'Living Room'
{{ states.light.living_room.last_updated }} # for the datetime object in UTC when it was last updated
{{ states.light.living_room.last_changed }} # for the datetime object in UTC when the state last changed
So you can kinda start to see how where we can access the state and attributes using that method too. You’ve probably seen this many times before without realizing it.
{{ states.light.living_room.state }} # for the state
{{ states.light.living_room.attributes.xxx }} # for the attribute 'xxx' if it exists