• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ideas Wanted Decision Matrix
#21
You need 10+ posts in order to post links to fight spam.
 
Reply
#22
(03-03-2019, 02:33 PM)curlymo Wrote: You need 10+ posts in order to post links to fight spam.

Ok, 2 more to go Smile . Here comes #1:

I implemented the desired function in a lua module:

Code:
-- Determine, if venting air from an external space to an internal space makes sense
--  regarding humidity.
--
--  Parameters:
--    te = external temperature in °C
--    he = external rel. humidity in percent
--    ti = internal temperature in °C
--    hi = internal rel. humidity in percent
--
--  Returns:
--    boolean true, if venting makes sense, false otherwise
local function OkToVent(te, he, ti, hi)
   local am = (he * 0.42 * math.exp(te * 10 * 0.006235398) / 10)
   local hr = am * 10 / (0.42 * math.exp(ti * 10 * 0.006235398))
   return (hr < hi)
end

-- Module code starts here
--
local M = {}

function M.run(te, he, ti, hi, c)
 if (ti == nil or te == nil or hi == nil or he == nil) or c ~= nil then
   error("OKTOVENT requires 4 arguments");
 end
 if tonumber(ti) == nil then
   error(string.format("OKTOVENT argument #1 expected number, \"%s\" given", type(ti)));
 end
 if tonumber(te) == nil then
   error(string.format("OKTOVENT argument #2 expected number, \"%s\" given", type(te)));
 end
 if tonumber(hi) == nil then
   error(string.format("OKTOVENT argument #3 expected number, \"%s\" given", type(hi)));
 end
 if tonumber(he) == nil then
   error(string.format("OKTOVENT argument #4 expected number, \"%s\" given", type(he)));
 end

 return OkToVent(tonumber(te), tonumber(he), tonumber(ti), tonumber(hi));
end

function M.info()
 return {
   name = "OKTOVENT",
   version = "1.0",
   reqversion = "8.1.2",
   reqcommit = "94"
 }
end

return M;


You can put it into /usr/local/lib/pilight/functions/oktovent.lua

In your rule, invoke it like this:


Code:
IF OKTOVENT(text,hext,tint,hint) THEN switch DEVICE fan.state TO on else switch DEVICE fan.state TO off


where text = the external temp (in °C), hext = the external rel humidity (in %), tint and hint are the same for the internal space (your basement).
 
Reply
#23
Here is a little lua code that helps you with manually testing a lua module outside of pilight (a.k.a. standalone on the commandline using lua):


Code:
local args = table.pack(...)
if (args.n < 1) then
   error("testmod requires at least a module name")
end
print(string.format("Testing module %s", args[1]))
m = require(args[1])
print(m .run(select(2,...)))


Put this code into testmod.lua
Put oktovent.lua into the same directory, then invoke test it manually like in the following example:


Code:
[felfert@fritz ~]$ lua testmod.lua oktovent 20 30 23 25
Testing module oktovent
true
[felfert@fritz ~]$ lua testmod.lua oktovent 20 30 23 24
Testing module oktovent
false

In the above example the external temperature is 20°C, the external rel. humidity is 30%, the internal temperature is 23°C

If the internal rel. humidity is 25%, it still would make sense to vent air, however if it is 24% then the venting should stop.
 
Reply
#24
What about naming it a little more generic? E.g. rh2ah. Let it take 2 parameters so the rule becomes:
Code:
IF rh2ah(a, b) < rh2ah(c, d) THEN ...
Taken from here:
https://github.com/hendrikwout/meteo/blo...umidity.py
 
Reply
#25
(03-03-2019, 06:00 PM)curlymo Wrote: What about naming it a little more generic? E.g. rh2ah. Let it take 2 parameters so the rule becomes:
Code:
IF rh2ah(a, b) < rh2ah(c, d) THEN ...
Taken from here:
https://github.com/hendrikwout/meteo/blo...umidity.py

Assuming rh2ah meaning RelativeHumidityToAbsoluteHumidity?

