Page 1 of 8
Lua script for controlling humidity in the bathroom
Posted: Wednesday 17 December 2014 16:36
by dannybloe
Hi people,
I created a wiki page with a Lua script that I wrote (and have been using for a while to test) for controlling humidity levels in a bathroom using a sensor and a ventilator. It detects sudden rises of humidity and when that happens it starts the ventilator until the pre-rise level has been reached.
So, in case you have been looking for something like this: enjoy
http://www.domoticz.com/wiki/Humidity_control
Re: Lua script for controlling humidity in the bathroom
Posted: Thursday 18 December 2014 12:37
by proohu01
I created a script for the verry same purpose just a week ago. My script is not nearly as good as the one you created. I will give this a try. Thanks for sharing!
Re: Lua script for controlling humidity in the bathroom
Posted: Friday 19 December 2014 8:39
by proohu01
The script works but it seems to run every x seconds instead of every 5 minutes. Thus, the fanMaxTimer is reached in just a couple of minutes. What am I doing wrong?
Log:
Code: Select all
2014-12-19 08:32:30 Script event triggered: /home/pi/domoticz/scripts/lua/script_device_switch-ventilator-onoff_v2.lua
2014-12-19 08:32:31 LUA: Fan control
2014-12-19 08:32:31 LUA: Current humidity:80
2014-12-19 08:32:31 LUA: targetFanOffHumidity:52
2014-12-19 08:32:31 LUA: humidityTmin5: 80
2014-12-19 08:32:31 LUA: humidityTmin10: 80
2014-12-19 08:32:31 LUA: fanMaxTimer: 8
2014-12-19 08:32:31 LUA: humCounter:3
2014-12-19 08:32:31 LUA: fanFollowsProgram:1
2014-12-19 08:32:31 Script event triggered: /home/pi/domoticz/scripts/lua/script_device_switch-ventilator-onoff_v2.lua
2014-12-19 08:32:32 LUA: Fan control
2014-12-19 08:32:32 LUA: Current humidity:80
2014-12-19 08:32:32 LUA: targetFanOffHumidity:52
2014-12-19 08:32:32 LUA: humidityTmin5: 80
2014-12-19 08:32:32 LUA: humidityTmin10: 80
2014-12-19 08:32:32 LUA: fanMaxTimer: 7
2014-12-19 08:32:32 LUA: humCounter:0
2014-12-19 08:32:32 LUA: fanFollowsProgram:1
Re: Lua script for controlling humidity in the bathroom
Posted: Friday 19 December 2014 9:04
by dannybloe
It should run every minute but only after the humCounter variable is 5 (SAMPLE_INTERVAL) then it does processing. That is because domoticz can only run timer scripts every minute. So every minute it adds 1 to the humCounter and when humCounter == SAMPLE_INTERVAL it does its checking. Make sure that SAMPLE_INTERVAL is higher than 1 (minute). I have it set at 5. fanMaxTimer is also decreased every 5 minutes but of course only when the program is running. See the code, it is not hard to read (I think

)
It does however print out the variables every minute. Just for debugging purposes.
Hope this helps.
Let me know

Re: Lua script for controlling humidity in the bathroom
Posted: Friday 19 December 2014 9:12
by proohu01
Woops. My lua file started with "script_device_*". I renamed it to "script_time_*".
Re: Lua script for controlling humidity in the bathroom
Posted: Friday 19 December 2014 9:17
by dannybloe
Yes, that helps a lot

