Use HUM LEVEL to setLevel for Ventilation  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
puntjuh
Posts: 2
Joined: Monday 16 November 2020 12:18
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Use HUM LEVEL to setLevel for Ventilation

Post by puntjuh »

Hi all,

I'm new to dzVents, have been using blockly but i want to go about using dzVents as i find it provides me with more flexibility but i'm stuck at trying to get my Ventilation to enable once the detected humidity passes a certain level (65%).

The average humidity on my bathroom is between 50-60 percent during winter time and between 30-50 percent during the summer so i was kind of hoping to enable my ventilation and set it to 100% if my humidity passes 65 percent.

the script i have at the moment will detect the current value of my humidity sensor and then use the value to enable the ventilation.
Or would it be better to detect a major increase of humidity from a certain current level? But on rainy days humidity seems to increase quite quick anyway.

The problem with the current script is that it will keep running and the logging comes back with the error:

Code: Select all

2021-03-16 11:34:51.045 Error: dzVents: Error: (3.0.2) ...e/pi/domoticz/scripts/dzVents/generated_scripts/test.lua:28: attempt to concatenate a nil value (local 'humidity')
Which makes sense, but i'm not to sure as to prevent it from happening, how can i prevent the script from being executed over and over?
Also, preferably i would want to prevent the ventilation from becoming active during the night even though it is quiet even at 100%.

Code: Select all

return {
   on = 
    {
        devices = 
        {
            'BDKth',
            'MV'
        },
    },
    
    logging = 
    {
        level = domoticz.LOG_DEBUG, 
    },

    data =
    {
        currentState = 
        { 
            initial = '',
        },
    },

 execute = function(dz, item)
        local temperature = item.temperature
        local humidity = item.humidity
     
dz.log('Device ' .. item.name .. '; temperature is '.. temperature .. '° C , humidity is ' ..humidity .. '.', dz.LOG_DEBUG)

if humidity > 65 then -- if humidity is higher than 50%
 dz.devices('MV').setLevel(100).forMin(60) -- Set MV to 100% for 60 Minutes
elseif humidity < 64 then -- if humidity is lower than 50%
 dz.devices('MV').setLevel(50) -- set to default 50% 

end

end

}
Any help is greatly appreciated!

Regards,

Dimitri.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Use HUM LEVEL to setLevel for Ventilation  [Solved]

Post by waaren »

puntjuh wrote: Tuesday 16 March 2021 11:39 The problem with the current script is that it will keep running and the logging comes back with the error:

Code: Select all

2021-03-16 11:34:51.045 Error: dzVents: Error: (3.0.2) ...e/pi/domoticz/scripts/dzVents/generated_scripts/test.lua:28: attempt to concatenate a nil value (local 'humidity')
Which makes sense, but i'm not to sure as to prevent it from happening, how can i prevent the script from being executed over and over?
Also, preferably i would want to prevent the ventilation from becoming active during the night even though it is quiet even at 100%.
Below version should solve some of the mentioned issues.

Code: Select all

return
{
   on =
    {
        timer =
        {
            'at 06:00-23:00', -- not at night
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,  -- set to domoticz.LOG_ERROR when all ok
        marker = 'Vent control',
    },

    data =
    {
        currentState =
        {
            initial = '',
        },
    },

    execute = function(dz)
        local sensor = dz.devices('BDKth')
        local vent = dz.devices('MV')

        local temperature = sensor.temperature
        local humidity = sensor.humidity

        dz.log('Device ' .. sensor.name .. '; temperature is '.. temperature .. '° C , humidity is ' ..humidity .. '.', dz.LOG_DEBUG)

        if humidity > 65 and vent.level < 100 then -- if humidity is higher than 50% and vent not already at max
            vent.setLevel(100) -- Set MV to 100% for 60 Minutes
            vent.setLevel(50).afterSec(3600) -- Set MV back to 50%
        elseif humidity < 64 then -- if humidity is lower than 50%
            vent.setLevel(50) -- set to default 50%
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
puntjuh
Posts: 2
Joined: Monday 16 November 2020 12:18
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Use HUM LEVEL to setLevel for Ventilation

Post by puntjuh »

Thanks Waaren, this seems to have fixed the issue with the script looping and the time issue, should've thought of that!
For now this is exactly what i was looking for, and now it's a question of seeing whether maintaining a static number of 65% will work or whether i should change it to look at a major increases of the humidity level.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest