Hello, i would like to create a custom enery sensor to count the correct energy.
“giorno_consumo_prese_pt” is a power meter that takes the all power on the lower flor but of course I have also dedicate energy power sensor which count the own consumption. I would like to remove those from the total but this is the error that i see later on the energy dashboard for the individual entity:
Assuming you got the unit wrong, and they are energy sensors, not power:
The sensor requires a valid state_class to be used in the energy dashboard.
You can not do this with legacy template sensors. You need to use the newer template integration.
You did not include the multi-line indicator ( >) in your template and you quoted a multi-line template (incorrect).
You also need an availability template or your sensor will generate weird spikes in the energy dashboard.
configuration.yaml (not sensors.yaml)
template:
- sensor:
- name: "giorno consumo prese pt updated"
state: >
{{ (states('sensor.giorno_consumo_prese_pt') | float - (
states('sensor.giorno_consumo_lavatrice_e_asciugatrice') | float +
states('sensor.giorno_consumo_presa_comandata') | float +
states('sensor.giorno_consumo_aspirapolvere') | float +
states('sensor.giorno_consumo_nouvelle_cuisine') | float )
) | round(2) }}
availability: >
{{ has_value('sensor.giorno_consumo_prese_pt') and
has_value('sensor.giorno_consumo_lavatrice_e_asciugatrice') and
has_value('sensor.giorno_consumo_presa_comandata') and
has_value('sensor.giorno_consumo_aspirapolvere') and
has_value('sensor.giorno_consumo_nouvelle_cuisine') }}
device_class: energy
state_class: total # or total_increasing
unit_of_measurement: kWh
If they are power sensors (kW) instead of energy sensors (kWh) then you are using the wrong sensors and need to use the energy sensors instead. If you dont have them then you need to make them with the Riemann Sum helper and use those in the template.
I confim it work only using “total_increasing” instead of “total” on configuration.yaml.
It is not really clear why i have to do it on configuration.yaml and cannot be done below custom_sensor folder or sensor.yaml.