Lua script for controlling humidity in the bathroom Topic is solved

Moderator: leecollings

Post Reply
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Lua script for controlling humidity in the bathroom

Post 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
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
proohu01
Posts: 95
Joined: Friday 17 October 2014 12:20
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Lua script for controlling humidity in the bathroom

Post 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!
Pi 2 B | Pi Camera | PiFace 2 | RFXtrx433E (KaKu + Oregon Scientific) | Plugwise (9 Circles) | Aeon Z-Wave stick (Fibaro - dimmers, sockets, RGB, screens/blinds) | RFXMeter (Kwh/water/gaz) | WOL | Onkyo Receiver | RTC | Hikvision | Netatmo | Satel Integra
User avatar
proohu01
Posts: 95
Joined: Friday 17 October 2014 12:20
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Lua script for controlling humidity in the bathroom

Post 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
Pi 2 B | Pi Camera | PiFace 2 | RFXtrx433E (KaKu + Oregon Scientific) | Plugwise (9 Circles) | Aeon Z-Wave stick (Fibaro - dimmers, sockets, RGB, screens/blinds) | RFXMeter (Kwh/water/gaz) | WOL | Onkyo Receiver | RTC | Hikvision | Netatmo | Satel Integra
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Lua script for controlling humidity in the bathroom

Post 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 :)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
proohu01
Posts: 95
Joined: Friday 17 October 2014 12:20
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by proohu01 »

Woops. My lua file started with "script_device_*". I renamed it to "script_time_*".
Pi 2 B | Pi Camera | PiFace 2 | RFXtrx433E (KaKu + Oregon Scientific) | Plugwise (9 Circles) | Aeon Z-Wave stick (Fibaro - dimmers, sockets, RGB, screens/blinds) | RFXMeter (Kwh/water/gaz) | WOL | Onkyo Receiver | RTC | Hikvision | Netatmo | Satel Integra
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by dannybloe »

Yes, that helps a lot :mrgreen:
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
rron
Posts: 247
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: Lua script for controlling humidity in the bathroom

Post 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?
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by dannybloe »

You have to create them yourself. I added that to the installation instructions.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
rron
Posts: 247
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: Lua script for controlling humidity in the bathroom

Post 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.
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Lua script for controlling humidity in the bathroom

Post 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?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
rron
Posts: 247
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: Lua script for controlling humidity in the bathroom

Post 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.
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Lua script for controlling humidity in the bathroom

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
rron
Posts: 247
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: Lua script for controlling humidity in the bathroom

Post 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.
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
vmb
Posts: 26
Joined: Thursday 02 October 2014 14:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post 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.
User avatar
proohu01
Posts: 95
Joined: Friday 17 October 2014 12:20
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Lua script for controlling humidity in the bathroom

Post 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!
Pi 2 B | Pi Camera | PiFace 2 | RFXtrx433E (KaKu + Oregon Scientific) | Plugwise (9 Circles) | Aeon Z-Wave stick (Fibaro - dimmers, sockets, RGB, screens/blinds) | RFXMeter (Kwh/water/gaz) | WOL | Onkyo Receiver | RTC | Hikvision | Netatmo | Satel Integra
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by dannybloe »

Ah nice. Good to hear it is working.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
roblom
Posts: 408
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by roblom »

What kind of sensor are you using?
User avatar
proohu01
Posts: 95
Joined: Friday 17 October 2014 12:20
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Lua script for controlling humidity in the bathroom

Post 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.
Pi 2 B | Pi Camera | PiFace 2 | RFXtrx433E (KaKu + Oregon Scientific) | Plugwise (9 Circles) | Aeon Z-Wave stick (Fibaro - dimmers, sockets, RGB, screens/blinds) | RFXMeter (Kwh/water/gaz) | WOL | Onkyo Receiver | RTC | Hikvision | Netatmo | Satel Integra
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Lua script for controlling humidity in the bathroom

Post 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)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Skippiemanz
Posts: 230
Joined: Sunday 14 July 2013 20:21
Target OS: Linux
Domoticz version: 4.10233
Location: Alkmaar, The Netherlands
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by Skippiemanz »

Works like a champ thanks! Replaced my old blockly event with it!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest