Formula for pressure: Wrong results if input data has gaps?
Closed this issue · 3 comments
Smo-RBR commented
It seems, if the input data has gaps, the formula gives not "no data", but a result of the other factors. This results in wrong, and ugly :) graphs
Smo-RBR commented
lichtteil commented
You could try wrapping your template in a condition and give your desired value/no-value when the sensor has its gaps.
Untested example:
{% if not states('sensor.feinstaubsensor_temperature') == 'unknown' and not states('sensor.feinstaubsensor_pressure') == 'unknown' %}
{% set temperature_gradient = 0.0065 %}
{% set exponent = 0.03416 / temperature_gradient %}
{% set altitude_meters = 300 %}
{% set temperature_celsius = states('sensor.feinstaubsensor_temperature') | float %}
{% set temperautre_at_sealevel_kelvin = temperature_celsius + (temperature_celsius * temperature_gradient) + 273.15 %}
{% set air_pressure_hpa = (states('sensor.feinstaubsensor_pressure') | float / 100) | round(1) %}
{{ (air_pressure_hpa / (1 - ((temperature_gradient * altitude_meters) / temperautre_at_sealevel_kelvin)) ** exponent) | round(1) }}
{% endif %}
Smo-RBR commented
Thank you, Mario and Lichtteil