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
Do you have any Idea, if I need to manually trigger the template?
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 ?
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.