Is_state versus state_attr(...., "state")

I have an entity where I can see the state and if I use is_state(, “value”) it works, but if I try to use state_attr(,“state”) or state_attr(, “State”), it returns none. I have also tried state.state, but that doesn’t work either.

What is the correct way to get the value for state of an entity?

states('entity_id')

Templating States Docs

You may also wan to check out the State Object docs to learn how the properties and attributes are structured.

I read the templating docs, but it wasn’t very helpful. When you say states(), do you mean I should use state_attr(,“states()”)?

{{ states('light.kitchen') }}

To get the value of a light entity’s brightness attribute:

{{ state_attr('light.kitchen', 'brightness') }}

EDIT

If you want to confirm that an entity’s state or attribute has a specific value:

{{ is_state('light.kitchen', 'on') }}
{{ is_state_attr('light.kitchen', 'brightness', 255) }}

I’m not sure that you’re understanding my question. I use

{{ state_attr(“climate.back_thermostat”,“current_temperature”) }}

to get the current temperature, but the other value I want (the mode) is only listed in the State column using the developer tools States tab. So I want to be able to do a state_attr that returns the value of that. I know I can use is_state, but I would like to understand how to get this value using state_attr.

I understood your original question and answered it. Use states() to get an entity’s state value, use state_attr() to get the value of an entity’s attribute. Two different functions for two different purposes.

You’re asking how to use state_attr() to get the value of an entity’s state. It’s not designed to do that.


Question for you:

Why do you want to use a function intended for getting the value of an entity’s attributes to get the value of an entity’s state?

The state is not an attribute, so you cannot get it using state_attr("entity_id", "attribute name"), you need to use states("entity_id")

That did it, thanks.

And as far as why, it’s easier to just report the state that add conditions and two different logs.