artem-sedykh / mini-climate-card

Minimalistic climate card for Home Assistant Lovelace UI
MIT License
262 stars 19 forks source link

How to display a sensor attribute in the indicators? #131

Closed roldengarm closed 10 months ago

roldengarm commented 11 months ago

I would like to display the last_updated property of a sensor under the indicators. As this is an attribute, I'm not sure how to do that? As the examples only show how to display entities. So e.g. the templated value would be: sensor.living_temp_sensor_temperature.last_updated

regevbr commented 11 months ago

Indicators allow setting the attribute of an entity it is listed in the config table (no examples though) can you share what will be the thoeritcal configuration you want to use so I can direct you better?

roldengarm commented 10 months ago

Thanks @regevbr So I've got a sensor with id "living_temp_sensor_temperature" which shows the temperature. I would like to show when it was last updated. This is useful as they are Zigbee wireless sensors and sometimes they no longer update.

When I display it in an entity row card it shows like this, so I'd like to add the "x minutes ago" to mini-climate-card

image

the YAML for above:

entity: sensor.living_room_temp_sensor_temperature
type: custom:multiple-entity-row
name: Living Room
secondary_info: last-changed
entities:
  - entity: sensor.living_room_temp_sensor_humidity
    name: humidity
  - entity: sensor.living_room_temp_sensor_battery
    name: battery

Does this answer your question? I really appreciate your support!

regevbr commented 10 months ago

Can you share your mini climate card config?

roldengarm commented 10 months ago

Sure! @regevbr

type: custom:mini-climate
entity: climate.living_ac
secondary_info:
  type: hvac-action
  hide: false
icon: mdi:heating-coil
indicators:
  battery:
    icon: mdi:battery
    unit: '%'
    round: 1
    source:
      entity: sensor.living_room_temp_sensor_battery
  humidity:
    icon: mdi:water
    unit: '%'
    round: 1
    source:
      entity: sensor.living_room_temp_sensor_humidity
regevbr commented 10 months ago
type: custom:mini-climate
entity: climate.living_ac
secondary_info:
  type: hvac-action
  hide: false
icon: mdi:heating-coil
indicators:
  battery:
    icon: mdi:battery
    unit: '%'
    round: 1
    source:
      entity: sensor.living_room_temp_sensor_battery
  humidity:
    icon: mdi:water
    unit: '%'
    round: 1
    source:
      entity: sensor.living_room_temp_sensor_humidity
  updated:
    source:
      entity: sensor.living_room_temp_sensor_temperature
      attribute: last_updated
roldengarm commented 10 months ago

Thanks @regevbr I tried that, but doesn't seem to work. It just shows empty. Any idea?

regevbr commented 10 months ago

Are you sure that it has an attribute called last_updated?

roldengarm commented 10 months ago

@regevbr pretty sure, please see below debugging template:

image

regevbr commented 10 months ago

please check in the developer tools on the entity itself. My guess is that it is not an attribute but a property of the entity. You can use a mapper instead see examples in the docs if that is the case

roldengarm commented 10 months ago

Thanks @regevbr I fixed it with a mapper indeed, like this:

  updated:
    icon: mdi:clock
    source:
      entity: sensor.living_room_temp_sensor_temperature
      mapper: |
        (value, entity, climate_entity, hvac_mode) => {                    
          const date = new Date(entity.last_changed);
          const minutes = Math.floor((new Date() - date) / 60000);
          return minutes + ' min ago';
        }