Hello everyone, I want to rewrite the first code so that it works even if one of the sensors has the status unknown. Unfortunately, the sensor does not appear in the corrected version. Do I have an error in the code?"
First Code:
template:
- sensor:
- name: v2
state_class: total_increasing
icon: mdi:transmission-tower
unit_of_measurement: W
device_class: power
state: "{{states('sensor.tasmota_power_power_curr') | float() +states('sensor.balkon_ch2_power') | float() }}"
And new Version:
template:
- sensor:
- name: v2
state_class: total_increasing
icon: mdi:transmission-tower
unit_of_measurement: W
device_class: power
value_template: >
{% set sensor_a = states('sensor.tasmota_power_power_curr') | float %}
{% set sensor_b = states('sensor.balkon_ch2_power') %}
{% if sensor_b == 'unknown' %}
{{ sensor_a }}
{% else %}
{{ sensor_a + sensor_b | float }}
{% endif %}
Thank you so far !