Page 1 of 1

How to check is devices is changed for a couple of minutes within LUA?

Posted: Tuesday 16 August 2016 18:36
by tlpeter
I want to start my mechanical ventilation by temp and/or humidity.
Right now i use a temp sensor and if a threshold is reached the fan starts.
But that also means that this happens when i turn on the hot water for washing hands.
I want to turn the ventilation on after a couple of minutes.
So if temp > 45 degrees for 5 minutes then ......
But 'for' is only used in a commandarray while i want it to use in a devicechanged or othervalues.

How do i do this or is it even possible?

Re: How to check is devices is changed for a couple of minutes within LUA?

Posted: Tuesday 16 August 2016 23:49
by DanM
I've tried a few different ways of managing timers but in the end I've always come back to using the user variables to keep track of time.

Create a ventilation_timer variable set to 0. Have a timer script that checks if the temp is > 45 and adds one to the count (timer scripts are checked every minute). If the count is greater than 5 then turn the switch on. If the temp drops below 45 then reset the count to zero.

Something roughly like this... (the temp sensor stuff is definitely wrong.. this is just for illustration)

Code: Select all

  if ( otherdevices[tempsensor]> 45) then
  	--the sensor is over 45, so add 1 to our timer
	commandArray['Variable:ventilation_timer']= tostring(uservariables["ventilation_timer"] + 1)
 else
 	--the sensor is under 45, so reset our timer
	commandArray['Variable:ventilation_timer']=0
end

  if ( uservariables["ventilation_timer"]> 5) then
	commandArray['Ventilation System']='On'
else
	commandArray['Ventilation System']='Off'
end
Hope this helps.

Re: How to check is devices is changed for a couple of minutes within LUA?

Posted: Wednesday 17 August 2016 7:32
by bizziebis
I use this script for over a year now: http://www.domoticz.com/wiki/Humidity_control

Does everything you want.
Setting a fixed temperature or humidity to trigger the fan is not always convenient. This script will do better :)

Re: How to check is devices is changed for a couple of minutes within LUA?

Posted: Wednesday 17 August 2016 10:53
by tlpeter
Thanks both,

I used the variable option as i already have a script using another variable to see if there is used a manual switch or not.
Bizziebis, i like the script but i already have a different script.
Maybe in the future as i really like it.