Hello everyone,
i’ve got a Weishaupt heat pump for which i use the Modus integration. Unfortunately, Weishaupt is hiding the most interesting information from the Modbus registers (this would be current elektrical input power, current thermal output). To be able to calculate those, I planned to use the provided statistics register which integrate the consumed electrical power for day, month and year. My aim is to create a template sensor which provides the used electrical energy for heating, hot water, defrosting and others. While masking the corresponding machine states, was easy, I do not succeed in calculating the differential sensor values.
The masking from the heatpump states works, looks like this:
Now, i want to calculate the delta values.
My state code looks like this (example for masked “Heating Energy”):
{% if states('sensor.wh_warmepumpe_betrieb') == 'heatpump_operationmode_heating' %}
{% if last == 0 %}
{% set last = states('sensor.wh_statistik_elektr_energie_jahr') | int %}
{{ 0 }}
{% else %}
{% set result = ((states('sensor.wh_statistik_elektr_energie_jahr') | int) - last) %}
{% set last = states('sensor.wh_statistik_elektr_energie_jahr') | int %}
{{ result }}
{% endif %}
{% else %}
{{ 0 }}
{% endif %}
This leads to an error since ‘last’ is not available before declaration. I basically need a method to pass a value to the next trigger run of the template. I think I miss a basic concept of the sensor data. How can I differentiate a sensor value which was integrated by the manufacturer?
I dived into some existing topics but found no solution. (Like Calculating delta (change since last value) or others)
My goal is to feed this data to a VictoriaMetrics DB to visualize with grafana.
I created this template sensors via the GUI.
Edit: This is the entry from core.config_entries:
{
"created_at":"2025-12-28T12:25:58.467470+00:00",
"data":{},
"disabled_by":null,
"discovery_keys"{},
"domain":"template",
"entry_id":"01KDJERBE303APSWE1DAM4N2R3",
"minor_version":1,
"modified_at":"2025-12-28T18:43:55.763781+00:00",
"options":
{
"device_class":"energy",
"device_id":"6eb9cc13298a8e82d2800ed706e340f9",
"name":"Elektrische Energie Heizen",
"state":
"{%- if states('sensor.wh_warmepumpe_betrieb') == 'heatpump_operationmode_heating' %}\n {{ states('sensor.wh_statistik_elektr_energie_jahr') }}\n {%- else %}\n {{ 0 }}\n {%- endif %}","state_class":"total","template_type":"sensor","unit_of_measurement":"kWh"
},
"pref_disable_new_entities":false,
"pref_disable_polling":false,
"source":"user",
"subentries":[],
"title":"Elektrische Energie Heizen",
"unique_id":null,
"version":1
},


