Adding unit to attribute show on entity card in lovelace

Hi,

Anyone know if there is a possibility to add a unit of measurement to an attribute show on entities cards in lovelace?

I have an Entities card, which shows different utility meters, and I would like to show last_period attribute value from utility meter on it. It’s showing the correct value, but without unit.
I’ve tried: unit: , unit_of_measurement: but none of them works.
Alternativly, maybe attribute last_period from utility meter can be customized to add units there, but I cannot find any documentation how to customize an attribute. It looks like that customization corresponds to entity value only and not attributes.

There is how it looks like:
Skærmbillede 2022-10-16 104341

There is a part of code for this:

 - type: entities
    entities:
      - entity: sensor.pv_money_saved_today
        icon: mdi:currency-eur-off
        secondary_info: none
      - entity: sensor.grid_energy_cost_today
        icon: mdi:currency-eur
      - entity: sensor.pv_money_saved_today
        type: attribute
        attribute: last_period
        name: PV Money saved - Yesterday
        icon: mdi:currency-eur-off
        secondary_info: none
        unit: "DKK" ### not working###
1 Like

try

suffix: "DKK"

Entities Card - Home Assistant (home-assistant.io)

1 Like

That does nothing for me, even upon clicking “Save”.

I think here you need to use an attribute to show a suffix as documented here: Entities card - Home Assistant

type: entities
entities:
  - entitiy: sensor.wie_lang_zuletzt_geschalfen
    attribute: attribute_name_here
    icon: mdi:sleep
    secondary_info: none
    suffix: h

Hope that helps!

Am I supposed to enter the name of the actual unit attribute?
Either way, it doesn’t work.


As the unit is not shown as an attribute you may need to use something like ‘lovelace-template-entity-row’ from the HACS store. Information on how to install is here: GitHub - thomasloven/lovelace-template-entity-row: 🔹 Display whatever you want in an entities card row.

Then you could try something like:

entities:
  - type: 'custom:template-entity-row'
    entity: sensor.wie_lang_zuletzt_geschalfen
    state: |
      [[[
        return entity.state + ' h';
      ]]]
1 Like

Because you have not specified a proper 'type: attribute" here

Like this?


That just throws an error.

Because you specified an attribute - but forgot to specify an entity.

I’m confused. Does - entitiy: sensor.wie_lang_zuletzt_geschalfen not count as specifying an entity?

@beecho01
With the custom component it worked like this:

type: entities
entities:
  - type: 'custom:template-entity-row'
    entity: sensor.wie_lang_zuletzt_geschlafen
    state: "{{states('sensor.wie_lang_zuletzt_geschlafen')}} h"

Don’t know how to do the conversion though, as the time is shown as 6,81 h rather than 6:48 h.

It does count - but you did not specify an entity for THAT particular row.
Check this:


Every “-” describes a “row”:

  • 1st row - shows an entity’s state
  • 2nd row - shows an entity’s attribute