Use of state friendly name in template

Hello, sorry for probably a stupid question, but I must be missing something elemental…

How do I access state in template using friendly name ?

I have a sensor, shown in states as “sensor.0x00124b00239ddd94_humidity” entity, with friendly_name “cidl_sklep_humidity”.

I need to access it in template, trying it using the Template editor. It works ok this way:

{{ states("sensor.0x00124b00239ddd94_humidity") }}

results in some (expected) value:

58.2

But if try it using friendly name:

{{ states("cidl_sklep_humidity") }} 

I get:

unknown

Thanks for help…

is a state attribute of your sensor; if you want to access this:


{{ state_attr('sensor.0x00124b00239ddd94_humidity', 'friendly_name') }}

1 Like

Yes, that works, but that is not what I wanted to achieve. My concern was how to get the value while using just the friendly name, without using the “sensor.0x00124b00239ddd94_humidity” entity name (which could change if I e.g. replace the sensor, but keep using the same friendly name, I guess…)

This is not supported, you must use the entity id.

Sure but you can make the new entity_id match the old easily in one place (configuration/entities page). What you cant do (easily) is change the device_id. So avoid device automations and you will be fine.

I see, thanks for info.

1 Like