Re: Lua script for controlling humidity in the bathroom
Posted: Monday 22 December 2014 9:43
by rron
dannybloe wrote:Hi people,
I created a wiki page with a Lua script that I wrote (and have been using for a while to test) for controlling humidity levels in a bathroom using a sensor and a ventilator. It detects sudden rises of humidity and when that happens it starts the ventilator until the pre-rise level has been reached.
So, in case you have been looking for something like this: enjoy
http://www.domoticz.com/wiki/Humidity_control
Do you have to fill in those user variables yourself or is the script doing this?
Re: Lua script for controlling humidity in the bathroom
Posted: Monday 22 December 2014 16:38
by dannybloe
You have to create them yourself. I added that to the installation instructions.
Re: Lua script for controlling humidity in the bathroom
Posted: Monday 22 December 2014 21:20
by rron
dannybloe wrote:You have to create them yourself. I added that to the installation instructions.
Ok can you give me an example what you are using? I have filed in some value's but that didn't work out for me.
Re: Lua script for controlling humidity in the bathroom
Posted: Monday 22 December 2014 21:58
by dannybloe
Well, the user variables only have to be created as stated in the wiki page (name and type and initial value (0 will do)). These variables get their values from the script itself so you don't have to worry about that. The script has a couple of constants (upper-case variables). Some of them you have to set like the name of your devices. All of them have a clear explanation ("Use the source Luke"). The values in them are the ones that I use and they seem to work just fine.
Does that help?
Re: Lua script for controlling humidity in the bathroom
Posted: Monday 22 December 2014 22:09
by rron
dannybloe wrote:Well, the user variables only have to be created as stated in the wiki page (name and type and initial value (0 will do)). These variables get their values from the script itself so you don't have to worry about that. The script has a couple of constants (upper-case variables). Some of them you have to set like the name of your devices. All of them have a clear explanation ("Use the source Luke"). The values in them are the ones that I use and they seem to work just fine.
Does that help?
I only changed the user value targetFannOffHumidity to 60%. The rest i left alone and this is what happened:
Mon Dec 22 22:02:00 2014 LUA: Fan control
Mon Dec 22 22:02:00 2014 LUA: Current humidity:70
Mon Dec 22 22:02:00 2014 LUA: targetFanOffHumidity:60
Mon Dec 22 22:02:00 2014 LUA: humidityTmin5: 68
Mon Dec 22 22:02:00 2014 LUA: humidityTmin10: 56
Mon Dec 22 22:02:00 2014 LUA: fanMaxTimer: 4
Mon Dec 22 22:02:00 2014 LUA: humCounter:4
Mon Dec 22 22:02:00 2014 LUA: fanFollowsProgram:0
Mon Dec 22 22:02:00 2014 LUA: Delta: 14
Mon Dec 22 22:02:00 2014 LUA: New values >>>>>>>>>>>
Mon Dec 22 22:02:00 2014 LUA: humidityTmin5: 70
Mon Dec 22 22:02:00 2014 LUA: humidityTmin10: 68
Mon Dec 22 22:02:00 2014 LUA: fanMaxTimer: 3
Mon Dec 22 22:02:00 2014 LUA: humCounter:0
Mon Dec 22 22:02:00 2014 LUA: fanFollowsProgram:0
Mon Dec 22 22:02:00 2014 LUA: ------ target: 60
The fan wich I renamed to my own switch name didn't switch on
I think I see the problem, the name off the swich i miss typed! I will try again.
Re: Lua script for controlling humidity in the bathroom
Posted: Monday 22 December 2014 22:33
by dannybloe
Like I said: create the variables and initialize them to 0. The script takes care of the rest. These variables are there to carry along information between each script-run. Don't set any values there yourself. So, please set them all to 0 as if you just created them. Then watch the logs as the script runs each minute. It will initialize some values and then start increasing the humCounter until it reaches the sample interval amount. Then it will calculated deltas etc and decide to turn on the ventilator.
Re: Lua script for controlling humidity in the bathroom
Posted: Tuesday 23 December 2014 7:30
by rron
dannybloe wrote:Like I said: create the variables and initialize them to 0. The script takes care of the rest. These variables are there to carry along information between each script-run. Don't set any values there yourself. So, please set them all to 0 as if you just created them. Then watch the logs as the script runs each minute. It will initialize some values and then start increasing the humCounter until it reaches the sample interval amount. Then it will calculated deltas etc and decide to turn on the ventilator.
Thank you for your answer. I will follow your advise. Like i said yesterday i made a mistake in the renaming off the fan switch. I will try tonight again.
Re: Lua script for controlling humidity in the bathroom
Posted: Tuesday 23 December 2014 13:19
by vmb
Thx! Was searching already a few months for a script like this. I tried something like this with blockly's but ended up in a ventilator that keeps running because of the humidity that won't go down because of rain and a moisty bathroom.
Will inform you about my experiences with the script.
Re: Lua script for controlling humidity in the bathroom
Posted: Tuesday 23 December 2014 14:09
by proohu01
I've been using it for a couple of days now and I am happy to say, it work PERFECT! Friday was a rainy day so I was already able to test that part. Thanks again for sharing!
Re: Lua script for controlling humidity in the bathroom
Posted: Thursday 25 December 2014 16:40
by dannybloe
Ah nice. Good to hear it is working.
Re: Lua script for controlling humidity in the bathroom
Posted: Thursday 25 December 2014 20:15
by roblom
What kind of sensor are you using?
Re: Lua script for controlling humidity in the bathroom
Posted: Thursday 25 December 2014 21:07
by proohu01
I use the very cheap one from this post:
http://www.domoticz.com/forum/viewtopic.php?f=30&t=3800 I ordered two and only use one at the moment.
Re: Lua script for controlling humidity in the bathroom
Posted: Friday 26 December 2014 9:24
by dannybloe
I have the Aeon Multi Sensor (usb powered) hanging on the ceiling of the bathroom and a zwave plug connected to the ventilator.
(I was hoping I could use the sensor's motion sensor as well for controlling the light but it doesn't detect movement when you are in the shower)
Re: Lua script for controlling humidity in the bathroom
Posted: Saturday 27 December 2014 15:04
by Skippiemanz
Works like a champ thanks! Replaced my old blockly event with it!