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.
An attribute has no unit in HA, sot here is nothing that the frontend can automatically deduce.
You have two options:
The entities card allows specifying a suffix for the attribute, so you can set the unit there.
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.
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.
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.