Skip to content

Instantly share code, notes, and snippets.

@zegerk
Last active June 21, 2019 13:12
Show Gist options
  • Save zegerk/f7d89dcd227f3d118919bfd2d0d8e71b to your computer and use it in GitHub Desktop.
Save zegerk/f7d89dcd227f3d118919bfd2d0d8e71b to your computer and use it in GitHub Desktop.
--[[
%% properties
93 value
95 value
100 value
102 value
%% weather
%% events
%% globals
--]]
-- Calculate the dew point using air temp, humidity and floor temps, to be
-- used in Fibaro Home Center 2 scene, global variables are set to be used
-- in other scenes.
------------------------------------------------------------------------
--
-- Dew point calculation using Magnus formula: http://en.wikipedia.org/wiki/Dew_point
--
-- http://forum.micasaverde.com/index.php?topic=37464.0
--
function dewPoint (T, RH)
-- a,b,c taken from a 1980 paper by David Bolton in the Monthly Weather Review
-- local a = 6.112 -- a is not used in this approximation
local b,c = 17.67, 243.5
RH = math.max (RH or 0, 1e-3)
local gamma = math.log (RH/100) + b * T / (c + T)
return c * gamma / (b - gamma)
end
local startSource = fibaro:getSourceTrigger();
-- Device ids are stored in global variables
local FLOOR_LEFT_AIR_TEMP = fibaro:getGlobal('D_FLOOR_LEFT_AIR_T')
local FLOOR_LEFT_TEMP = fibaro:getGlobal('D_FLOOR_LEFT_TEMP')
local FLOOR_LEFT_HUM = fibaro:getGlobal('D_FLOOR_LEFT_HUM')
local FLOOR_R_AIR_TEMP = fibaro:getGlobal('D_FLOOR_R_AIR_T')
local FLOOR_R_TEMP = fibaro:getGlobal('D_FLOOR_R_TEMP')
local FLOOR_R_HUM = fibaro:getGlobal('D_FLOOR_R_HUM')
local floor_left_air_temp = tonumber(fibaro:getValue(FLOOR_LEFT_AIR_TEMP, "value"))
local floor_left_hum = tonumber(fibaro:getValue(FLOOR_LEFT_HUM, "value"))
local floor_left_temp = tonumber(fibaro:getValue(FLOOR_LEFT_TEMP, "value"))
local floor_right_air_temp = tonumber(fibaro:getValue(FLOOR_R_AIR_TEMP, "value"))
local floor_right_hum = tonumber(fibaro:getValue(FLOOR_R_HUM, "value"))
local floor_right_temp = tonumber(fibaro:getValue(FLOOR_R_TEMP, "value"))
-- offset for the air temperture
local air_temp_offset = -1
-- take the maximum temperature and the maximum humidity,
-- assume the "worst" combination
local dew_point = math.ceil(
dewPoint(
math.max(floor_left_air_temp, floor_right_air_temp) + air_temp_offset,
math.max(floor_left_hum, floor_right_hum)
) * 100
) / 100
-- Store the dew point in a global variable so we can use it in other scenes
fibaro:setGlobal(
"cellar_dew_point",
dew_point
);
fibaro:debug(dew_point)
-- Compute the temperature difference between dew point and floor temperature
fibaro:setGlobal(
"cellar_dew_diff_l",
floor_left_temp - dew_point
)
fibaro:setGlobal(
"cellar_dew_diff_r",
floor_right_temp - dew_point
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment