Seeking Assistance for Template Sensor Accuracy

Hi everyone, I’m currently working on setting up a template sensor to convert my pellet usage into gas measurements for my energy meter. While the basic setup seems to work, I’m encountering some issues where the sensor reports incorrect values, which messes up my energy calculations.

Here’s the state template I’m using:
{{ states(‘sensor.pellet_usage_today’) | float(default=0.0) | multiply(4.8) | round(1) }}

The problem arises when the sensor starts reporting values that don’t align with my actual usage. I’ve tried limiting the value, but that doesn’t solve the root issue of preventing erroneous jumps in the reported data. My workaround looks like this:
{% set x = (states(‘sensor.pellet_usage_today’) | float(default=0.0) | multiply(4.8) | round(1)) %} {{ ([0, x, 100]|sort)[1] }}

Unfortunately, this approach isn’t effective as it doesn’t address the underlying problem of sudden spikes or drops in the sensor readings. I’m wondering if there’s a more robust method to filter out these anomalies or if there’s a different approach altogether to ensure the sensor provides accurate and reliable data.

Any insights or suggestions would be greatly appreciated! Let’s collaborate to find a solution that keeps my energy calculations on track. Cheers, Nana