I have two sensors and calculate their average. However, the average time to time returns apparently wrong number. Any idea where the problem could lie?
Code:
livingroom_temperature:
friendly_name: Living room Temperature
unit_of_measurement: '°C'
value_template: "{{((states('sensor.livingroom_valve_temperature')) | float + (states('sensor.livingroom_sensor_temperature')) | float) / 2}}"
The template in configuration.yaml is certainly correct. HACS sensor wont make difference. The problem is not the return of the value but sudden accidental wrong return as you can see on the graph. The yellow line drop.
It could be an issue with the updating of the sensor values that is used to calculate average and the template sensor itself. can you check what are the parent sensor values at the time of such deviation. Is it nominal?
When a sensor value is unknown filtering that sensor with |float returns 0.
Use an availability template to ensure both your sensors are available.
You will have to scroll up a bit as the current security warning is messing with the link location: Template - Home Assistant
This is the easiest way to do it assuming your sensors never get to 0 degrees:
availability_template: >
{{ 0 not in [ states('sensor.livingroom_sensor_temperature')|float, states('sensor.livingroom_valve_temperature')|float ] }}
If either of the sensors could report 0 degrees, use this instead:
availability_template: >
{{ states('sensor.livingroom_sensor_temperature') not in ['unavailable', 'unknown', 'none' ] and states('sensor.livingroom_valve_temperature') not in ['unavailable', 'unknown', 'none' ] }}
So firstly I make the virtual availability_template out of the sensor provided by the hw, then I create another layer that calculates the average? So my current sensor never calucalte with zeros?
or netatmo integration? Maybe cgtobi is playing with my valves as I provided my home as a testbed, haha, no you are correct. I am playing with it all the time and this can be the cause. If I let the HA for half day alone, the error does not surface
Is there a better syntax to avoid it or I should ignore it?
livingroom_temperature:
friendly_name: Living room Temperature
unit_of_measurement: '°C'
value_template: "{{((states('sensor.livingroom_valve_temperature')) | float + (states('sensor.livingroom_sensor_temperature')) | float) / 2}}"
availability_template: "{{ 0 not in [ states('sensor.livingroom_sensor_temperature')|float, states('sensor.livingroom_valve_temperature')|float ] }}"
availability_template: "{{ states('sensor.livingroom_sensor_temperature') not in ['unavailable', 'unknown', 'none' ] and states('sensor.livingroom_valve_temperature') not in ['unavailable', 'unknown', 'none' ] }}"