Because it has nothing to do with absolute humidity and is not generic at all (at least as far as I understand it):
I have not the slightest clue about the physics behind that Angel
I just transformed the formula from javascript (from the site, mentioned in this question)
to lua.

Instead (as far as I understand) it directly calculates the resulting relative humidity as a function of the original relative humidity and the temperatures of the originating and destination space. (actually 3 input parameters) and then compares that to the existing relative humidity of the destination (the 4th parameter).

So: It actually is named appropriately after "Ok To Vent".

Cheers
 -Fritz
 
Reply
#26
Thanks a lot, guys.

I will read into lua and test, as soon I found some minutes spare time...;-)
 
Reply
#27
Gave it a first shot an ran into an error:

Code:
                 "keller_kino": {
                        "protocol": [ "elro_800_switch" ],
                        "id": [{
                                "systemcode": 29,
                                "unitcode": 1
                        }],
                        "state": "off"
                },
                 "sensor_keller": {
                        "protocol": [ "tfa30" ],
                        "id": [{
                                "id": 32
                        }],
                        "temperature": 25.2,
                        "humidity": 44.0
                },
                "sensor_draussen": {
                        "protocol": [ "tfa30" ],
                        "id": [{
                                "id": 22
                        }],
                        "temperature": 25.4,
                        "humidity": 43.0
                }
        },
        "rules": {
                "test": {
                        "rule": "IF OKTOVENT(sensor_draussen.temperature,sensor_draussen.humidity,sensor_keller.temperature,sensor_keller.humidity) THEN switch DEVICE keller_kino.state TO on else switch DEVICE keller_kino.state TO off",
                        "active": 1
                        }
                },

Code:
pilight-daemon: ERROR: /usr/local/lib/pilight/actions/switch.lua:94: device "off" does not exist

Am I thinking wrong?

Testmod also Fails:

Code:
root@raspberrypi:/usr/local/lib/pilight/functions# lua testmod.lua oktovent 20 30 23 25
lua: testmod.lua:1: attempt to call field 'pack' (a nil value)
stack traceback:
        testmod.lua:1: in main chunk
        [C]: ?
 
Reply
#28
There is no device called, which you are telling pilight there should.
Code:
keller_kino.state
 
Reply
#29
(03-10-2019, 06:45 PM)curlymo Wrote: There is no device called, which you are telling pilight there should.
Code:
keller_kino.state

Oh... You´re Right. removed .state and now it´s running.

But have no idea on how to test it...

Seems not to work. Removed Sender/Receiver Hardware and setted Values manually:

Code:
"sensor_keller": {
                        "protocol": [ "tfa30" ],
                        "id": [{
                                "id": 32
                        }],
                        "temperature": 23.0,
                        "humidity": 25.0
                },
                "sensor_draussen": {
                        "protocol": [ "tfa30" ],
                        "id": [{
                                "id": 22
                        }],
                        "temperature": 20.0,
                        "humidity": 30.0
                },

But Fan stay´s off...
 
Reply
#30
Regarding this error:

Code:
root@raspberrypi:/usr/local/lib/pilight/functions# lua testmod.lua oktovent 20 30 23 25
lua: testmod.lua:1: attempt to call field 'pack' (a nil value)
stack traceback:
        testmod.lua:1: in main chunk
        [C]: ?

The pack() function was introduced in lua 5.2.x. So: obviously you have an older lua. (My PC runs Fedora19 which provides a newer - current - lua). On the raspberry, there's only lua 5.1.5. You can print your lua version by running:

Code:
[felfert@fritz ~]$ lua -v

Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio


Sorry for the inconvenience. Here is a new testmod.lua which is backward-compatible to lua 5.1.x (as found on my raspian "Raspbian GNU/Linux 9 (stretch)"):

Code:
local args = {...}
local argc = select('#', ...)
if (argc < 1) then
    error("testmod requires at least a module name")
end
print(string.format("Testing module %s", args[1]))
m = require(args[1])
print(m .run(select(2,...)))
 
Reply
  


Forum Jump:


Browsing: 1 Guest(s)