Accessing/testing entity_category "property" in templates

In a template how do I find that an entity has an entity_category “property”?
How do I find it / test or filter for a category / print it?
By the way (stupid question?) what is an entity property?

see Device configuration URL and entity categories | Home Assistant Developer Docs

For example in one of my ESPHome component I have added ‘entity_category: diagnostic’ on one of my sensor and it is correctly reported as a diagnostic sensor but where is the information hidden

You can see this under Settings - Devices (or the device link of the integration):

your_homeassistant_url:8123/config/devices/dashboard

I don’t think there is currently a way to access this through the object properties. I tried this:

states.domain.object_id.entity_category

for a couple of entities that I know have this property defined but it showed nothing:

And generated this warning:

Template variable warning: 'homeassistant.helpers.template.TemplateState object' has no attribute 'entity_category' when rendering '{{ states.sensor.lawn_moisture_battery.entity_category }} {{ states.sensor.lawn_moisture_soil_moisture.entity_category }}'

I have opened a feature request to have this added. Vote for it here: Add the entity_category to the available state object properties

There are very few stupid questions and this isn’t one of them. Petro has a great post on object properties here:

1 Like

I did try exactly the same thing on one of my devices
{{ states.sensor.weather_power_cuisine.entity_category }}
I did not get any error, but I also did not get any value back.

Thanks for the feature request, I have voted for it :slight_smile:

I am in the process of exploring templating in detail and I have read in detail the state object page. Before reading the explanation from @petro (this guy seems to know everything about architecture and is a “god” in templating) I did not realize that field = property ! So in the documentation in some places field is used and in some other places property is used

So far I have been trying to avoid using the states.sensor.weather_power_cuisine kind of syntax as this is not recommended in the templating page but as @petro mention sometimes there is no other way around, for example for accessing last_updated field/property :
states.sensor.weather_power_cuisine.last_updated
and by using his trick
{% if states.sensor.weather_power_cuisine is defined %}
you can avoid error during startup time.

I think it would be nice to have a function like state_field('domain.object_id', 'field_name') that would return the value of the field for the specified entity.

And less important, but would be nice to have, iterators like state_fields('domain.object_id') and to be consistant state_attributes('domain.object_id') as well

Thanks again

1 Like

You can always open a feature request.