Unit not shown at attributes of entities

I’m using a sensor to measure the daily energy comsumption. This sensor has an attribute “last_period”.
In lovelace, I want both elements to show the unit “kWh”, but for the attribute, it doesn’t work.

type: horizontal-stack
title: Power Consumption daily
cards:
  - type: entities
    title: Today
    show_header_toggle: false
    state_color: true
    entities:
      - entity: sensor.daily_energy_pool_tag
        name: Power
  - type: entities
    title: Yesterday
    show_header_toggle: false
    state_color: true
    entities:
      - type: attribute
        entity: sensor.daily_energy_pool_tag
        attribute: last_period
        name: Day
        unit: Power

This is the lovelace card:
grafik

The attribute “last_period” does not show the unit in the lovelace card!

Has anybody similar experiences? Am I doing something wrong? Any hint is appreciated - thanks!

An attribute has no unit in HA, sot here is nothing that the frontend can automatically deduce.

You have two options:

  1. The entities card allows specifying a suffix for the attribute, so you can set the unit there.
  2. Create a template entity for the attribute and specify the unit there.

Option 1 is fastest if you only need it once for this card. If you want to display the same attribute in different cards and not specify the suffix each and every time, when option 2 might make sense.

1 Like

Good point - thanks! But an attribute does hava a unit as following example shows:

type: horizontal-stack
title: Power Consumption daily
cards:
  - type: entities
    entities:
      - type: attribute
        entity: sensor.daily_energy_pool_tag
        attribute: last_period
        name: Day
        unit: kWh
  - type: entity
    entity: sensor.daily_energy_pool_tag
    attribute: last_period
    name: Day
    unit: kWh

grafik

  • In the the “entities” list (left element), the attribute is not shown
  • As a separate entity (right element), the unit is shown.

I think, it is a bug in the entities list - I will open an issue in GitHub

Where is the example from? Either way, I wouldn’t call it a bug, but a feature request. unit is not documented as it is not supported currently for an attribute row.

Unit does show in the documentation for Entity Card. However I agree with the OP, it does not work.
Ref: Entity Card - Home Assistant

However, the suffix label does work as documented here:

In your screenshot, only the right card is an “entity” card which indeed has a unit. But the left one is an “Entities” card, which allows you to show attributes directly, but does not support units.

So I’d still say that this is not a bug and the docs are correct here.