Lua script for controlling humidity in the bathroom Topic is solved

Moderator: leecollings

Cybertom
Posts: 10
Joined: Tuesday 13 October 2015 10:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by Cybertom »

aaahhh i get it.

I must read this in a different way. not like
(fan = off and fanfollowprogram = 0) or (fan = on and fanfollowprogram = 0)
but
(fan=off) or (fan=on and fanfollowsprogram = 0)

That make sense to me, Thanks Dannyblo :)
almirhod
Posts: 4
Joined: Sunday 03 January 2016 15:11
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by almirhod »

I have a question regarding the code below.

Code: Select all

if (fanFollowsProgram == 1 and otherdevices[FAN_NAME]=='Off') then
            -- likely someone turned off the ventilator while the program was running
            fanFollowsProgram = 0
        end
Why do you reset the program when the fan is OFF? Doesnt it make more sense to turn the fan back ON and finish the ongoing program?

Maybe I'm missing something but dont your risk that the next humidity measure is the same or lower and therefore not starting the fan at all. Best case a few degrees higher.
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 »

almirhod wrote:I have a question regarding the code below.

Code: Select all

if (fanFollowsProgram == 1 and otherdevices[FAN_NAME]=='Off') then
            -- likely someone turned off the ventilator while the program was running
            fanFollowsProgram = 0
        end
Why do you reset the program when the fan is OFF? Doesnt it make more sense to turn the fan back ON and finish the ongoing program?

Maybe I'm missing something but dont your risk that the next humidity measure is the same or lower and therefore not starting the fan at all. Best case a few degrees higher.
Well, I thought that if someone turned it off while the program was running there must have been a good reason for it. In fact, I use this 'feature' sometimes. Sometimes I don't want all the heat in the bathroom to be sucked away while I am still there and if there is not much moist then I just turn it off (in effect canceling the de-humidification program). But you can easily remove that piece of code if you want to.

I am considering to adapt the script a bit so that it starts the de-humid program only until there is nobody left in the bathroom or when the lights are out. That way you don't suck out all the warmth while there are still people in there. Guess that's not very hard to do. But I'm not sure yet how.. if I'm gonna use the PIR (motion) data, the lux values or the state of the light/dimmer switch.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
almirhod
Posts: 4
Joined: Sunday 03 January 2016 15:11
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by almirhod »

Ok, now I understand why you want to stop the program.

In my case the light and fan is controller by direct association with a MultiSensor. The Multisensor turns ON/OFF the fan/light based on movement. So I want the script to start the de-humidification and keep the fan ON even if the multisensor turns it off. My priority is to get rid of humidity first so I dont want anyone to be able to stop the program.

Anyhow the script looks good. I wanted to write a similar script and was reading Domoticz WIKI. Selected a random script just to see an example and this was the script. :)
pecora
Posts: 12
Joined: Monday 13 July 2015 12:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by pecora »

Very nice script...! It helped me out in the bathroom.

But I've got another sensor in the kitchen. How can I implement that one in the script?

Cant make a new script because I can't paste him also in "on action" of the fan.
pecora
Posts: 12
Joined: Monday 13 July 2015 12:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by pecora »

Does anyone have a suggestion?
franzelare
Posts: 139
Joined: Thursday 19 February 2015 21:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by franzelare »

i have my script based on a sunscreen script, works the same and also time out after manual operation can be re-used
https://www.domoticz.com/wiki/Automate_ ... nds_shades

or a bit updated version in this topic
viewtopic.php?t=6085
sj3fk3
Posts: 23
Joined: Sunday 22 March 2015 6:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by sj3fk3 »

Very nice script! I was messing about with a lot of nodes in a node-red flow (using mqtt), but this is much cleaner..

My only optimisation would be to store all variables in 1 object (I don't really need to humanly read the different values). That way it's much easier to use the script for more then 1 fan/sensor combination (I have 2 sets in my house).
franzelare
Posts: 139
Joined: Thursday 19 February 2015 21:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by franzelare »

I plan to add an methane sensor to my script, I have the sensor only need to do the coding for a mysensor wifi node... (ESP01)
I will share the script when ready!
toups
Posts: 8
Joined: Sunday 17 January 2016 15:50
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by toups »

Hi all and thx to Dan for this script.

Having said this, I have an issue with an error msg that comes every minutes:
"2016-06-09 19:35:00.426 Error: EventSystem: in script_time_humidity: [string "..."]:62: attempt to perform arithmetic on global 'humCounter' (a nil value)"
which refers to line 62 which is "humCounter = humCounter + 1"

To give more detail, I'm using Domotocz on Win7 & RFLINK and my sensors are dual (temp+hum sensors).

Many thx in advance for those who may have tips & tricks or elements that could help me to investigate.
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 »

Did you create the uservariables in Domoticz as described in the wiki?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
toups
Posts: 8
Joined: Sunday 17 January 2016 15:50
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by toups »

dannybloe wrote:Did you create the uservariables in Domoticz as described in the wiki?
Yes I did create the 6 variable with integer @ 0
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 assume you use the same script as in the wiki. The only thing that I can think of is that this results in a nil value:

Code: Select all

humCounter = tonumber(uservariables['humCounter'])
Are you sure that you didn't make a typo when creating the variable? It must be exactly with that name. If you did then maybe remove the variable and create it again.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
toups
Posts: 8
Joined: Sunday 17 January 2016 15:50
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by toups »

Bingo !!!!
well spotted Dan... a space was before the variable name "humCounter" ...
Sorry for this and many thx for your suggestion :)
I look forward to check how it goes now :)
But I'm not going to take an another shower this evening :)

cheers
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 »

Good luck.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
toups
Posts: 8
Joined: Sunday 17 January 2016 15:50
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by toups »

Thx again Dan !
it's confirm I can see interaction between humidity increase and FAn ON/OFF.

cheers
jorns
Posts: 6
Joined: Tuesday 14 January 2014 15:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by jorns »

pecora wrote:Does anyone have a suggestion?
Nice peace of work. Works like charm in my bathroom. I even empty my hot water tank to just try it out :) . Though i have the same issue as pecora.
Can someone give us a clue how to implement a second humiditysensor that can control the fan?.

thx
toups
Posts: 8
Joined: Sunday 17 January 2016 15:50
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by toups »

jorns wrote:
pecora wrote:Does anyone have a suggestion?
Can someone give us a clue how to implement a second humiditysensor that can control the fan?.

thx
this one may do the work... I haven't tried it
https://github.com/BazemanKM/Domoticz-M ... 20humidity

let us know
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 will make a version in the coming days that will support multiple devices. It will be based on dzVents though because that allows me to check previous readings more easily. And it is much easier to support multiple 'rooms/devices'.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
toups
Posts: 8
Joined: Sunday 17 January 2016 15:50
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script for controlling humidity in the bathroom

Post by toups »

dannybloe wrote:I will make a version in the coming days that will support multiple devices. It will be based on dzVents though because that allows me to check previous readings more easily. And it is much easier to support multiple 'rooms/devices'.
could you pls confirm if dzVents could run directly on Windows ?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest