Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Question

Guest muhmuh
Posted

Hello,

im looking for a HC3 Script which switch a Bathroom Fan on/off with dependency relative humindity.

I found a HC2 Script from kapitano1 (https://forum.siio.de/t/lua-taupunktlueftung-im-keller/5206)

My Lua skill is very low, so i tried to change the code to hc3 and add my ids.

The script will run correctly when humidInAbs - humidOutAbs > 1 but the switch off fan code is not correct.

And sorry for my english, but it is not my native language; i tried my best.

Can anyone correct it please?
Debug:
28.08.2020] [12:44:00] [DEBUG] [SCENE218]: - 28.08.2020 12:44:00 AußenTemp 21.59°C rel. Feuchtigkeit 57.0%
[28.08.2020] [12:44:00] [DEBUG] [SCENE218]: - 28.08.2020 12:44:00 absolute Luftfeuchtigkeit Außen 10.969697021231g/m³
[28.08.2020] [12:44:00] [DEBUG] [SCENE218]: - 28.08.2020 12:44:00 InnenTemp 25.4°C rel. Feuchtigkeit 51.0%
[28.08.2020] [12:44:00] [DEBUG] [SCENE218]: - 28.08.2020 12:44:00 absolute Luftfeuchtigkeit Innen 12.211619119493g/m³
[28.08.2020] [12:49:00] [ERROR] [SCENE218]:

Please login or register to see this code.

 

 

Recommended Posts

  • 0
Posted
3 hours ago, muhmuh said:

can u add a delayin X Minutes, so we can config a minimal runtime for the fan?

its names hysteresis

OK

  • 0
Posted (edited)
On 9/6/2020 at 9:38 AM, muhmuh said:

I think this is a good Site in english which explain the rel. humidity. 

Please login or register to see this link.


For your fan and for fresh up the air u need the rel. humidity.

 


Thanks Muhmuh. So relative humidity is an algoritme of absolute humidity, temperature and air pressure. I will try to get the on / off values for my Fan with the relative humidity level. 

 

 

 

Edited by SmartHomeEddy
  • 0
