How to display on a gauge card the AQI information provided as integers in string format

Hello everyone.

My custom sensor sends an integer from 0 to 5 on a given topic every 5s, which represents the air quality index.
This is the subscription json message:
{
  "stat_t": "+ / + / BTtoMQTT / 0280E10000F5",
  "dev_cla": "aqi",
  "name": "Sensus191-gases_avg_aqi",
  "uniq_id": "0280E10000F5-gases_avg_aqi",
  "val_tpl": "{{value_json.gases_avg_aqi | is_defined}}",
  "state_class": "measurement",
  "device": {
    "identifiers": [
      "0280E10000F5"
    ],
    "connections": [
      [
        "mac",
        "0280E10000F5"
      ]
    ],
    "manufacturer": "ALGOL",
    "model": "Sensus191",
    "name": "PEMS",
    "via_device": "OpenMQTTGateway_ESP32_OLM_POE"
  }
}

I am currently viewing the AQI with a gauge card configured as follows:

type: gauge
entity: sensor.sensus191_gases_avg_aqi
name: AQI (From gaseous pollutants - Average value)
min: 1
max: 5
needle: true
severity:
   green: 1
   yellow: 3
   red: 4

What I would like is to display the classification string in the gauge card instead of (or with) the numeric value.
For example:
EXCELLENT when sensor.sensus191_gases_avg_aqi = 0
FINE when sensor.sensus191_gases_avg_aqi = 1
...
SEVERE when sensor.sensus191_gases_avg_aqi = 5

How could I do?

Thank you and greetings
Tommaso

Not an exact response to your question but I’m using the AirNow integration to get my AQI. I’ve got it displayed on my dashboard in the following way which uses the Lovelace Card Templater front end integration in HACS. The color bands match the bands used by AirNow and I set the description to what they provide. However, if I had to do it strictly on the sensor value the status information would be a series of templated if statements that provide the output string based upon the value.

type: custom:card-templater
entities:
  - sensor.airnow_aqi
card:
  type: gauge
  entity: sensor.airnow_aqi
  name_template: Status - {{ state_attr('sensor.airnow_aqi', 'description') }}
  needle: true
  unit: AQI
  min: 0
  max: 500
  segments:
    - from: 0
      color: rgba(0, 255, 0, .75)
    - from: 51
      color: rgba(255, 255, 0, .75)
    - from: 101
      color: rgba(255, 126, 0, .75)
    - from: 151
      color: rgba(255, 0, 0, .75)
    - from: 201
      color: rgba(143, 63, 151, .75)
    - from: 301
      color: rgba(126, 0, 35, .75)
5 Likes

Hi Andrew

Thanks a lot for the tip.
For the moment I have decided to add and send the description topic to my sensor, so that it can be displayed in the gauge card

Greetings