Hello.
With the new Long term statistic data in HA i got confused on what sensors need to have LTS and how to make this.
For example, i have a daily energy sensor:
daily_energy_offpeak:
name: "Daily Energy Offpeak"
source: sensor.electricity_meter_energieverbruik_tarief_1
cycle: daily
daily_energy_peak:
name: "Daily Energy Peak"
source: sensor.electricity_meter_energieverbruik_tarief_2
cycle: daily
This sensor is having LTS with the following Attributes:
state_class: total_increasing
source: sensor.electricity_meter_energieverbruik_tarief_1
status: collecting
last_period: 32.785
last_valid_state: 18640.086
meter_period: daily
cron pattern: 0 0 * * *
last_reset: 2024-02-03T23:00:00.086648+00:00
unit_of_measurement: kWh
device_class: energy
icon: mdi:counter
friendly_name: Daily Energy Offpeak
I created a Template sensor to combine the 2 sensors (peak and offpeak) to make 1 total:
daily_energy:
friendly_name: "Daily Energy"
unit_of_measurement: "kWh"
value_template: "{{ states('sensor.daily_energy_offpeak')|float + states('sensor.daily_energy_peak')|float }}"
But this total ‘daily energy’ sensor has no LTS.
It’s Attributes:
unit_of_measurement: kWh
friendly_name: Daily Energy
I changed the Template to this:
daily_energy:
friendly_name: "Daily Energy"
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
value_template: "{{ states('sensor.daily_energy_offpeak')|float + states('sensor.daily_energy_peak')|float }}"
As described here: Sensor Entity | Home Assistant Developer Docs (home-assistant.io)
But this seems to do nothing, it does not keep LTS.
How can I make my sensor correct so that it keeps LTS? Do i have to do this in the Template or do i need to make a customization?
I also created a ‘yesterday_energy’ sensor with the same Templating:
yesterday_energy:
friendly_name: "Yesterday Energy"
unit_of_measurement: "kWh"
value_template: "{{ state_attr('sensor.daily_energy_offpeak','last_period')|float + state_attr('sensor.daily_energy_peak','last_period')|float }}"
With no LTS data