Page 7 of 8

Re: Lua script for controlling humidity in the bathroom

Posted: Sunday 10 November 2019 19:44
by Dekereluitherel
Hi Guys,

frequent reader of the forum, but first post.
I'm having the same problems as BarryT since updating to latest beta:

the script does not work anymore because of the decimal in data from the humidity sensor (xiaomi sensor)

changing the integer to string does not work with me because the targetFanOffHumidity stays 0.

anyone knows how to fix this?

Re: Lua script for controlling humidity in the bathroom

Posted: Sunday 10 November 2019 20:46
by waaren
Dekereluitherel wrote: Sunday 10 November 2019 19:44 I'm having the same problems as BarryT since updating to latest beta:
anyone knows how to fix this?
There are many different versions of this script flying around on this forum. If you share the version you use (or a link to it) I will have a look.

Re: Lua script for controlling humidity in the bathroom

Posted: Monday 11 November 2019 20:39
by Dekereluitherel
Hi waaren,

This is my script.

Code: Select all

--[[
 
This script controls the humidity in a typical bathroom setting by detecting
relative rises in humidity in a short period.
Of course it requires a humidity sensor and a binary switch controlling a fan/ventilator.
(there is no provision for variable speed ventilators here!)
 
How it works (assuming the default constants as defined below):
Every 5 minutes a reading is done. Every reading is stored together
with the previous reading and is stored in two user variables (humidityTmin5 and humidityTmin10).
So it has two reading over the past 10 minutes.
It then takes the lowest of the two and compares it with the latest reading and
calculates a delta.
If the delta is 3 or higher (see constants) then the fan will be turned
on, it calculates the target humidity and the 'humidity-decrease program' is started (fanFollowsProgram=1).
From then on, every 5 minutes the current humidity is compared to the
stored target humidity. Basically if that target is reached, the fan is turned off
and the 'program' is ended.
Of course, it is possible that the target is never reached (might start raining outside
or whatever). Then there is a failsafe (FAN_MAX_TIME) after which the ventilator
will be turned off.
 
Also, it will detect if the ventilator is manually switched off during a program
or when it is switched on before the program starts.
 
Along the lines it prints to the log and sends notifications
but of course you can turn that off by removing those lines.
 
--]]
 
commandArray = {}
 
-- declare some constants
-- adjust to your specific situation
SAMPLE_INTERVAL = 5                 -- time in minutes when a the script logic will happen
FAN_DELTA_TRIGGER = 3               -- rise in humidity that will trigger the fan
FAN_MAX_TIME = 15                   --  maximum amount of sample cycles the fan can be on, 
                                    -- in case we never reach the target humidity
TARGET_OFFSET = 5                -- ventilator goes off if target+offset is reached 
                                    -- (maybe it takes too long to reach the true target due to wet towels etc)
FAN_NAME = 'ventilatie percentage'    -- exact device name of the switch turning on/off the ventilator
SENSOR_NAME = 'luchtvochtigheid badkamer'     -- exact device name of the humidity sensor
TEST_MODE = false                   -- when true TEST_MODE_HUMVAR is used instead of the real sensor
TEST_MODE_HUMVAR = 'testHumidity'   -- fake humidity value, give it a test value in domoticz/uservars
PRINT_MODE = true					-- when true wil print output to log and send notifications

if PRINT_MODE == true then
print('Fan control')
end

-- get the global variables:
-- this script runs every minute, humCounter is used to create SAMPLE_INTERVAL periods
humCounter = tonumber(uservariables['humCounter'])
humidityTmin5 = tonumber(uservariables['humidityTmin5'])                -- youngest reading
humidityTmin10 = tonumber(uservariables['humidityTmin10'])              -- oldest reading
targetFanOffHumidity = tonumber(uservariables['targetFanOffHumidity'])  -- target humidity
fanMaxTimer = tonumber(uservariables['fanMaxTimer'])
fanFollowsProgram = tonumber(uservariables['fanFollowsProgram'])        -- marker indicating that the 
                                                                        -- decrease program is started
 
target = 0 -- will hold the target humidity when the program starts
 
-- get the current humidity value
if (TEST_MODE) then
    current = tonumber(uservariables[TEST_MODE_HUMVAR])
else
    current = otherdevices_humidity[SENSOR_NAME]
end
 
