Hi all!
Some days ago installed PZEM-004t current sensor on my electricity input and another power sensor(SONOFF POW R2) on electric water heater.
Then, configured energy dashboard with PZEM as “Grid consumption” and SONOFF POW R2 as " Individual devices".
The third thing that i’ve made was a template energy sensor also added as individual device. The sensor is configured to substract the value consumed by a boiler from the total consumed energy:
This might be due to communication failures of one or both of the underlying sensors.
If they are unavailable your template becomes unknown and this is interpreted as a reset.
To avoid this add the availability attribute to your template-sensor and check, if the underlying sensors actually report a number.
You have three sensors in your state template, but only test for two in your availability template.
Also it iwould be easier to just test for number:
{{ not false in
[states('sensor.home_meter_grid_phase1_energy'),
states('sensor.home_meter_grid_phase2_energy'),
states('sensor.home_meter_grid_phase3_energy')]|map('is_number')
}}
No, I have exactly two sensors: mains and boiler, by the first instruction I am getting the previous value of the template sensor itself and maxing with the computed value (to get rid of the situations when the computed value is lower than the previous one).
But that is not enough unfortunately(
Not sure what your sensors deliver and what your template does, but know, that if ever a calculated state value is smaller then the one before, this will be interpreted as a reset, which could account for “weird statistics”.
Fixed this by returning zero value at the first second of midnight (21:00:00 on screenshot is local midnight here in Ukraine) with the following config
- name: "Other daily consumed energy (kWh)"
unique_id: other_daily_consumed_energy_kWh
device_class: energy
state_class: total_increasing
unit_of_measurement: 'kWh'
state: >-
{% set time = now() %}
{% if time.minute == 0 and time.hour == 0 and time.second == 0 %}
{{ 0.00 | float() }}
{% else %}
{% set previousValue = states('sensor.other_daily_consumed_energy_kWh') | float(0) %}
{% set currentValue = (states('sensor.mains_cutoff_total_daily_energy') | float(0)
- states('sensor.boiler_cutoff_total_daily_energy_kwh') | float(0)) | round(2) %}
{{ [previousValue, currentValue] | max }}
{% endif %}
availability: >-
{{ states('sensor.mains_cutoff_total_daily_energy') not in ['unknown', 'unavailable', 'none']
and states('sensor.boiler_cutoff_total_daily_energy_kwh') not in ['unknown', 'unavailable', 'none'] }}
attributes:
last_reset: '1970-01-01T00:00:00+00:00'