Get "Friendly" name of Zone for use in template sensor?

hi all. trying to add a little more detail to display both the activity and the zone name in a custom template sensor. For example, if the person is not in a zone (away), I want to know what they’re doing, such as driving, walking, etc. If they are in a zone, I want to display the zone name. But when doing this I get the ugly Zone name, not the zone as it appears when putting the person entity on the gui. Can someone please help me get the “Friendly” zone name for use in a template sensor?

(So far my code is this: - and on anther note, how the heck does one put script into a post on these forums? Reddit has a code tag at least, I don’t see something like that here. so i’m putting an image of the short script. wth.

{% if is_state('person.yyy_m','away') %}
  {% if is_state('sensor.yyy_s_mobile_detected_activity','in_vehicle') %}
    {% set val = 'Driving' %}
  {% else %}
    {% set val = states('person.yyy_m') %}
  {% endif %}
{% else %}
  {% set val = states('person.yyy_m') %}
{% endif %}
{{ val }}


Code tag is the </> button.

Or, you can just do three backticks above and below.

works! thanks! I don’t have the </> button but the backticks worked.

{{ val | title }} or {{ val | capitalize }}

Jinja Built-In Filters

Either will work for “home”, just keep in mind that non-home named zones will be altered too so use the one that matches your preferred format… i.e. “Grocery Store” vs. “Grocery store”.

Is there no native way to pull the actual zone name? capitalize won’t work in all cases - I work for a company, for instance, that the company name officially is a lower case first letter of the name, but Corporation is capitalized. Of course not essential for my personal display, but it feels like an artificial solution when we “should” be able to pull the actual value from the zone… ??

edit: I replied to your capitalize version, but I think title is also a function applied to a value, and doesn’t pull the actual value. I know the value exists in HA because it displays when showing the “person”…

Yes, the state of a person in a non-home named zone will be the friendly name of the zone… “home” and “not_home” are outliers as state values in this regard. Also, be aware that there are a number of entities in HA that have frontend representations that are related to, but do not exactly match, the values available in the state object.

So it sounds like you really just want to capitalize home

{{ val | title if val == 'home' else val }}

WHAT??? I’ve only worked on this at home, so … didn’t do my proper research I guess before asking the question. If this is true, then your solution is totally perfect, and huge thank you!! Will test this evening!

Sorry. Was working earlier when we did the code tag thing. Didn’t have a chance to test what I thought might work. But …
I think this is what you are after.

{{ state_attr('zone.' ~ val, 'friendly_name') }}

You can certainly use that in a set statement too.