You were right, @VDRainer. I had the wrong sensor name. I’ve corrected it and tested it in the template editor, and it works. However, in the “Helpers” section, I’m getting an error because it says the result is a string. I’ve tried several options, but I still have this error
sensor:
- platform: template
sensors:
acumulador_energy:
friendly_name: "Energía Acumulada en Acumulador"
unit_of_measurement: "kWh"
value_template: >
{% set masa_agua_litros = 200 %}
{% set densidad_agua = 1 %}
{% set calor_especifico_agua = 4.186 %}
{% set temperatura_inicial_raw = states('sensor.contador_agua_temperatura_promedio_dia_anterior') %}
{% set temperatura_final_raw = states('sensor.esphome_web_7baa2c_acumulador') %}
{% set temperatura_inicial = temperatura_inicial_raw | float(0) %}
{% set temperatura_final = temperatura_final_raw | float(0) %}
{% set energia_acumulada = (masa_agua_litros * densidad_agua * calor_especifico_agua * (temperatura_final - temperatura_inicial) / 3600) | round(2) %}
{{ energia_acumulada | float if not temperatura_inicial_raw == 'unknown' and not temperatura_final_raw == 'unknown' else 0 }}