Templeate Sensor as a graph

I created a template sensor for the temperature of my bathroom climate component. Unfortunately it shows as states instead of a line graph. What am I doing wrong? The attribute current_temperature of the climate component shows correctly as a graph.

bathroom_temperature:
  value_template: "{{ state_attr('climate.thermostat_bath_room', 'current_temperature') | round(1) }}"
2 Likes
bathroom_temperature:
  value_template: "{{ state_attr('climate.thermostat_bath_room', 'current_temperature') | round(1) }}"
  unit_of_measurement: "°C"

Read the description here: https://www.home-assistant.io/components/template/#unit_of_measurement

5 Likes

I have been needing an answer to this for a longer time, and didn’t get to it, so am grateful you mention it.

Using a few of https://www.home-assistant.io/components/min_max/ myself, there’s no available unit_of_measurement, so I see the history of my lux sensor as you do:

59


  - platform: min_max
    entity_ids:
      - sensor.auditorium_motion_sensor_lux
      - sensor.dining_table_motion_sensor_lux
    type: mean
    name: Mean Living lux
    round_digits: 2

would this be a oversight for the integration then? seems strange one cant set the Uom on this sensor type

Ive tried it nonetheless, but the parser is unforgiving:

11

You should definitely request it support a unit of measurement.

ok, will do.
here we go again: would this be a feature request or a bug report…

here it is: https://github.com/home-assistant/home-assistant/issues/26133

there’s another detail though. I have 12 motion sensors reading the light, so to save on card space, only want the state (lx level) to be displayed, and dont need the UoM on all sensors to show Lx.

If I add the unit_of_measurement on these sensors, if automatically adds the unit on the card… would really love a way to not display that while having the recorder/history still show the values and not the discrete numbers as above… (of course this is for legacy HA not Lovelace)

adding a device_class only makes it change the icon, and not the display in more-info, as I already tried using eg device_class: illuminance

–update–

checking the source code for the min-max sensor, made me check the individual sensors, because they are checked for mutual consistency. I have not set the Uom on these sensors, and the min-max sensor doesnt error out in any way.

Setting the individual sensors to be unit_of_measurement: lx makes the min-max sensor display correctly in the more-info card.

still, would be nice to be able to set the uom on the min-max sensor, and be away with it.

It supports unit_of_measurement. Just add it.

no it doesn’t, I’ve tried and the result is displayed 3 posts above…

Okay, It looks like a bug then. It attempts to support it looking at the code for the min_max

from homeassistant.const import (
    CONF_NAME,
    STATE_UNKNOWN,
    STATE_UNAVAILABLE,
    CONF_TYPE,
    ATTR_UNIT_OF_MEASUREMENT,
)

Seems like they are missing it in voluptuous.

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {
        vol.Optional(CONF_TYPE, default=SENSOR_TYPES[ATTR_MAX_VALUE]): vol.All(
            cv.string, vol.In(SENSOR_TYPES.values())
        ),
        vol.Optional(CONF_NAME): cv.string,
        vol.Required(CONF_ENTITY_IDS): cv.entity_ids,
        vol.Optional(CONF_ROUND_DIGITS, default=2): vol.Coerce(int),
    }
)

Maybe they assumed that it comes from PLATFORM_SCHEMA but it doesn’t.

For the time being, just add it to customization and be done with it

as far as I’ve been able to test, it checks the individual entities to be of the same unit_of_measurement, and, if indeed set on the individual entities, inherits that uom.

if not set, it doesn’t error out, but it also doesnt inherit, and the min-max sensor is displayed with discrete values.

Ive filed an issue, asking to repair this

as I have already done on the individual sensors:

homeassistant:
  customize_glob:
    sensor.*_lux: #_motion_sensor
      icon: mdi:theme-light-dark
      templates:
        icon_color: >
          if (state < 1) return 'rgb(0,0,0)';
          if (state < 2) return 'rgb(51,0,0)'; 
          if (state < 10) return 'rgb(51,25,0)';
          if (state < 50) return 'rgb(102,51,0)';
          if (state < 150) return 'rgb(153,153,0)';
          if (state < 350) return 'rgb(102,204,0)';
          if (state < 700) return 'rgb(51,255,53)';
          if (state < 2000) return 'rgb(102,255,178)';
          if (state < 7000) return 'rgb(153,255,255)';
          return 'rgb(204, 255, 229)';
      unit_of_measurement: 'Lx'