Logic Machine Forum
Script help - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Script help (/showthread.php?tid=3566)



Script help - svetoslavp - 19.09.2021

Hello,

Could you please help me with one resident script?

If the temperature is below "A" for more then "B" seconds/ minutes turn on 1/1/2. If the temperature is above C for more then "D" seconds/minutes turn off 1/1/2

We have temperature with address 1/1/1.


RE: Script help - admin - 20.09.2021

Modify as needed, make sure that step value is the same as script sleep time (at least 5 seconds, can be more if the wait time is larger).
Code:
temp = grp.getvalue('1/1/1')

-- temp limits
temp_low = 20
temp_high = 30

-- time in seconds
time_low = 20
time_high = 40

step = 5 -- script sleep time in seconds

if temp < temp_low then
  timer_high = nil

  if timer_low then
    if timer_low < time_low then
      timer_low = timer_low + step

      if timer_low >= time_low then
        grp.write('1/1/2', true)
      end
    end
  else
    timer_low = 0
  end
elseif temp > temp_high then
  timer_low = nil

  if timer_high then
    if timer_high < time_high then
      timer_high = timer_high + step

      if timer_high >= time_high then
        grp.write('1/1/2', false)
      end
    end
  else
    timer_high = 0
  end
end



RE: Script help - svetoslavp - 21.09.2021

(20.09.2021, 10:52)admin Wrote: Modify as needed, make sure that step value is the same as script sleep time (at least 5 seconds, can be more if the wait time is larger).
Code:
temp = grp.getvalue('1/1/1')

-- temp limits
temp_low = 20
temp_high = 30

-- time in seconds
time_low = 20
time_high = 40

step = 5 -- script sleep time in seconds

if temp < temp_low then
  timer_high = nil

  if timer_low then
    if timer_low < time_low then
      timer_low = timer_low + step

      if timer_low >= time_low then
        grp.write('1/1/2', true)
      end
    end
  else
    timer_low = 0
  end
elseif temp > temp_high then
  timer_low = nil

  if timer_high then
    if timer_high < time_high then
      timer_high = timer_high + step

      if timer_high >= time_high then
        grp.write('1/1/2', false)
      end
    end
  else
    timer_high = 0
  end
end

Thank you very much!