Page 2 of 8
Re: Lua script for controlling humidity in the bathroom
Posted: Saturday 27 December 2014 15:54
by Hendrik
dannybloe wrote: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)
You can set the time, the senosor is on, when it see motion, the sensor stay on for .. minutes
how can i make easely the same lua script, but then with motion
i would alse switch the vent on time, my vent has two speed levels
i would set the low speed on time, and the high speed with this script, is this possible in lua?
Re: Lua script for controlling humidity in the bathroom
Posted: Saturday 27 December 2014 17:35
by Wirehead
I added a variable
Code: Select all
HEAT_NAME = 'Badkamer - verwarming'
Then on line 164 I added:
This should take care of turning off the bathroom heating as well, right?
I have no need for it to turn it on. It's usually on by timer
- but keeping it on until humidity has dropped helps a great deal with getting the humidity out.
Edit: worked like a charm.. The notifications are a nice touch (using Prowl here)
The maximum time a fan could run, would be approximately SAMPLE_INTERVAL x FAN_MAX_TIME. So if the interval is 5; and fan_max_time is 24. One could have his fan running 5x24 = 120 minutes
Edit2: I also liked to know in the notification at what level the fan/heat was turned off; so I changed the "turning off the ventilator" notification to:
Code: Select all
msg = msg .. '\nTurning off the ventilator at level ' .. current .. '#0'
Re: Lua script for controlling humidity in the bathroom
Posted: Monday 29 December 2014 22:10
by floris74
Hi,
it looks like the perfect script in a situation when you have 1 fan for 1 room. I have 1 fan for more then one room; bathroom, toilet, and kitchen. Can i use this script for this: when i turn on my fan (manually/blockly)when iḿ cooking for couple of hours and then turn of the fan (manually/blockly). Or will your script turn of the fan after a maximum time?
Floris
Re: Lua script for controlling humidity in the bathroom
Posted: Monday 29 December 2014 23:34
by webster
This script runs the fan for a max time and then turns the fan off
i use this script and it's works perfect you could extend the max time so the fan will run longer
Re: Lua script for controlling humidity in the bathroom
Posted: Tuesday 30 December 2014 11:02
by dannybloe
Hendrik wrote:You can set the time, the senosor is on, when it see motion, the sensor stay on for .. minutes
The problem is that I don't want an on-time that is long. Just half a minute or so. That doesn't work when taking a shower since that usually takes longer.
Hendrik wrote:how can i make easely the same lua script, but then with motion
i would alse switch the vent on time, my vent has two speed levels
i would set the low speed on time, and the high speed with this script, is this possible in lua?
I'm not sure I understand you correctly. But you can adapt the script that it checks if the ventilator is already on (at that lower speed) and then initiate the high-speed.
But why would you want to turn it on if there is no humidity-rise in the first place?
I would not use this script with variable speed though.. My idea is to lower the humidity as fast as possible then turn off. No need then to use different speeds.
Unless of course the ventilator is not for the bathroom alone.
Re: Lua script for controlling humidity in the bathroom
Posted: Tuesday 30 December 2014 11:09
by dannybloe
floris74 wrote:Hi,
it looks like the perfect script in a situation when you have 1 fan for 1 room. I have 1 fan for more then one room; bathroom, toilet, and kitchen. Can i use this script for this: when i turn on my fan (manually/blockly)when iḿ cooking for couple of hours and then turn of the fan (manually/blockly). Or will your script turn of the fan after a maximum time?
Yes you can. I had something like that before when it only started the de-humid program when the ventilator was not already on. I changed that later on so that I can turn the ventilator on manually in anticipation (to make sure the mirrors are not damp because the script has a start-delay of a couple of minutes). The problem by turning on the vents earlier is that it sucks warm air away so I never turn on the switch too early.
But you can adapt the script:
Code: Select all
if (otherdevices[FAN_NAME]=='Off' or (otherdevices[FAN_NAME]=='On' and fanFollowsProgram==0)) then
This line detects if the fan is on but not due to the de-humidify program (fanFollowsProgram == 0). If you change it to:
Code: Select all
if (otherdevices[FAN_NAME]=='Off') then
Then the program only starts if the fan isn't already on.
Re: Lua script for controlling humidity in the bathroom
Posted: Tuesday 30 December 2014 11:15
by dannybloe
Wirehead wrote:I added a variable
Code: Select all
HEAT_NAME = 'Badkamer - verwarming'
Then on line 164 I added:
This should take care of turning off the bathroom heating as well, right?
I have no need for it to turn it on. It's usually on by timer
- but keeping it on until humidity has dropped helps a great deal with getting the humidity out.
Yup. That could make sense. I think though that you would see a (small) rise in humidity as soon as the bathroom cools down (cold air can hold less humidity than warm air so the percentage will rise). And... now that I think of it... you do suck all the heat out of the room when the ventilator is turning.. maybe not so good idea energy-wise?
But.. the proof of the pudding is in the eating: try it with and without the heater and check the curves
Re: Lua script for controlling humidity in the bathroom
Posted: Tuesday 30 December 2014 11:18
by dannybloe
webster wrote:This script runs the fan for a max time and then turns the fan off
i use this script and it's works perfect you could extend the max time so the fan will run longer
Of course the max-time in the script is there for when the target humidity level isn't reached. But ideally it should reach it. I have had situations where multiple people took a shower in a sequence while at the same time the heater in the bathroom was turned off due to a thermostat cv-program. So the temperature was lower when everybody was done. That means that relative humidity is always higher. In that situation it just turned off after the max-time.
Re: Lua script for controlling humidity in the bathroom
Posted: Tuesday 30 December 2014 11:24
by dannybloe
Wirehead wrote:
The maximum time a fan could run, would be approximately SAMPLE_INTERVAL x FAN_MAX_TIME. So if the interval is 5; and fan_max_time is 24. One could have his fan running 5x24 = 120 minutes
Yes, that is correct:
Code: Select all
FAN_MAX_TIME = 24 -- maximum amount of sample cycles the fan can be on,
I deliberately control this in the script because the counter is reset as soon as a new humidity increase is detected. In that case it starts the max time count-down again.
Code: Select all
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
print('Another large increase detected, resetting max timer. Delta: ' .. delta)
fanMaxTimer = FAN_MAX_TIME
end
Re: Lua script for controlling humidity in the bathroom
Posted: Tuesday 30 December 2014 14:53
by floris74
Hi, thanks. but i've now the next error in my log:
2014-12-30 14:52:00 Error: ...loris/domoticz/scripts/lua/script_time_humidity_huis.lua:111: ')' expected near 'then'
worked it out; changed it into;
if (otherdevices[FAN_NAME]=='Off' and fanFollowsProgram==0) then
(i guess this is now correct??)
edit; i think i'm gonna have a problem when there is somebody is going to shower at the end of my Fan stand at the end of coocking. maybe i'll turn it back to the original line...)
dannybloe wrote:
Yes you can. I had something like that before when it only started the de-humid program when the ventilator was not already on. I changed that later on so that I can turn the ventilator on manually in anticipation (to make sure the mirrors are not damp because the script has a start-delay of a couple of minutes). The problem by turning on the vents earlier is that it sucks warm air away so I never turn on the switch too early.
But you can adapt the script:
Code: Select all
if (otherdevices[FAN_NAME]=='Off' or (otherdevices[FAN_NAME]=='On' and fanFollowsProgram==0)) then
This line detects if the fan is on but not due to the de-humidify program (fanFollowsProgram == 0). If you change it to:
Code: Select all
if (otherdevices[FAN_NAME]=='Off') then
Then the program only starts if the fan isn't already on.
Re: Lua script for controlling humidity in the bathroom
Posted: Tuesday 30 December 2014 15:02
by dannybloe
floris74 wrote:Hi, thanks. but i've now the next error in my log:
2014-12-30 14:52:00 Error: ...loris/domoticz/scripts/lua/script_time_humidity_huis.lua:111: ')' expected near 'then'
worked it out; changed it into;
if (otherdevices[FAN_NAME]=='Off' and fanFollowsProgram==0) then
(i guess this is now correct??)
I don't think you need that last part. Are you sure you pasted the code correctly? It seems you forgot a ) or you removed to much.
Re: Lua script for controlling humidity in the bathroom
Posted: Tuesday 30 December 2014 15:05
by floris74
i see it now, i missed the )
thanks! and thank you very much for this great script. i guess iḿ going to use it in my garage also, after a day surfing all my wet stuff isn't good for my garage. I only don't know if the difference in humbelty is big enough though.
FLoris
Re: Lua script for controlling humidity in the bathroom
Posted: Thursday 01 January 2015 10:51
by Hendrik
I have this script tested on my testPi, works great
now i moved it to my master, with the same variables and it didn't work
this is the reading of my sensor:
Badkamer Z 2015-01-01 10:37:54 27.1;25;1
on my testPi this works, but on my masterPi it gives the following error:
current is 0 or nil. Skipping this reading
When i try it with another sensor, with te following reading:
Badkamer 2015-01-01 10:38:32 21.0;66;1
it works like a charm.
what do i wrong with this???
Re: Lua script for controlling humidity in the bathroom
Posted: Thursday 01 January 2015 12:40
by dannybloe
Interesting... looks like it doesn't get the humidity from the sensor. So this is causing problems: otherdevices_humidity[SENSOR_NAME]. Are you really sure that SENSOR_NAME is set properly? I see "Badkamer" and "Badkamer Z".
Re: Lua script for controlling humidity in the bathroom
Posted: Thursday 01 January 2015 16:20
by Hendrik
the names are good, from the sensor "Badkamer" the readings are good (these sensor is read by the DomoticzmasterPi)
and the script works well
and from the sensor "Badkamer Z" they are not good.
the sensor "Badkamer Z' is reading with my DomoticzSlavePi, this is a Z-wave sensor.
I receive these data on my master pi, but when i set this sensor, the script doesn't works
for now i run the script on my domoticzslave Pi, it works good
now i set a virtual device on and of, and read this on my DomoticzmasterPi, and with this device, i set the fan on and of
Re: Lua script for controlling humidity in the bathroom
Posted: Thursday 01 January 2015 18:20
by dannybloe
Still looks like a zwave or domoticz problem. Not the script's. Maybe the sensor config is different. I'd create some debug scripts to see what is in the various device collections passed to the lua scripts.
Re: Lua script for controlling humidity in the bathroom
Posted: Saturday 03 January 2015 8:40
by Wirehead
dannybloe wrote:
Yup. That could make sense. I think though that you would see a (small) rise in humidity as soon as the bathroom cools down (cold air can hold less humidity than warm air so the percentage will rise). And... now that I think of it... you do suck all the heat out of the room when the ventilator is turning.. maybe not so good idea energy-wise?
But.. the proof of the pudding is in the eating: try it with and without the heater and check the curves
Well, that was the idea: warm air -> more moisture in it = keep heating "on" until humidity is gone. This way, it won't condense on the colder walls/windows. In my setup; the heating is adequate (i.e. when the ventilation is on, the temperature doesn't drop - this could be because dryer air is easier to heat).
It really works like a charm, the "reset counter on humidity rise" is also a nice touch when somebody pops in to the shower after you. There's not much to improve in this script
Lua script for controlling humidity in the bathroom
Posted: Tuesday 31 March 2015 22:40
by Skippiemanz
Script is running here for almost 2 months now. Works great. But is it possible to turn of the email notifications With a print True OR false setting?
Re: Lua script for controlling humidity in the bathroom
Posted: Thursday 02 April 2015 9:36
by dannybloe
Sure, you can modify the script in your system as you wish. Just comment out a couple of lines.
Re: Lua script for controlling humidity in the bathroom
Posted: Thursday 09 April 2015 22:06
by marten
2015-04-09 22:05:00.338 LUA: Current humidity:90
2015-04-09 22:05:00.339 Error: /home/pi/domoticz/scripts/lua/script_time_humidity.lua:75: attempt to concatenate global 'targetFanOffHumidity' (a nil value)
This is what the logfile of domoticz tells me, but i don't know what is wrong in the lua script