Calculate cumulative total sensor from daily total sensor

i did it like this;
in my case when PV is off the sensor becomes unavailable. you can try with 0 as a value in your case.

create 2 input.number helpers: pv_today, pv_total and create automation on the sensor:

alias: pv_total
description: ''
trigger:
  - platform: state
    entity_id: sensor.solis_energy_today
condition:
  - condition: template
    value_template: >-
      {{ trigger.to_state.state in [trigger.from_state.state, 'unknown',
      'unavailable'] }}
action:
  - service: input_number.set_value
    target:
      entity_id: input_number.pv_total
    data:
      value: >-
        {{ states('input_number.pv_total') | float +
        states('input_number.pv_today') | float }}
  - service: input_number.set_value
    target:
      entity_id:
        - input_number.pv_today
    data:
      value: 0
mode: single

alias: pv_today
description: ''
trigger:
  - platform: state
    entity_id: sensor.solis_energy_today
condition:
  - condition: template
    value_template: >-
      {{ trigger.to_state.state not in [trigger.from_state.state, 'unknown',
      'unavailable'] }}
action:
  - service: input_number.set_value
    target:
      entity_id: input_number.pv_today
    data:
      value: '{{ states(''sensor.solis_energy_today'')  }}'
mode: single

then in config calculate the total kWh

sensor:
  - platform: template
    sensors:
      solis_energy_total_kwh:
        value_template: "{{ states('input_number.pv_today') | float + states('input_number.pv_total') | float }}"
        unit_of_measurement: 'kWh'

and customize sensor to fit into energy dashboard:

  customize:
    sensor.solis_energy_total_kwh:
      device_class: energy
      state_class: total_increasing
      last_reset: '1970-01-01T00:00:00+00:00'
1 Like