Use statistic value inside entity row

Hello there,

at the moment im struggeling with a task, where i want to display the values of last day, week, month, year. I’ve used the normal statistic card to display this:

image

type: statistic
period:
  calendar:
    period: day
    offset: -1
stat_type: change
entity: sensor.gaszaehler_value
name: Gestern

The problem is, i can just get this values with the statistic card and cant use it in any other card, i want this in an entity card.

For the current stats its simple, but dont know how to get the past values into a row.

For example, i want to to something like this where i get an entity row with the value of yesterday/ last week, last month, last year:

image

Is there any way to use the built in statistic values outside the standard statistic card?

Thanks for your input guys.

No there isn’t.

So then i have to create a trigger at 23:59 and Check If its sunday/last day of month or year and Set the last week/month/year value to the current value because at 00:00 its get resetted.

Is this the best blueprint for my goal ?

So my solution is now:

Two template binary sensors for last day of month / year.

  - binary_sensor:
      - name: Last Day of the Month
        icon: mdi:calendar
        state: "{{ (now() + timedelta(days=1)).day == 1 }}"
        
        
      - name: Last Day of the Year
        icon: mdi:calendar
        state: "{{ (now() + timedelta(days=1)).year == now().year + 1 }}"
            

And then i have created four automations who set the last day / week / month / year values:

alias: Verbrauchswerte - Vormonat sichern
description: Speichert die Vormonatswerte in die input felder
trigger:
  - platform: time
    at: "23:59:00"
condition:
  - condition: state
    entity_id: binary_sensor.last_day_of_the_month
    state: "on"
action:
  - service: input_number.set_value
    data_template:
      value: "{{ float(states('sensor.kaltwasser_monatlich')) }}"
    target:
      entity_id: input_number.kaltwasser_letztermonat
  - service: input_number.set_value
    data_template:
      value: "{{ float(states('sensor.warmwasser_monatlich')) }}"
    target:
      entity_id: input_number.warmwasser_letztermonat
  - service: input_number.set_value
    data_template:
      value: "{{ float(states('sensor.abwasser_monatlich')) }}"
    target:
      entity_id: input_number.abwasser_letztermonat
  - service: input_number.set_value
    data_template:
      value: "{{ float(states('sensor.kaltwasserpreis_monatlich')) }}"
    target:
      entity_id: input_number.kaltwasserpreis_letztermonat
  - service: input_number.set_value
    data_template:
      value: "{{ float(states('sensor.warmwasserpreis_monatlich')) }}"
    target:
      entity_id: input_number.warmwasserpreis_letztermonat
  - service: input_number.set_value
    data_template:
      value: "{{ float(states('sensor.abwasserpreis_monatlich')) }}"
    target:
      entity_id: input_number.abwasserpreis_letztermonat
mode: single

did this for each last day/ week / month / year with different conditions at 23:59.

Then i’ve the values inside my number helpers. In the multiple entity row the input field isnt show, so thats the value is displayed without the chance to change it - like its normal mode for input numbers as entity card.

In the example picture the values are the same cuz i’ve set them to current values. My values need to grow now.

How-to: make a statistics card look like an entity row

I was faced with the same challenge, but I didn’t want to create any additional template sensors or automations, because everything is already there - it just doesn’t look the way I want it to. So I helped it along with card-mod. Solution: a vertical stack consisting of a regular entities card followed by the necessary statistics cards.

Result:

To make the statistic card look like an entity row, I use the following CSS adjustments, which I add to each statistic card with card mod:

type: statistic
period:
  calendar:
    period: day
    offset: -1
stat_type: change
name: Gasverbrauch gestern
entity: sensor.heizung_heating_gas_consumption_today
icon: mdi:meter-gas
card_mod:
  style:
    .: |
      ha-card {    
        border: 0;
        background: none;
        display: grid !important;
        grid-template-columns: auto min-content;
        align-items: center;
        padding-top: 0px;
        padding-bottom: 16px;
      }  
      ha-card * {    
        font-size: inherit !important;
        font-weight: inherit !important;
      } 
      div.header {    
        flex-flow: row-reverse nowrap;
        justify-content: flex-end;
        padding-top:0;
        padding-right:0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      } 
      div.header .icon {    
        width:40px;
        height: 40px;
        text-align: center;
      } 
      div.header > .name {    
        margin-left: 16px;
        color: inherit;
      } 
      div.info {    
        margin-top: unset;
        padding: 0 16px 0 0;
        text-align: right;
      } 
      div.info > span.value, 
      div.info > span.measurement {    
        color: inherit;
        margin: 0;
      } 

The entity “Gasverbrauch heute” is duplicated to match the similarity. The upper entity is a regular entity row of the entities card and the lower entity is the customized statistic card. It also behaves in the same way as the entity row if there is not enough space available: the state is always displayed and, if necessary, the entity name is abbreviated with three dots. The only small disadvantage is that there is no secondary info row.

Note: this is not a full copy&paste solution as it requires HACS to install card-mod. Furthermore, you may not want to use card-mod for the first time to get the desired result, which may require further customization when using (other) themes. For this reason, I have saved myself the trouble of posting the complete card yaml, because there is nothing special there apart from the procedure described above. All the “magic” is done by card-mod.

Perhaps it will help someone who, like me, does not want to create any further templates or automations.