If you use jchh’s suggested template, it will eliminate the error message but your Template Sensor will report 22031 every time sensor.solaredge_lifetime_energy_kwh is unknown.
If that’s how you want the Template Sensor to behave, then fine. Otherwise, you may wish to consider using the availability option in order to skip computing a value whenever sensor.solaredge_lifetime_energy_kwh is unknown and report unavailable.
one more question
Long time ago i made this script
---
#
# Power Consumption Grid Negative only = Teruglevering
# Bereken Energie verbruik - Opbrengst Zonnepanelen = Netto Verbruik, show positive only dus alleen Teruglevering
#
sensor:
name: Power Consumption Grid (Neg)
unit_of_measurement: "W"
icon: "mdi:transmission-tower-export"
state: >-
{% set PowerConsumption = states('sensor.power_consumption_w') | float(0) %}
{% set SolarPower = states('sensor.solaredge_current_power') | float(0) %}
{% set PowerConsumptionGridNeg = (PowerConsumption - SolarPower) | int %}
{{ ( [-10000, PowerConsumptionGridNeg, 0] | sort ) [1] }}
But now i think i can also use this one instead, same results, looks more simple:
But i have no idea anymore what this dit: {{ ( [-10000, PowerConsumptionGridNeg, 0] | sort ) [1] }} changing the 10000 to something els wil result in thet given number instead of the 10000
My post was meant to make Ricks88 think about what value the Template Sensor should report when sensor.solaredge_lifetime_energy_kwh doesn’t have a numeric value.
Yes, it can report zero but that’s likely to skew the long-term results of a “Lifetime energy” sensor. Rick88 will need to decide what’s the best choice of value for his needs (unavailable, existing value, zero, or something else).
A time ago I reset my Solaredge, not so smart because it lost all data, the “22030” is the amount of kWh that was lost. So I created a new sensor that added the 22030 to the current kWh value of the Solaredge “lifetime energy”.
So not really sure what the best default value should be, maybe 22030, or 0, when Lifetime energy is loaded it will add the 22030 to the current amount by the lifetime energy sensor.