-- check if the sensor is on or has some weird reading
if (current == 0 or current == nil) then
    print('current is 0 or nil. Skipping this reading')
    return commandArray
end

if PRINT_MODE == true then
        print('Current humidity:' .. current)
		print('targetFanOffHumidity:' .. targetFanOffHumidity)
		print('humidityTmin5: ' .. humidityTmin5)
		print('humidityTmin10: ' .. humidityTmin10)
		print('fanMaxTimer: ' .. fanMaxTimer)
		print('humCounter:' .. humCounter)
		print('fanFollowsProgram:' .. fanFollowsProgram)
end

-- increase cycle counter
humCounter = humCounter + 1
 
if (humCounter >= SAMPLE_INTERVAL) then
 
    if (humidityTmin5 == 0) then
        -- initialization, assume this is the first time
        humidityTmin5 = current
        humidityTmin10 = current
    end
 
    humCounter = 0 -- reset the cycle counter
 
    -- pick the lowest history value to calculate the delta
    -- this also makes sure that two relative small deltas in the past 2*interval minutes are treated as one larger rise
    -- and therefore will still trigger the ventilator
    -- I don't want to use a longer interval instead because I want the ventilator to start as soon as possible
    -- (so rather after 5 minutes instead of after 15 minutes because the mirrors in the bathroom become kinda useless ;-)
    delta = current - math.min(humidityTmin10, humidityTmin5)
if PRINT_MODE == true then
	print('Delta: ' .. delta)
end
 
    -- pick the lowest history value
    target = math.min(humidityTmin10, humidityTmin5) + TARGET_OFFSET
 
    -- shift the previous measurements
    humidityTmin10 = humidityTmin5
    -- and store the current
    humidityTmin5 = current
 
    if (otherdevices[FAN_NAME]=='Off' or (otherdevices[FAN_NAME]=='On' and fanFollowsProgram==0)) then
        -- either the fan is off or it is on but the decrease program has not started
        -- in that latter case we start the program anyway. This could happen if someone turns on the ventilator
        -- manually because he/she is about to take a shower and doesn't like damp mirrors.
        -- I don't do this because the ventilator removes heat from the bathroom and I want this to happen
        -- as late as possible ;-)
 
        if (fanFollowsProgram == 1 and otherdevices[FAN_NAME]=='Off') then
            -- likely someone turned off the ventilator while the program was running
            fanFollowsProgram = 1
        end
 
        -- see if we have to turn it on
        if (delta >= FAN_DELTA_TRIGGER) then
            -- time to start the fan
            commandArray[FAN_NAME] = 'Set Level 99'
            targetFanOffHumidity = target
 
            if (fanFollowsProgram == 1) then
                print('Ventilator was already on but we start the de-humidifying program')
            end
 
            fanFollowsProgram = 1
 
            -- set the safety stop
            fanMaxTimer = FAN_MAX_TIME
			
			if PRINT_MODE == true then
            print('Rise in humidity. Turning on the vents. Delta: ' .. delta)
            print('Target humidity for turning the ventilator: ' ..targetFanOffHumidity)
            commandArray['SendNotification'] = 'Ventilator is on#The ventilator was activated at humidity level ' .. current .. '#0'
			end
        end
 
    else
        if (fanMaxTimer > 0) then
            -- possible that someone started the ventialator manually
            fanMaxTimer = fanMaxTimer - 1
        end
 
 
        if (fanFollowsProgram == 1) then -- not manually started
 
            if (delta >= FAN_DELTA_TRIGGER) then
                -- ok, there is another FAN_DELTA_TRIGGER rise in humidity
                -- when this happen we reset the fanMaxTimer to a new count down
                -- because we have to ventilate a bit longer due to the extra humidity
                if PRINT_MODE == true then
				print('Another large increase detected, resetting max timer. Delta: ' .. delta)
				end
                fanMaxTimer = FAN_MAX_TIME
            end
 
            -- first see if it can be turned off
            if (current <= targetFanOffHumidity or fanMaxTimer==0) then
                commandArray[FAN_NAME] = 'Off'
 
                msg = ''
 
                if (fanMaxTimer == 0 and current > targetFanOffHumidity) then
                    msg = 'Target not reached but safety time-out is triggered.'
                    if PRINT_MODE == true then
					print(msg)
					end
                else
                    msg = 'Target humidity reached'
                    if PRINT_MODE == true then
					print(msg)
					end
                end
 
				if PRINT_MODE == true then
                print('Turning off the ventilator')
                msg = msg .. '\nTurning off the ventilator'
				end
				
                targetFanOffHumidity = 0
                fanMaxTimer = 0
                fanFollowsProgram = 0
                -- reset history in this case.. we start all over
                -- Tmin10 is still in the 'ventilator=On'-zone
                humidityTmin10 = humidityTmin5
                 if PRINT_MODE == true then
				commandArray['SendNotification'] = 'Ventilator is off#' .. msg .. '#0'
				end
 
            else
                -- we haven't reached the target yet
               if PRINT_MODE == true then
			   print('Humidity delta: ' .. delta)
			   end
            end
        end
    end