Guest muhmuh
  • Inquirer
  • Posted
    On 9/6/2020 at 8:33 PM, 10der said:

    its names hysteresis

    OK

     

    And can u add this in the code @10der? is this possible?

    • 0
    Posted
    9 hours ago, muhmuh said:

     

    And can u add this in the code @10der? is this possible?

    actually I am busy on the workweek.

    weekend... only weekend...

    sorry!

    • 0
    Posted

    @muhmuh "Humidity_Controller (6).fqa" 

    updated

    • 0
    Guest muhmuh
  • Inquirer
  • Posted

    thank you very much. i will add it at evening.

    • 0
    Posted (edited)

    I like to say thank you for the stable main formule and script. I redesigned it a little bit for my own bathroom regulation.

     

    It's now in dutch however, Buiten = Outdoor, Woonkamer = living room, Badkamer = Bathroom

    If outdoor humidity  is less than inside it's possible to dry the bathroom (4.28 < 8.13)

    Normaal status is if 8,13 + 2 = True

    Hoog status is if 8,13 + 4 = True 

     

    Normal status set every few minutes mechanical ventilation + 5% with a max of 40%

    High status set mechanical ventilation to 90%

     

    Please login or register to see this image.

    /monthly_2021_01/1896725913_Screenshot2021-01-09at09_53_17.png.9e68613eb82f54a3824a51a3b4da3fb6.png" />

    Edited by Hearts
    • Like 1
    • 0
    Posted

    Looks great @Hearts I have other logics, but not happy with how it works, because winter, summer has different behavior. So i am looking for the absolute humidity to finetune my fan. 

    • 0
    Posted

    Thanks, i was already testing last summer with this script. The part Buiten 4.28 < 8.13 g/m3 is only for the summer to block the running fan if the outside humidity is higher than inside. The last tuneup I did was last week because of the littlebit frosty weather now in the Netherlands ?

    • 0
    Posted

    Trying to understand the values in your QA

     

    what represents 4.28 8.13 8.77 ?

    • 0
    Posted

    With the help of InfluxDB and Grafana I got a great insight of a comparison of the humidity.
     

    Because I now can compare Absolute Humidity, it is more easy to get a better setpoints for my Fan to turn on and off. At this moment I still just use a Relative Humidity setpoint on my Everspring, but now I am thinking of using a variable setpoint from my Living Absolute Humidity reading.  

    Nice graphic ?
     

    Please login or register to see this attachment.


     

     

    • Like 3
    • 0
    Posted

    New script works great.

     

    If absolute humidity bathroom is more than 2 g/m3 Living room then fan goes to level 2 and if absolute humidity bathroom is more than 3 g/m3 Living room then fan goes to level 3. 

     

    (and also works with in house CO2 levels)

     

    Please login or register to see this code.

     

    • Like 1
    • 0
    Posted

    This is great, was looking for something like this. Thanks guys. But can someone elaborate on the variables:

     

    pressure: should this be the inside or outside pressure
    switch: I quess this is the ventilation switch?
    tOutside: is this outside the bathroom so still inside the house or the temp outside the house
    hOutside: same question as above
    target: is this the sensor in the bathroom so if its a multisensor it will get temp and humidity?
    hysteresis_up: will wiki this?
    hysteresis_dn: 

     

    But was also interested in a timer for maximum time vent should spin. Or is this related to hysteresis up?

     

    Thanks!

    • 0
    Posted

    I don't know how the above quickapp works in detail. I see some different quickapps in the above posts. 

     

    The idea is to measure the absolute humidity inside your bathroom and outside your bathroom. Outside your bathroom would be inside your house, that will be your baseline where you want to keep your bathroom absolute humidity.

     

    So if you take a shower, the absolute humidity in your bathroom will increase. If the absolute humidity inside your bathroom increases above some value (hysteresis) your fan will turn on. I use 2 g/m³ difference for fan to level 2 and 3 g/m³ difference for fan to level 3. 

     

    You don't need a maximum time for your fan, because it should turn of if it goes below some value (in my case below 2 g/m³ and will go from level 3 to 2 if between 2-3 g/m³). 

     

    To calculate the absolute humidity, the air pressure will (almost) be the same inside your house and inside your bathroom. Perhaps the altitude will give some difference, but that won't be much, unless you live on the 1st floor and take a shower on the 55th floor ;-) If you don't have a pressure sensor, you could use the average pressure of 1013.25. 

    • 0
    Posted

    Hi SmartHomeEddy,

     

    Thanks for your quick response. Should it not also take into account the humidity outside the house. This is the air that is sucked into the house if that is very high it might not be beneficial to turn on the ventilation. And on that subject I thought of a turn off time when it takes to long to take humidity down and it starts to annoy me ;-).

     

    I took the pressure from your buienradar QA ;-)

     

    If you look at the screenshot of the humidity QA it tels me 64% outside and 58% inside. This is correct but it also tells 14.6 degrees, which is I guess outside the house but I did not gave a device ID for this temperature. So where is this coming from? And it gives message "hysteresis" which implies inside is more humid than outside, right? That is not the case in this example...

     

    Thanks!

     

     

    Please login or register to see this attachment.

    • 0
    Posted (edited)
    1 hour ago, ErikP said:

    if that is very high it might not be beneficial to turn on the ventilation


    The relative humidity outside could be high because of the low temperature. That is why we want to compare the absolute inside and outside humidity, that is sort of “corrected” with the temperature (and pressure). 

     

    1 hour ago, ErikP said:

    I took the pressure from your buienradar QA ;-)

    The outside absolute humidity is also there ?

     

    But I don’t compare my bathroom absolute humidity with the outside, but with the living room. For example, these are the measurements at this moment:

     

    6162E168-B6D7-4342-BFCB-08233DF3CB5B.jpeg.c4f5889b7169781269f81b196247350a.jpeg
     

    (And outside absolute humidity at this moment 8,35 g/m3)

     

    With this relative humidity 73% in the bathroom, you could think to turn on the fan. But that is not necessary, because the absolute humidity is ok compared to the living room. The absolute humidity in the living room, I should also be able to get in the bathroom. That is not always the case compared with the outside absolute humidity. 
     

    I don’t know what your quickapp should do. I think the hysteresis should be the treshold when to turn on the fan. Maybe post the source code here to see. 
     

     

     

     

     

     

    Edited by SmartHomeEddy
    • 0
    Posted

    Thanks again for your answer. I was just trying the QA from this discussion v6 download from the first post. This is the source code:

     

    if dofile and not hc3_emulator then
        require("fibaro")
        -- hc3_emulator = {startWeb = false, speed = 1}
        hc3_emulator = {quickVars = {}, id = 1979}
        hc3_emulator.quickVars["tOutside"] = "1170"
        hc3_emulator.quickVars["hOutside"] = "1176"
        hc3_emulator.quickVars["tInside"] = "861"
        hc3_emulator.quickVars["hInside"] = "1180"
        hc3_emulator.quickVars["pressure"] = "1470"
        hc3_emulator.quickVars["switch"] = "989"
        dofile("fibaroapiHC3.lua")
        return
    end
     
    local temperatureOutsideId
    local humidiryOutsideId
    local temperatureInsideId
    local humidiryInsideId
    local pressureId
    local switchId
     
    local hygro_target = 1
    local hygro_hysteresis_up = 0
    local hygro_hysteresis_dn = 2
     
    function round(num, idp)
        idp = idp or 0
        if idp ~= 0 and num % 1 ~= 0 then
            local mult = 10 ^ idp
            r = math.floor(num * mult + 0.5) / mult
            if r % 1 == 0 then
                return math.floor(r)
            else
                return r
            end
        else
            return math.floor(tonumber(num) + 0.5)
        end
    end
     
    function QuickApp:turnOn()
        self:debug("binary switch turned on")
        self:updateProperty("value", true)
        self:updateProperty("log", "enabled...")
        self:check()
    end
     
    function QuickApp:turnOff()
        self:debug("binary switch turned off")
        self:updateProperty("value", false)
        self:updateProperty("log", "disabled...")
        self:check()
    end
     
    function calcHumidity(temperature, humidity, pressure)
        local EXP = tonumber("2.71828182845904523536028747135266249775724709369995")
        local humAbs =
            0.622 * humidity / 100 *
            (1.01325 *
                10 ^
                    (5.426651 - 2005.1 / (temperature + 273.15) +
                        0.00013869 * ((temperature + 273.15) * (temperature + 273.15) - 293700) / (temperature + 273.15) *
                            (10 ^
                                (0.000000000011965 * ((temperature + 273.15) * (temperature + 273.15) - 293700) *
                                    ((temperature + 273.15) * (temperature + 273.15) - 293700)) -
                                1) -
                        0.0044 * 10 ^ (-0.0057148 * (374.11 - temperature) ^ 1.25)) +
                (((temperature + 273.15) / 647.3) - 0.422) * (0.577 - ((temperature + 273.15) / 647.3)) *
                    EXP ^
                        (0.000000000011965 * ((temperature + 273.15) * (temperature + 273.15) - 293700) *
                            ((temperature + 273.15) * (temperature + 273.15) - 293700)) *
                    0.00980665) /
            (pressure / 1000 -
                humidity / 100 *
                    (1.01325 *
                        10 ^
                            (5.426651 - 2005.1 / (temperature + 273.15) +
                                0.00013869 * ((temperature + 273.15) * (temperature + 273.15) - 293700) /
                                    (temperature + 273.15) *
                                    (10 ^
                                        (0.000000000011965 * ((temperature + 273.15) * (temperature + 273.15) - 293700) *
                                            ((temperature + 273.15) * (temperature + 273.15) - 293700)) -
                                        1) -
                                0.0044 * 10 ^ (-0.0057148 * (374.11 - temperature) ^ 1.25)) +
                        (((temperature + 273.15) / 647.3) - 0.422) * (0.577 - ((temperature + 273.15) / 647.3)) *
                            EXP ^
                                (0.000000000011965 * ((temperature + 273.15) * (temperature + 273.15) - 293700) *
                                    ((temperature + 273.15) * (temperature + 273.15) - 293700)) *
                            0.00980665)) *
            pressure /
            1000 *
            100000000 /
            ((temperature + 273.15) * 287.1)
        return humAbs
    end
     
    function QuickApp:check()
        local pressure = 1013 -- Standard sea level pressure is 1013 hPa
        if pressureId then
            pressure = fibaro.getValue(pressureId, "value") * 10 -- kPa to Millibar
        end
     
        -- outsioe
        local outside = 0
        local tOutside = fibaro.getValue(temperatureOutsideId, "value")
        local hOutside = fibaro.getValue(humidiryOutsideId, "value")
        if tOutside ~= nil and hOutside ~= nil then
            outside = calcHumidity(tOutside, hOutside, pressure)
        else
            self:warning("Oudside calculation failed!")
            return
        end
     
        -- inside
        local inside = 0
        local tInside = fibaro.getValue(temperatureInsideId, "value")
        local hInside = fibaro.getValue(humidiryInsideId, "value")
     
        if tInside ~= nil and hInside ~= nil then
            inside = calcHumidity(tInside, hInside, pressure)
        else
            self:warning("Inside calculation failed!")
            return
        end
     
        local currentState = false
        if switchId then
            currentState = fibaro.getValue(switchId, "value")
        end
        local diff = round(inside) - round(outside)
        local needVentilation  = nil
     
        local hygro_target_on = hygro_target + hygro_hysteresis_up
        local hygro_target_off = hygro_target - hygro_hysteresis_dn
     
        if (currentState == false and diff >= hygro_target_on) then
            needVentilation = true
        elseif (currentState == true and diff <= hygro_target_off) then
            needVentilation = false
        else
            -- hysteresis
        end
     
        --print(tOutside, tInside)
        --print(hOutside, hInside)
     
        self:updateView("lblTemp", "text", round(tOutside, 1) .. "°C" .. "/" .. round(tInside, 1) .. "°C")
     
        self:updateView("lblHum", "text", round(hOutside, 1) .. "%" .. "/" .. round(hInside, 1) .. "%")
     
        self:updateView(
            "labelInfo",
            "text",
            "OUT: " ..
                tostring(round(outside)) ..
                    "g/m³" .. " < " .. " IN:" .. tostring(round(inside)) .. "g/m³" .. "\n" .. tostring(needVentilation)
        )
     
        if needVentilation == nil then
            self:updateProperty("log", "Hysteresis...")
            return
        end
     
        if switchId then
            local enabled = fibaro.getValue(self.id, "value")
            if not enabled then
                -- disabled. do not control
                return
            end
     
            if needVentilation then
                self:updateProperty("log", "Ventilation.")
                if not currentState then
                    -- turn ON
                    fibaro.call(switchId, "turnOn")
                end
            else
                self:updateProperty("log", "idle")
                if currentState then
                    -- turn OFF
                    fibaro.call(switchId, "turnOff")
                end
            end
        end
    end
     
    function QuickApp:getValueOrDefault(name, defValue)
        local value = self:getVariable(name)
        if value == "" or value == "-" then
            if value == "" then
                fibaro.call(plugin.mainDeviceId, "setVariable", name, "-")
            end
            return defValue
        else
            return value
        end
    end
     
    function QuickApp:onInit()
        self:debug("onInit")
     
        local room = api.get("/rooms/" .. (fibaro.getRoomID(self.id) or 0))
        if room ~= nil then
            temperatureInsideId = room.defaultSensors.temperature
            humidiryInsideId = room.defaultSensors.humidity
        end
     
        temperatureOutsideId = tonumber(self:getVariable("tOutside"))
        if not temperatureOutsideId then
            self:warning("tOutside is not configured")
            return
        end
     
        humidiryOutsideId = tonumber(self:getVariable("hOutside"))
        if not humidiryOutsideId then
            self:warning("hOutside is not configured")
            return
        end
     
        local _temperatureInsideId = tonumber(self:getVariable("tInside"))
        if _temperatureInsideId then
            temperatureInsideId = _temperatureInsideId
        elseif not temperatureInsideId then
            self:warning("tInside is not configured")
            return
        end
     
        local _humidiryInsideId = tonumber(self:getVariable("hInside"))
        if _humidiryInsideId then
            humidiryInsideId = _humidiryInsideId
        elseif not humidiryInsideId then
            self:warning("hInside is not configured")
            return
        end
     
        pressureId = tonumber(self:getVariable("pressure"))
        if not pressureId then
            self:warning("pressure is not configured")
            pressureId = nil
        end
     
        switchId = tonumber(self:getVariable("switch"))
        if not switchId then
            self:warning("switch is not configured")
            switchId = nil -- just show. no actions
        end
     
        local hygro_target = self:getValueOrDefault("target", 1)
        local hygro_hysteresis_up = self:getValueOrDefault("hysteresis_up", 1)
        local hygro_hysteresis_dn = self:getValueOrDefault("hysteresis_dn", 2)
     
        setInterval(
            function()
                self:check()
            end,
            1000 * 60 * 1
        ) -- 1 minutes
        self:check()
    end
    • 0
    Posted

    So I'm unsure what variable "target" is. And also I see tInside and hInside but those are not in the variable list of the QA so I'm a bit puzzled how to use it the correct way

    • 0
    Posted (edited)
    6 minutes ago, ErikP said:

    tInside and hInside


    If you don’t add them in the quickapp variable, the default temperature and humidity sensor of the room where the quickapp is in, will be used.

     

    local room = api.get("/rooms/" .. (fibaro.getRoomID(self.id) or 0))
        if room ~= nil then
            temperatureInsideId = room.defaultSensors.temperature
            humidiryInsideId = room.defaultSensors.humidity
        end

     

     

     

     

     

    Edited by SmartHomeEddy
    • 0
    Posted
    On 3/6/2021 at 1:22 PM, SmartHomeEddy said:

    New script works great.

     

    If absolute humidity bathroom is more than 2 g/m3 Living room then fan goes to level 2 and if absolute humidity bathroom is more than 3 g/m3 Living room then fan goes to level 3. 

     

    (and also works with in house CO2 levels)

     

    Please login or register to see this code.

     

    And @SmartHomeEddy which script are you referring to here? Can you share?

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...