Aviation Density Altitude Calculator + Conversions

I couldn’t find a good way to get some of the aviation weather data I wanted to display on a metar section on my dashboard, so I had to make some templates. The hardest one was figuring out the math for the Density Altitude. Since no one else seems to have a solution posted, I modified mine a bit so it can work for anyone.

Density Altitude Template Sensor

Do you have a sensors section in your configuration.yaml? If not, add this:

# Sensors
sensor:

Most of you can skip that and just add the following code to your configuration.yaml file in the sensors section:

# Density Altitude
  - platform: template
    sensors:
      weather_density_altitude:
        friendly_name: "Density Altitude"
        unit_of_measurement: "Feet"
        value_template: >
          {% set QNH = states('sensor.yoursensor_pressure_inhg') | float %}
          {% set OAT = states('sensor.yoursensor_temperature_c') | float %}
          {% set FA = yourfieldalt | float %}
          {% set ISA = 15 - (FA/1000 * 2) | float %}
          {% set PA = (FA + 145442.2) * (1 - ((QNH / 29.92126) ** 0.190261)) | float %}
            {{ (PA + (120 * (OAT - ISA) ) ) | round(0) }}

You must change three variables in the code above to make this work:

  1. Change “yoursensor” above to name of your pressure sensor, in inHg. Example:
    {% set QNH = states('sensor.openweathermap_pressure_inhg') | float %}

  2. Change the “yoursensor” above to name of your temperature sensor, in Celcius. Example:
    {% set OAT = states('sensor.openweathermap_temperature_c') | float %}

  3. Change the “yourfieldalt” above to the elevation of your airfield, in feet.
    Denver Example: {% set FA = 5433.8 | round(0) %}
    JFK Example: {% set FA = 13 | round(0) %}

Definitions:
PA = Calculated Pressure Altitude
FA = Altitude at Your Airfield
QNH = Current Barometric Pressure (inHg)
OAT = Current Outside Air Temp (C)
ISA = Standard Temp at Your Airfield (C)

Unit of Measure Conversions:

If your sensors aren’t currently using the correct units of measurement, you can also add any of the following to your configuration.yaml file, also under the sensors section:

# Metar Units Conversion
- platform: template
  sensors:

  # m/s to kts
    metar_wind_speed_kts:
      friendly_name: "Weather Wind Speed"
      unit_of_measurement: "knots"
      value_template: "{{ (states('sensor.yoursensor_wind_speed')|float*1.94384)|round(1) }}"

Use the following for other conversions:

  # mph to kts:
    value_template: "{{ (states('sensor.yoursensor_wind_speed')|float*0.868976)|round(1) }}"`

  # m/s to mph:
    value_template: "{{ (states('sensor.yoursensor_wind_speed')|float*2.23694)|round(1) }}"`

  # mb to inhg:
    value_template: "{{ (states('sensor.yoursensor_pressure')|float*0.02953)|round(2) }}"`

  # c to f:
    value_template: "{{ (states('sensor.yoursensor_temperature_c')|float*(9/5)+32)|round(2) }}"`

  # f to c:
    value_template: "{{ ((states('sensor.yoursensor_temperature')|float-32)*(5/9))|round(2) }}"`

Again, don’t forget to replace the “yoursensor” to the actual name of your sensor. Example:
value_template: "{{ ((states('sensor.openweathermap_temperature')|float-32)* 5/9)|round(2) }}"

Disclaimer:

NONE OF THIS INFO SHOULD BE UTILIZED IN THE AIRPLANE!

Use this for fun and so you can have a good idea of the conditions before you head to the airport. If you’re a pilot, you already know where to get the info you need for performance calculations.

Just be safe… and keep the blue side up!!!

a320

1 Like

HI, great post.

I found it while looking for a way to use the barometer in my RV (Recreational Vehicle).
The formula I should use is the #1 here Barometric formula - Wikipedia
image

So, here is my lazy lame question: do you think I can (re)use your formula for my purpose?

Thank you,
Piero