if PRINT_MODE == true then
    print('New values >>>>>>>>>>>')
    print('humidityTmin5: ' .. humidityTmin5)
    print('humidityTmin10: ' .. humidityTmin10)
    print('fanMaxTimer: ' .. fanMaxTimer)
    print('humCounter:' .. humCounter)
    print('fanFollowsProgram:' .. fanFollowsProgram)
    print('------ target: ' .. targetFanOffHumidity)
end

end
 
-- save the globals
commandArray['Variable:humCounter'] = tostring(humCounter)
commandArray['Variable:humidityTmin10'] = tostring(humidityTmin10)
commandArray['Variable:humidityTmin5'] = tostring(humidityTmin5)
commandArray['Variable:targetFanOffHumidity'] = tostring(targetFanOffHumidity)
commandArray['Variable:fanMaxTimer'] = tostring(fanMaxTimer)
commandArray['Variable:fanFollowsProgram'] = tostring(fanFollowsProgram)
 
return commandArray

edit: removing and re-adding the variable targetFanOffHumitiy seems to fix te working of the script!

Re: Lua script for controlling humidity in the bathroom

Posted: Tuesday 12 November 2019 0:24
by waaren
waaren wrote: Tuesday 12 November 2019 0:18
tonumber('12.0') in Lua <= 5.2 returns 12
tonumber('12.0') in Lua >= 5.3 returns 12.0
can you try with this.

Code: Select all

--[[
 
This script controls the humidity in a typical bathroom setting by detecting
relative rises in humidity in a short period.
Of course it requires a humidity sensor and a binary switch controlling a fan/ventilator.
(there is no provision for variable speed ventilators here!)
 
How it works (assuming the default constants as defined below):
Every 5 minutes a reading is done. Every reading is stored together
with the previous reading and is stored in two user variables (humidityTmin5 and humidityTmin10).
So it has two reading over the past 10 minutes.
It then takes the lowest of the two and compares it with the latest reading and
calculates a delta.
If the delta is 3 or higher (see constants) then the fan will be turned
on, it calculates the target humidity and the 'humidity-decrease program' is started (fanFollowsProgram=1).
From then on, every 5 minutes the current humidity is compared to the
stored target humidity. Basically if that target is reached, the fan is turned off
and the 'program' is ended.
Of course, it is possible that the target is never reached (might start raining outside
or whatever). Then there is a failsafe (FAN_MAX_TIME) after which the ventilator
will be turned off.
 
Also, it will detect if the ventilator is manually switched off during a program
or when it is switched on before the program starts.
 
Along the lines it prints to the log and sends notifications
but of course you can turn that off by removing those lines.
 
--]]
 
commandArray = {}
 
-- declare some constants
-- adjust to your specific situation
SAMPLE_INTERVAL = 5                 -- time in minutes when a the script logic will happen
FAN_DELTA_TRIGGER = 3               -- rise in humidity that will trigger the fan
FAN_MAX_TIME = 15                   --  maximum amount of sample cycles the fan can be on, 
                                    -- in case we never reach the target humidity
TARGET_OFFSET = 5                -- ventilator goes off if target+offset is reached 
                                    -- (maybe it takes too long to reach the true target due to wet towels etc)
FAN_NAME = 'ventilatie percentage'    -- exact device name of the switch turning on/off the ventilator
SENSOR_NAME = 'luchtvochtigheid badkamer'     -- exact device name of the humidity sensor
TEST_MODE = false                   -- when true TEST_MODE_HUMVAR is used instead of the real sensor
TEST_MODE_HUMVAR = 'testHumidity'   -- fake humidity value, give it a test value in domoticz/uservars
PRINT_MODE = true                    -- when true wil print output to log and send notifications

if PRINT_MODE == true then
print('Fan control')
end

local function toInteger(str)
    return math.floor(str)
end

-- get the global variables:
-- this script runs every minute, humCounter is used to create SAMPLE_INTERVAL periods
humCounter = toInteger(uservariables['humCounter'])
humidityTmin5 = toInteger(uservariables['humidityTmin5'])                -- youngest reading
humidityTmin10 = toInteger(uservariables['humidityTmin10'])              -- oldest reading
targetFanOffHumidity = toInteger(uservariables['targetFanOffHumidity'])  -- target humidity
fanMaxTimer = toInteger(uservariables['fanMaxTimer'])
fanFollowsProgram = toInteger(uservariables['fanFollowsProgram'])        -- marker indicating that the 
                                                                        -- decrease program is started
 
target = 0 -- will hold the target humidity when the program starts
 
-- get the current humidity value
if (TEST_MODE) then
    current = toInteger(uservariables[TEST_MODE_HUMVAR])
else
    current = toInteger(otherdevices_humidity[SENSOR_NAME])
end
 
-- check if the sensor is on or has some weird reading
if (current == 0 or current == nil) then
    print('current is 0 or nil. Skipping this reading')
    return commandArray
end

if PRINT_MODE == true then
        print('Current humidity:' .. current)
        print('targetFanOffHumidity:' .. targetFanOffHumidity)
        print('humidityTmin5: ' .. humidityTmin5)
        print('humidityTmin10: ' .. humidityTmin10)
        print('fanMaxTimer: ' .. fanMaxTimer)
        print('humCounter:' .. humCounter)
        print('fanFollowsProgram:' .. fanFollowsProgram)
end

-- increase cycle counter
humCounter = humCounter + 1
 
if (humCounter >= SAMPLE_INTERVAL) then
 
    if (humidityTmin5 == 0) then
        -- initialization, assume this is the first time
        humidityTmin5 = current
        humidityTmin10 = current
    end
 
    humCounter = 0 -- reset the cycle counter
 
    -- pick the lowest history value to calculate the delta
    -- this also makes sure that two relative small deltas in the past 2*interval minutes are treated as one larger rise
    -- and therefore will still trigger the ventilator
    -- I don't want to use a longer interval instead because I want the ventilator to start as soon as possible
    -- (so rather after 5 minutes instead of after 15 minutes because the mirrors in the bathroom become kinda useless ;-)
    delta = current - math.min(humidityTmin10, humidityTmin5)
if PRINT_MODE == true then
    print('Delta: ' .. delta)
end
 
    -- pick the lowest history value
    target = math.min(humidityTmin10, humidityTmin5) + TARGET_OFFSET
 
    -- shift the previous measurements
    humidityTmin10 = humidityTmin5
    -- and store the current
    humidityTmin5 = current
 
    if (otherdevices[FAN_NAME]=='Off' or (otherdevices[FAN_NAME]=='On' and fanFollowsProgram==0)) then
        -- either the fan is off or it is on but the decrease program has not started
        -- in that latter case we start the program anyway. This could happen if someone turns on the ventilator
        -- manually because he/she is about to take a shower and doesn't like damp mirrors.
        -- I don't do this because the ventilator removes heat from the bathroom and I want this to happen
        -- as late as possible ;-)
 
        if (fanFollowsProgram == 1 and otherdevices[FAN_NAME]=='Off') then
            -- likely someone turned off the ventilator while the program was running
            fanFollowsProgram = 1
        end
 
        -- see if we have to turn it on
        if (delta >= FAN_DELTA_TRIGGER) then
            -- time to start the fan
            commandArray[FAN_NAME] = 'Set Level 99'
            targetFanOffHumidity = target
 
            if (fanFollowsProgram == 1) then
                print('Ventilator was already on but we start the de-humidifying program')
            end
 
            fanFollowsProgram = 1
 
            -- set the safety stop
            fanMaxTimer = FAN_MAX_TIME
            
            if PRINT_MODE == true then
            print('Rise in humidity. Turning on the vents. Delta: ' .. delta)
            print('Target humidity for turning the ventilator: ' ..targetFanOffHumidity)
            commandArray['SendNotification'] = 'Ventilator is on#The ventilator was activated at humidity level ' .. current .. '#0'
            end
        end
 
    else
        if (fanMaxTimer > 0) then
            -- possible that someone started the ventilator manually
            fanMaxTimer = fanMaxTimer - 1
        end
 
 
        if (fanFollowsProgram == 1) then -- not manually started
 
            if (delta >= FAN_DELTA_TRIGGER) then
                -- ok, there is another FAN_DELTA_TRIGGER rise in humidity
                -- when this happen we reset the fanMaxTimer to a new count down
                -- because we have to ventilate a bit longer due to the extra humidity
                if PRINT_MODE == true then
                print('Another large increase detected, resetting max timer. Delta: ' .. delta)
                end
                fanMaxTimer = FAN_MAX_TIME
            end
 
            -- first see if it can be turned off
            if (current <= targetFanOffHumidity or fanMaxTimer==0) then
                commandArray[FAN_NAME] = 'Off'
 
                msg = ''
 
                if (fanMaxTimer == 0 and current > targetFanOffHumidity) then
                    msg = 'Target not reached but safety time-out is triggered.'
                    if PRINT_MODE == true then
                    print(msg)
                    end
                else
                    msg = 'Target humidity reached'
                    if PRINT_MODE == true then
                    print(msg)
                    end
                end
 
                if PRINT_MODE == true then
                print('Turning off the ventilator')
                msg = msg .. '\nTurning off the ventilator'
                end
                
                targetFanOffHumidity = 0
                fanMaxTimer = 0
                fanFollowsProgram = 0
                -- reset history in this case.. we start all over
                -- Tmin10 is still in the 'ventilator=On'-zone
                humidityTmin10 = humidityTmin5
                 if PRINT_MODE == true then
                commandArray['SendNotification'] = 'Ventilator is off#' .. msg .. '#0'
                end
 
            else
                -- we haven't reached the target yet
               if PRINT_MODE == true then
               print('Humidity delta: ' .. delta)
               end
            end
        end
    end

if PRINT_MODE == true then
    print('New values >>>>>>>>>>>')
    print('humidityTmin5: ' .. humidityTmin5)
    print('humidityTmin10: ' .. humidityTmin10)
    print('fanMaxTimer: ' .. fanMaxTimer)
    print('humCounter:' .. humCounter)
    print('fanFollowsProgram:' .. fanFollowsProgram)
    print('------ target: ' .. targetFanOffHumidity)
end

end
 
-- save the globals
commandArray['Variable:humCounter'] = tostring(humCounter)
commandArray['Variable:humidityTmin10'] = tostring(humidityTmin10)
commandArray['Variable:humidityTmin5'] = tostring(humidityTmin5)
commandArray['Variable:targetFanOffHumidity'] = tostring(targetFanOffHumidity)
commandArray['Variable:fanMaxTimer'] = tostring(fanMaxTimer)
commandArray['Variable:fanFollowsProgram'] = tostring(fanFollowsProgram)
 
return commandArray

Re: Lua script for controlling humidity in the bathroom

Posted: Wednesday 13 November 2019 21:17
by Dekereluitherel
Waaren, thanx for your time. but see edit in my previous post.
i fixed the problem bij re-adding the variable in domoticz. (and making it a string)
the scrips works like a charm again!
waaren wrote: Tuesday 12 November 2019 0:18 tonumber('12.0') in Lua <= 5.2 returns 12
tonumber('12.0') in Lua >= 5.3 returns 12.0

Re: Lua script for controlling humidity in the bathroom

Posted: Wednesday 13 November 2019 21:28
by waaren
Dekereluitherel wrote: Wednesday 13 November 2019 21:17 I fixed the problem bij re-adding the variable in domoticz. (and making it a string)
the scrips works like a charm again!
Good to read it is solved.
Reason why I replied anyway is that this type of problem might well affect other Lua scripts comparing integers with floats.

Re: Lua script for controlling humidity in the bathroom

Posted: Tuesday 17 December 2019 20:02
by RikkerdNL
I have searched this topic, but could the script also use FAN_NAME = for a ifttt trigger? I have unflashed sonoff using IFTTT as power switch.

I think I solved it with the solution from post: https://www.domoticz.com/forum/viewtopi ... 87#p175921 it created a dummy switch that will function with ifttt

Re: Lua script for controlling humidity in the bathroom

Posted: Sunday 30 August 2020 19:07
by Jasper79
Hi,

I tried to control the bathroom fan with Blockly and it just doesn't work. This script works though the fan is turning off way too soon.

I just took a shower and after 2 minutes the fan came on. Then little over 2 minutes later it turned off.

After me my wife went to the shower and the same thing happened, on and 2 minutes later off.

I checked the humidity sensor and it was 92%, is the script not working, did I do something wrong or can I add a backup somewhere that when humidity is above 80% it stays on?

Thanks,

Re: Lua script for controlling humidity in the bathroom

Posted: Wednesday 02 September 2020 16:01
by Jasper79
Turned on logging and the target is set ot 0 when on.

Code: Select all

2020-09-02 16:00:32.568 Status: LUA: humidityTmin10: 82.0
2020-09-02 16:00:32.568 Status: LUA: fanMaxTimer: 11
2020-09-02 16:00:32.568 Status: LUA: humCounter:4
2020-09-02 16:00:32.568 Status: LUA: fanFollowsProgram:1
2020-09-02 16:00:32.568 Status: LUA: Delta: 0.0
2020-09-02 16:00:32.568 Status: LUA: Humidity delta: 0.0
2020-09-02 16:00:32.568 Status: LUA: New values >>>>>>>>>>>
2020-09-02 16:00:32.568 Status: LUA: humidityTmin5: 82.0
2020-09-02 16:00:32.568 Status: LUA: humidityTmin10: 82.0
2020-09-02 16:00:32.568 Status: LUA: fanMaxTimer: 10
2020-09-02 16:00:32.568 Status: LUA: humCounter:0
2020-09-02 16:00:32.568 Status: LUA: fanFollowsProgram:1
2020-09-02 16:00:32.568 Status: LUA: ------ target: 0
2020-09-02 16:00:32.572 Status: EventSystem: Script event triggered: script_time_humidity
2020-09-02 16:00:32.796 Status: LUA: Fan control
2020-09-02 16:00:32.796 Status: LUA: Current humidity:82.0
2020-09-02 16:00:32.797 Status: LUA: targetFanOffHumidity:0
2020-09-02 16:00:32.797 Status: LUA: humidityTmin5: 82.0
2020-09-02 16:00:32.797 Status: LUA: humidityTmin10: 82.0
2020-09-02 16:00:32.797 Status: LUA: fanMaxTimer: 10
2020-09-02 16:00:32.797 Status: LUA: humCounter:0
2020-09-02 16:00:32.797 Status: LUA: fanFollowsProgram:1
2020-09-02 16:00:32.800 Status: EventSystem: Script event triggered: script_time_humidity
2020-09-02 16:00:32.814 Status: LUA: Fan control
2020-09-02 16:00:32.814 Status: LUA: Current humidity:82.0
2020-09-02 16:00:32.814 Status: LUA: targetFanOffHumidity:0
2020-09-02 16:00:32.814 Status: LUA: humidityTmin5: 82.0
2020-09-02 16:00:32.814 Status: LUA: humidityTmin10: 82.0
2020-09-02 16:00:32.814 Status: LUA: fanMaxTimer: 10
2020-09-02 16:00:32.814 Status: LUA: humCounter:1
2020-09-02 16:00:32.814 Status: LUA: fanFollowsProgram:1
2020-09-02 16:00:32.817 Status: EventSystem: Script event triggered: script_time_humidity
Also the counter thats set to 24 goes down very fast, I thought that are minutes??

Re: Lua script for controlling humidity in the bathroom

Posted: Wednesday 02 September 2020 18:01
by waaren
Did you save the script as time triggered?





Re: Lua script for controlling humidity in the bathroom

Posted: Wednesday 02 September 2020 18:15
by Jasper79
Thanks, that's the part I missed I think.

Re: Lua script for controlling humidity in the bathroom

Posted: Thursday 08 October 2020 11:08
by robgeisink
I'm getting these errors (first time use)...what is the problem? or should i let the script be active for some time to retrieve different data?

2020-10-08 11:05:00.234 Error: EventSystem: Error updating variable humidityTmin10: Not a valid integer
2020-10-08 11:05:00.235 Error: EventSystem: Error updating variable humidityTmin5: Not a valid integer

Re: Lua script for controlling humidity in the bathroom

Posted: Thursday 08 October 2020 11:30
by Jasper79
changing the integer to string

Manual is old.

Re: Lua script for controlling humidity in the bathroom

Posted: Thursday 08 October 2020 12:05
by waaren
Jasper79 wrote: Thursday 08 October 2020 11:30 Manual is old.
Updated the wiki page with a last known working version.

Re: Lua script for controlling humidity in the bathroom

Posted: Thursday 08 October 2020 12:10
by robgeisink
No more errors,
But my fan won't go on...i thought i had the correct vallues
Counter keeps resetting

Status: LUA: Automatisch Keukenspotjes Aan
2020-10-08 12:09:00.593 Status: LUA: Fan control
2020-10-08 12:09:00.593 Status: LUA: Current humidity:74.0
2020-10-08 12:09:00.593 Status: LUA: targetFanOffHumidity:67
2020-10-08 12:09:00.593 Status: LUA: humidityTmin5: 74.0
2020-10-08 12:09:00.593 Status: LUA: humidityTmin10: 74.0
2020-10-08 12:09:00.593 Status: LUA: fanMaxTimer: 0
2020-10-08 12:09:00.593 Status: LUA: humCounter:0
2020-10-08 12:09:00.593 Status: LUA: fanFollowsProgram:0

So it stays op program 0 and counter keeps going round and reset. so it never switches on, not even when humidity is way above target (67)
And another log writing:

Status: LUA: Fan control
2020-10-08 12:20:00.523 Status: LUA: Current humidity:74.0
2020-10-08 12:20:00.523 Status: LUA: targetFanOffHumidity:67
2020-10-08 12:20:00.523 Status: LUA: humidityTmin5: 74.0
2020-10-08 12:20:00.523 Status: LUA: humidityTmin10: 74.0
2020-10-08 12:20:00.524 Status: LUA: fanMaxTimer: 0
2020-10-08 12:20:00.524 Status: LUA: humCounter:3
2020-10-08 12:20:00.524 Status: LUA: fanFollowsProgram:0
2020-10-08 12:20:00.524 Status: LUA: Delta: 0.0
2020-10-08 12:20:00.524 Status: LUA: New values >>>>>>>>>>>
2020-10-08 12:20:00.524 Status: LUA: humidityTmin5: 74.0
2020-10-08 12:20:00.524 Status: LUA: humidityTmin10: 74.0
2020-10-08 12:20:00.524 Status: LUA: fanMaxTimer: 0
2020-10-08 12:20:00.524 Status: LUA: humCounter:0
2020-10-08 12:20:00.524 Status: LUA: fanFollowsProgram:0
2020-10-08 12:20:00.524 Status: LUA: ------ target: 67

Re: Lua script for controlling humidity in the bathroom

Posted: Thursday 08 October 2020 12:28
by waaren
robgeisink wrote: Thursday 08 October 2020 12:10 No more errors,
But my fan won't go on...i thought i had the correct vallues
From the commentLines:
If the delta is 3 or higher (see constants) then the fan will be turned on
The start of the Fan is not controlled by the humidity as such but by looking at the delta humidity. Your delta is 0 so Fan will not start.

Re: Lua script for controlling humidity in the bathroom

Posted: Thursday 08 October 2020 12:30
by Jasper79
waaren wrote: Thursday 08 October 2020 12:05
Jasper79 wrote: Thursday 08 October 2020 11:30 Manual is old.
Updated the wiki page with a last known working version.
Was looking at a other online version. Thought that was wat he followed according to the error message given.

Re: Lua script for controlling humidity in the bathroom

Posted: Saturday 03 April 2021 14:52
by Hcroij
This thing is killing me

Used the latest script from wiki https://www.domoticz.com/wiki/Humidity_control
But this time getting the error
script_time_humidity.lua:61: bad argument #1 to 'floor' (number expected, got nil)

Line 61 represents the line in the script
59 -- Function added to overcome compatibility problem between Lua version 5.2 an 5.3
60 local function toInteger(str)
61 return math.floor(str)
62 end


Anyone can offer some help with this ?

Re: Lua script for controlling humidity in the bathroom

Posted: Saturday 03 April 2021 16:20
by Jasper79
I think you changed something to "floor" because I don't remember that being in the script?

Re: Lua script for controlling humidity in the bathroom

Posted: Saturday 03 April 2021 20:40
by Hcroij
@Jasper
Its in the script.
The Wiki script on line 61 on the waaren script (few posts above) its around line 52 or so.

On wiki it says

-- Function added to overcome compatibility problem between Lua version 5.2 an 5.3
local function toInteger(str)
return math.floor(str)
end