Possible to return the 'friendly' name that lovelace displays instead of the raw entity state?

Hi all, I’ve been googling this one for far too long.

I am automating some notifications, and was wondering if there is a simple way to return the more ‘friendly’ status of an entity that Lovelace displays when an entity is part of a domain?

For example I would like to have the template read out ‘open’ instead ‘on’ when I output {{ states('sensor.door') }}

I know I could manually do this using replace in YAML (somehow) but was thinking there might be a way to directly call the lovelace display name instead that I’m just not aware of.

Thanks in advance!!

It would be helpful if you could prove the (properly formatted) code for what you have so far for what you are trying to achieve.

Apologies. Here’s a bit more detail.

I have an automation that results in the following action.

service: notify.signal 
  message: >-
    The door is {{ states('sensor.front_door') }}.

Because the value of {{ states('sensor.front_door') }} is always either ‘on’ or ‘off’ it results in a message that just says “The door is on.” Which obviously isn’t very intuitive.

However, on my Lovelace dashboard, that same sensor displays as “open” instead of on, because it is part of the “opening” domain and it knows that ‘on’ means ‘open’.

In a nutshell, what I am hoping for is a way to make my notification say “The door is open” instead of “The door is on.”

Well, that’s not really “properly formatted” but I’ll give it a whirl…

service: notify.signal
  message: >
    The door is {% 'open' if states(‘sensor.front_door’) == 'on' else 'closed' %}.

BTW, the way tgo properly format the code snippets is to put three backticks (```) on the line both before and after the code block.

Thank you. I did fix the code block. Thanks.

To take this a step further, say for instance I had a sensor sensor.moon that could be any of the following states

new_moon, waxing_crescent, first_quarter, waxing_gibbous, full_moon, waning_gibbous, last_quarter or waning_crescent

Those aren’t very nicely formatted for output. Again, on the dashboard it displays them nicely as “New Moon” instead of “new_moon”, for example.

If I wanted to output the state of sensor.moon formatted as “New Moon” would my best option be to further extrapolate your suggested template by using 12 different elseif statements?

In that case you can create a dictionary of conversions:

{% set mapper = {
              'new_moon':'New Moon',
              'waxing_crescent':'Waxing Crescent',
              'first_quarter':'First Quarter',
              'waxing_gibbous':'Waxing Gibbous',
              'waning_crescent':'Waning Crescent' } %}
{% set sensor_state = states('sensor.moon') %}
the moon phase is {{ mapper[sensor_state] }}

I’ve never seen anyone come back over 7 months since the thread was solved to finally mark the solution. :laughing: that’s a long time!

but you’re welcome! :laughing: