Enery monitoring: template/sensor does not update its value

Hi all,

I have a combined heating system / water heater and I want to measure hot water / heating separately.

As input, i have a SmartMeter that I can read with the edl21 integration.
It will export:

sensor.waermepumpe_electricity_id = (censored)
sensor.waermepumpe_positive_active_energy_in_tariff_t = 11958983.0
sensor.waermepumpe_sum_active_instantaneous_power = 1063.6

Unfortunately, the only thing I can fetch from my heater is a value called “Heizstufe” [0…2] which tells the current activity:
0: Idle
1: Heating
2: Hot Water

Therefore, I would like to split the power measured by my meter onto the activities:
sensor:

sensor:
    - platform: scrape
      #resource: http://servicewelt.fritz.box/?s=1,0
      resource: http://192.168.188.59/?s=1,0
      select: "#werte>#content>div+div+div+div+div tr+tr>td+td"
      value_template: "{{ value|int }}"
      name: tecalor_heizstufe

template:
    - sensor:
        name: tecalor_heizung_leistung
        unique_id: tecalor_heizung_leistung
        device_class: power
        state_class: measurement
        unit_of_measurement: "W"
        #else branch set to nonzero values for debugging purposes
        state: >-
          {% if (states('sensor.Heizstufe')|int == 0) or (states('sensor.Heizstufe')|int == 1) %}
            {{ states('sensor.waermepumpe_sum_active_instantaneous_power ')|float }}
          {% else %}
            0.1
          {% endif %}
          
    - sensor:
        name: tecalor_warmwasser_leistung
        unique_id: tecalor_warmwasser_leistung
        device_class: power
        state_class: measurement
        unit_of_measurement: "W"
        #else branch set to nonzero values for debugging purposes
        state: >-
          {% if (states('sensor.Heizstufe')|int == 2) %}
            {{ states('sensor.waermepumpe_sum_active_instantaneous_power ')|float }}
          {% else %}
            0.2
          {% endif %}

What I observe now:
If the “IF” does not match, I can see the values 0.1 / 0.2 shown in the ELSE branch.
But if it matches, I will only get
sensor.tecalor_heizung_leistung = unavailable

I already tried all kinds of typecasting to waermepumpe_sum_active_instantaneous_power, but nothing changes :frowning:

Do you have any Idea, if I need to manually trigger the template?

BR
Nippey

You have to give default value to “int” and “float” (you probably have errors in the logfiles), like this (see below) but you can choose any other number than 0 as you are testing the value equal to 0, so if the entity is unknown/unavailable the value will be 0 by default… we should probably use 3 as default for the expression testing equal to “0”:

sensor:
    - platform: scrape
      #resource: http://servicewelt.fritz.box/?s=1,0
      resource: http://192.168.188.59/?s=1,0
      select: "#werte>#content>div+div+div+div+div tr+tr>td+td"
      value_template: "{{ value|int(default=0) }}"
      name: tecalor_heizstufe

template:
    - sensor:
      - name: tecalor_heizung_leistung
        unique_id: tecalor_heizung_leistung
        device_class: power
        state_class: measurement
        unit_of_measurement: "W"
        #else branch set to nonzero values for debugging purposes
        state: >-
          {% if (state('sensor.Heizstufe')|int(default=3) == 0) or (state('sensor.Heizstufe')|int(default=0) == 1) %}
            {{ states('sensor.waermepumpe_sum_active_instantaneous_power ')|float(default=0) }}
          {% else %}
            0.1
          {% endif %}
          
      - name: tecalor_warmwasser_leistung
        unique_id: tecalor_warmwasser_leistung
        device_class: power
        state_class: measurement
        unit_of_measurement: "W"
        #else branch set to nonzero values for debugging purposes
        state: >-
          {% if (state('sensor.Heizstufe')|int(default=0) == 2) %}
            {{ states('sensor.waermepumpe_sum_active_instantaneous_power ')|float(default=0) }}
          {% else %}
            0.2
          {% endif %}

What is the value of “sensor.tecalor_heizstufe” ?
Any error in home-assistant.log ?

Awesome, adding default values worked!
Now, I’ll have to wait some time to see if nonzero values for Heizstufe are working, too.

What is the value of “sensor.tecalor_heizstufe” ?

sensor.tecalor_heizstufe = 0
In summer, basically 0 almost all day long.
Shot periods of 2 for some minutes each day.
Difficult to debug :smiley:

Any error in home-assistant.log ?

2022-08-12 13:37:13.562 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform scrape is taking over 10 seconds.

I saw this message before, and just assumed, that after 10 seconds, it will work fine.
Message is still there, but it is working now!

BR
Nippey

Hi @browetd,

adding the default values removed the errors. But the conditional was still not working.
The error was actually sitting in front of the screen, missing an obvious typo. []tecalor_heizstufe != Heizstufe]
(Which didn’t show up in the logs)

What I learned:
Even if default values will be quite useful (and will use them), they will hide any mismatches/typos of the entity names.

Thank you!

1 Like