Logic Machine Forum
Underfloor Water heating - Night lowering - 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: Underfloor Water heating - Night lowering (/showthread.php?tid=1580)



Underfloor Water heating - Night lowering - Bobby - 09.09.2018

Hi!

I am using PID script for UFH. And i want to have 2 adjustable setpoint temperatures for day/nighttime.
is this possible? 
Another alternative is to use the current setpoint temperature, but lower it by ie 4 degrees in night time.
My current script:

-- init pid algorithm
if not p1 then
  p1 = PID:init({
    current = '1/5/41',
    setpoint = '1/5/21',
    output = '1/5/1'
  })
end


RE: Underfloor Water heating - Night lowering - Erwin van der Zwart - 09.09.2018

Hi,

You need to create a event based script that has 2 setpoints as input and a output that is given a value by the day/night logic to set one of the 2 inputs to the output. The output can then be used for the PID.

BR,

Erwin


RE: Underfloor Water heating - Night lowering - admin - 11.09.2018

You can modify PID library compute function like this. Then you need to specify night_mode (boolean, true = night mode) and setpoint_night (float16 or similar) addresses in PID init. After that restart your script via enable/disable so new library and parameters are loaded.

Code:
function PID:compute()
  local params, current, setpoint, deltasc, deltain, output

  params = self.params

  -- get input values
  current = grp.getvalue(params.current)
  setpoint = grp.getvalue(params.setpoint)

  if params.night_mode and grp.getvalue(params.night_mode) then
    setpoint = grp.getvalue(params.setpoint_night)
  end

  -- delta between setpoint and current
  deltasc = setpoint - current

  -- calculate new iterm
  self.iterm = self.iterm + params.ki * self.deltatime * deltasc
  self:clampiterm()

  -- delta between current and previous value
  deltain = current - self.previous

  -- calculate output value
  self.output = params.kp * deltasc + self.iterm
  self.output = self.output - params.kd / self.deltatime * deltain

  -- write to output
  self:setoutput()

  -- save previous value
  self.previous = current

  return self.output
end