QFE to QNH Translation

From Domoticz
Revision as of 08:05, 27 February 2018 by Duodiscu92 (talk | contribs) (→‎Script with comments)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Purpose

Barometer sensors provide QFE values, that means the athmospheric pressure at the ground level of the sensor location. This make difficult to compare the indication with other sources like airfields wheather stations which devliver pressure at the sea level, namely QNH.

The purpose of this script is to convert QFE indication into QHN taking into account the altitude of the sensor location.

Dependencies

You will require a barometer sensor (e.g. Oregon, Xiaomi, La Crosse, home made etc.)

The script also uses a user variable of integer type which contain the altitude of your barometer location in meters.

Domoticz Setup

Input sensors

The input sensor is a barometer or a pressure sensor which delivers the QFE values in hPa

Output sensors

You must create a virtual sensor of type "barometer". It will contain the QNH value.

Altitude site user variable

Simply add a user variable of type 'integer', and assign it the altitude of your input sensor (in meters).

Installation instructions

1) configure the devices as described above

2) copy the script below and paste it into your preferred editor

3) change the name of the QFE sensor, QNH Sensor and user variable with the names of your own and the actual idx of your QNH virtual sensor

4) save the script under your .../domoticz/scripts/lua directory under the name: script_device_qfe2qnh.lua

Script with comments

--
-- Initial version from Jacques Ehrlich <[email protected]>
-- Can be freely copied and improved
------------------------------------------------------------------------------
-- script pour convertir un QFE en QHN en fonction de l'altitude du lieu ou se trouve le capteur
-- script to convert a QFE to QNH taking into account the sensor altitude

-- definition (from aeronautics)
--      QFE = pression a l'endroit où on se trouve/pressure at the current location level
--      QNH = pression au niveau de la mer/pressure at sea level

-----------------------------------------------------------------------------
-- sonde de QFE  Xiaomi/QFE Xiaomi sensor
-- name must be replaced by the name you have assigned to your QFE sensor
qfe = 'kPa Bureau (Xiaomi)'

-- sonde de QNH virtuelle/QNH virtual seensor
-- name must be replaced by the name you have assigned to your QNH virtual sensor
qhn = 'QNH Bureau (Xiaomi)'
qnh_id = 62

-- variable utilisateur : altitude du lieu/user variable : site altitude
-- name must be replaced by the name you have assigned to your user variable
alt = 'Altitude site'

------------------------------------------------------------------------------
commandArray = {}

if (devicechanged[qfe]) then
   current_qfe = tonumber(devicechanged[qfe])
-- you can uncomment the two following lines for debugging purpose. The QFE and site altitude will be printed in the log.
--   print(current_qfe)
--   print(uservariables[alt])
   current_qnh = math.floor(current_qfe + uservariables[alt]*0.1171)
-- note that forecast indicator is set to stable
   commandArray['UpdateDevice'] = qnh_id .. "|0|" .. current_qnh .. ";" .. "0"
   print ('Script qfe2qnh : conversion faite/translation done')
end

return commandArray