23.01.2025, 11:22 
		
	
	
		Hi.
I am running a PID-controller from a resident script, every 60 seconds.
However my water temperature change is quite slow changing and I try to run the same script with the same PID-controller from scheduled scripts instead.
I have now copied all code and disabled the resident script.
However, when i schedule this script it doesn't run.
No log, nothing. Even if i klick "run script" nothing happens.
Other scheduled scripts works just fine.
Any clues?
	
	
	
	
I am running a PID-controller from a resident script, every 60 seconds.
However my water temperature change is quite slow changing and I try to run the same script with the same PID-controller from scheduled scripts instead.
I have now copied all code and disabled the resident script.
However, when i schedule this script it doesn't run.
No log, nothing. Even if i klick "run script" nothing happens.
Other scheduled scripts works just fine.
Any clues?
Code:
-- Resident: Golvvärme styrvärde regulator pid nedan:
-- Ange avrundningssteget här (t.ex. 0.1, 0.2, 0.25, 0.5, etc.)
local round_step = 0.20  -- Du kan ändra detta till det steg du vill ha..
-- Funktion för att avrunda till närmaste "step"
local function round_to_nearest(value, step)
  return math.floor(value / step + 0.5) * step
end
-- Variabel för att slå på eller av temperaturskillnadskontrollen
local temperature_diff_enabled = false  -- Sätt till 'true' för att kontrollera temperaturskillnaden, 'false' för att inaktivera
-- Hämta nuvarande och börvärde från sensorer och avrunda med angivet steg
local current_value = round_to_nearest(grp.getvalue('5/5/1'), round_step) -- Framledning ärvärde
local setpoint_value = round_to_nearest(grp.getvalue('5/5/0'), round_step) -- Framledning börvärde
-- Kontrollera temperaturskillnad efter avrundning
local temperature_diff = math.abs(setpoint_value - current_value)
local limit = 0.20 -- Gränsen för temperaturskillnad
-- Initiera PID om det behövs
if not p then
  require('user.pid')
  p = PID:init({
    current = '5/5/1', -- Framledning ärvärde
    setpoint = '5/5/0', -- Framledning börvärde
    output = '5/5/15',  -- GV styrvärde
    round_step = round_step -- Här skickas round_step till PID
  })
end
-- Kontrollera om temperaturskillnaden ska användas för att köra PID
if temperature_diff_enabled then
  -- Endast kör PID om temperaturskillnaden är signifikant
  if temperature_diff > limit then
    local previous_output = p.output
    p:run()
    if p.output ~= previous_output then
      -- Logga värdena tillsammans med styrvärdet
      log(string.format("Styrvärde skickat till 5/5/15: %.2f (Ärvärde: %.2f, Börvärde: %.2f, Skillnad: %.2f°C)",
                        p.output, current_value, setpoint_value, temperature_diff))
    end
  else
    log("Ingen signifikant avvikelse (" .. string.format("%.2f", temperature_diff) .. "°C), limit " .. string.format("%.2f", limit) .. "°C, PID ej körd. (Börvärde: " .. string.format("%.2f", setpoint_value) .. "°C, Ärvärde: " .. string.format("%.2f", current_value) .. "°C)")
  end
else
  -- PID körs alltid, oavsett temperaturskillnad
  local previous_output = p.output
  p:run()
  if p.output ~= previous_output then
    -- Logga värdena tillsammans med styrvärdet
    log(string.format("Styrvärde skickat till 5/5/15: %.2f (Ärvärde: %.2f, Börvärde: %.2f, Skillnad: %.2f°C)",
                      p.output, current_value, setpoint_value, temperature_diff))
  end
end 
 

 
