This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Help with timer/time in LUA script
#1
Hi!


I am trying to controll my heating cable outside the front door, for melting the snow in winter.

I pulling the weather forecast in node red and get a "true" signal if the forecast says snow, and "false" it not.
I also want the outdoor temperature to control the time for the heating cable. ( so its not ON all the time)

My plan is to have OFF, AUTO and ON mode.
In OFF mode its forced off.
In ON mode its forced on.
In AUTO i want the outside temperature and forecast to control the "on" time.

Like, if the forecast is "true" and the temperature is between +4 and 0, the heating is ON in 25 minutes and OFF in 35 minutes, then repeat as long as the temperature is in range.

Then if the forecast is "true" and the temperature is between 0 to -4, the heating is ON for 35 minutes and OFF for 25 minutes, then repeat.

And if the forecast is "true" and the temperature is between -4 to -8, the heting is ON for 50 minutes an OFF for 10 minutes then repeat.

Something like that.

So how can i do this in LUA script, to get the times right?

i tried with os.sleep in resident script, but that doesnt work.

Any ideas? Cool
Reply
#2
I assume you know how to write your conditions. Very simple solution for your time on/Off is just create 6 scheduled scripts. One for on and one for off for each condition and set minute in which you want to send on or off. In your script based on which condition just enable pair of the scheduled scripts and disable when condition is not meet.
------------------------------
Ctrl+F5
Reply
#3
Create a scheduled scripts that runs every minute.
Change group addresses as needed:
1/1/1 - mode (2 = auto)
1/1/2 - forecast (true/false)
1/1/3 - temperature value
1/1/4 - output control

To simplify things the output will turn on at 0 minutes of every hour if needed and will turn off after X minutes depending on the current temperature.
Code:
mode = grp.getvalue('1/1/1')
if mode ~= 2 then
  return
end

forecast = grp.getvalue('1/1/2')
temperature = grp.getvalue('1/1/3')
if not forecast or temperature > 4 then
  offtime = 0
-- 0..4
elseif temperature >= 0 then
  offtime = 25
-- -4..0
elseif temperature >= -4 then
  offtime = 35
-- -8..-4
elseif temperature >= -8 then
  offtime = 50
-- lower than -8
else
  offtime = 60
end

min = os.date('*t').min
value = min < offtime
grp.checkwrite('1/1/4', value)
Reply


Forum Jump: