Lua script for controlling humidity in the bathroom Topic is solved
Moderator: leecollings
-
- Posts: 3
- Joined: Tuesday 15 January 2019 22:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua script for controlling humidity in the bathroom
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?
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?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Lua script for controlling humidity in the bathroom
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.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?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 3
- Joined: Tuesday 15 January 2019 22:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua script for controlling humidity in the bathroom
Hi waaren,
This is my script.
edit: removing and re-adding the variable targetFanOffHumitiy seems to fix te working of the script!
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!
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Lua script for controlling humidity in the bathroom
waaren wrote: ↑Tuesday 12 November 2019 0:18can you try with this.tonumber('12.0') in Lua <= 5.2 returns 12
tonumber('12.0') in Lua >= 5.3 returns 12.0
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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 3
- Joined: Tuesday 15 January 2019 22:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua script for controlling humidity in the bathroom
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!
i fixed the problem bij re-adding the variable in domoticz. (and making it a string)
the scrips works like a charm again!
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Lua script for controlling humidity in the bathroom
Good to read it is solved.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!
Reason why I replied anyway is that this type of problem might well affect other Lua scripts comparing integers with floats.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 1
- Joined: Tuesday 17 December 2019 19:59
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Lua script for controlling humidity in the bathroom
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
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
-
- Posts: 85
- Joined: Sunday 26 July 2020 8:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: Lua script for controlling humidity in the bathroom
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,
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,
- Attachments
-
- Screenshot_20200830-190641_Chrome.png (376.8 KiB) Viewed 5599 times
-
- Screenshot_20200830-190342_Chrome.png (360.21 KiB) Viewed 5599 times
-
- Posts: 85
- Joined: Sunday 26 July 2020 8:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: Lua script for controlling humidity in the bathroom
Turned on logging and the target is set ot 0 when on.
Also the counter thats set to 24 goes down very fast, I thought that are minutes??
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
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Lua script for controlling humidity in the bathroom
Did you save the script as time triggered?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 85
- Joined: Sunday 26 July 2020 8:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: Lua script for controlling humidity in the bathroom
Thanks, that's the part I missed I think.
-
- Posts: 7
- Joined: Wednesday 27 May 2020 13:47
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua script for controlling humidity in the bathroom
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
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
-
- Posts: 85
- Joined: Sunday 26 July 2020 8:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: Lua script for controlling humidity in the bathroom
changing the integer to string
Manual is old.
Manual is old.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Lua script for controlling humidity in the bathroom
Updated the wiki page with a last known working version.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 7
- Joined: Wednesday 27 May 2020 13:47
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua script for controlling humidity in the bathroom
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
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
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Lua script for controlling humidity in the bathroom
From the commentLines: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
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.If the delta is 3 or higher (see constants) then the fan will be turned on
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 24
- Joined: Sunday 27 November 2016 16:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua script for controlling humidity in the bathroom
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 ?
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 ?
-
- Posts: 85
- Joined: Sunday 26 July 2020 8:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: Lua script for controlling humidity in the bathroom
I think you changed something to "floor" because I don't remember that being in the script?
-
- Posts: 24
- Joined: Sunday 27 November 2016 16:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua script for controlling humidity in the bathroom
@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
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
Who is online
Users browsing this forum: No registered users and 1 guest