Lovelace UI - Gauge Card: Add attribute variable

Hello,
I’ve a boiler with “domestic hot water” sensor that exposes different attribute, such as:

  • current_temperature: show the current temperature
  • operation_mode: set to off or auto (show me if the boiler provider or not the hot water)
  • min_temperature: the minimal temperature setting
  • max_temperature: the maximum temperature setting

as so on…

I would create a gauge card related the current temperature for this sensor, but if I insert it into a card of type gauge, the UI show me an error related the impossibility to convert the sensor into numeric value.
This, because I cannot select the attribute related the sensor.

My idea is to create a gauge card with “current_temperature” attribute as the value, and the min and max temperature as the threshold.
In this case, I can select as a min and max value as an attribute of the entity? If not, it’s possible to develop also this part?

Meanwhile, I’m now forced, to create a entity type card, selecting the sensor with the attribute set on current_temperature. But this is only an entity type card.

+1. I am surprised this feature request didn’t get lots of attention and so far was not implemented (as of Nov 2022). Would be really nice to use state attributes in gauge cards.

For example, for different weather states (temperature, humidity, wind, etc.)

Entity:
weather.home_assistant_hourly
State:
sunny
State attributes:
temperature: 72
temperature_unit: °F
humidity: 44
pressure: 30.27
pressure_unit: inHg
wind_bearing: 325.6
wind_speed: 6.96
wind_speed_unit: mph
visibility_unit: mi
precipitation_unit: in

As a workaround, I had to create new sensors from state attributes using platform template and then use them in gauge card, which is not ideal but works.

configuration.yaml:
sensor: !include sensors.yaml

sensors.yaml

- platform: template
  sensors: 
    weather_outside_humidity: 
      friendly_name: 'Outside Humidity' 
      unit_of_measurement: '%'
      value_template: >-
        {{ state_attr('weather.home_assistant_hourly', 'humidity') }}
    weather_outside_temperature: 
      friendly_name: 'Outside Temperature' 
      unit_of_measurement: 'F'
      value_template: >-
        {{ state_attr('weather.home_assistant_hourly', 'temperature') }}
    weather_outside_pressure: 
      friendly_name: 'Outside Pressure' 
      unit_of_measurement: 'inHg'
      value_template: >-
        {{ state_attr('weather.home_assistant_hourly', 'pressure') }}
    weather_outside_wind_speed: 
      friendly_name: 'Outside Wind Speed' 
      unit_of_measurement: 'mph'
      value_template: >-
        {{ state_attr('weather.home_assistant_hourly', 'wind_speed') }}

lovelace (code editor):

type: horizontal-stack
cards:
  - type: gauge
    entity: sensor.weather_outside_temperature
    needle: true
    severity:
      green: 32
      yellow: 85
      red: 100
    max: 150
    name: Temperature
  - type: gauge
    entity: sensor.weather_outside_humidity
    max: 100
    needle: true
    severity:
      green: 30
      yellow: 10
      red: 70
    name: Humidity
  - type: gauge
    entity: sensor.weather_outside_pressure
    needle: true
    min: 28
    max: 32
    severity:
      green: 29.8
      yellow: 30.2
      red: 0
    name: Pressure
  - type: gauge
    entity: sensor.weather_outside_wind_speed
    name: Wind
    needle: true
    severity:
      green: 1
      yellow: 39
      red: 73
    max: 120

Screenshot:
image

I agree, in general, it seems like anyplace you can use an entity value you ought to be able to use an attribute value. So yes, it would be great to have gauges support attributes.

Creating individual entities for each attribute works, but it sort of defeats one of the niceties of having all the data for a given sensor wrapped up in one nice package. Now I have to create and manage “fake” entities for each attribute, which is one more level of indirection to deal with.

2 Likes