The Voice assistant reads up underscore in a sensor

Hi,

I have a an automation that´s read ups if an error occurs according to specific conditions. That´s works fine. The issue is that when it´s reads up the error from the sensor it also reads up the underscore.

I´m using:

{{states(‘sensor.roger_error’)}}

where the sensor consist of the error e.g. “collision_sensor_problem_front” however I would like it to be read out the friendly name which I see in e.g. History of the sensor which is “Front collision sensor problem”

How do I get that instead?

The “friendly name” is an attribute of the sensor.

{{ state_attr('sensor.roger_error', 'friendly_name') }}

Hi, thanks.

But it´s not the friendly name of the sensor itself I would like to have but the friendly name of the state of the sensor. How do I get that, or does´t that exist? But in that case how could I remove the underlines.

I don’t think states have friendly names. There are similar issues with weather forecasts, where there are a lot of hyphens which voice assistants stumble over. I use a template sensor to tidy them up:

  - sensor:
      - name: Weather voice
        unique_id: b8d54f34-1e67-4b4f-aed1-20e3f48ee81a
        state: >
          {% if is_state('weather.met_office_datahub', 'partlycloudy') %}
              partly cloudy
          {% elif is_state('weather.met_office_datahub', 'fog') %}
              foggy
          {% elif is_state('weather.met_office_datahub', 'clear-night') %}
              a clear night
          {% else %}
              {{ states('weather.met_office_datahub') | replace('-', ' ') }}
          {% endif %}
{{ states('sensor.roger_error').replace('_', ' ') }}

?

Edit:

Or

{{ state_attr('sensor.' ~ states('sensor.roger_error'), 'friendly_name') }}

Thanks that works