lichtteil / local_luftdaten

Custom component for Home Assistant that integrates your (own) local Luftdaten sensor (air quality/particle sensor) without using the cloud.
MIT License
46 stars 19 forks source link

Formula for pressure: Wrong results if input data has gaps? #46

Closed Smo-RBR closed 2 years ago

Smo-RBR commented 2 years ago

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 2 years ago

For better understanding, i did two screenshots and combined them: Ohne Titel

lichtteil commented 2 years ago

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 2 years ago

Thank you, Mario and Lichtteil