Kod: Markera allt
--[[
%% properties
13 value
%% events
%% globals
--]]
-- User configurable parameters.
local debug = true -- Set to true/false to enable/disable debug messages.
local sensorId = 13 -- Id of sensor. For example a temperature sensor
local actorId = 26 -- Id of actor. For example a 0-10V output controling a valve.
local setPoint = 20.0 -- The wanted value.
local outMin = 0 -- Minimum output value to actor.
local outMax = 100 -- Maximum output value to actor.
local Kp = 1.5 -- Proportional factor in regulator. P-value.
local bias = 50 -- Zero offset. Output value when error is zero.
-- Function for rounding a value to no decimal places.
function round(num)
if (num >= 0) then
return math.floor(num + 0.5)
else
return math.ceil(num - 0.5)
end
end
-- Read sensor value.
local actual = tonumber(fibaro:getValue(sensorId, "value"))
-- P-regulator algorithm.
local err = setPoint - actual -- Calculate error.
local out = err * Kp + bias -- Calculate output value.
-- Limit output range.
if (out < outMin) then
out = outMin
end
if (out > outMax) then
out = outMax
end
-- Round to remove decimals.
out = round(out)
-- Set value on output actor.
fibaro:call(actorId, "setValue", out)
-- Debug.
if debug then
fibaro:debug("actual="..actual.." setPoint="..setPoint.." error="..err.." out="..out)
end
Kod: Markera allt
%% properties
13 value
Kod: Markera allt
local setPoint = 20.0 -- The wanted value.
Kod: Markera allt
local panelID = 309 -- Can be found with <ip to your HC2>/api/panels/heating.
local panel, status = api.get("/panels/heating/"..panelID) -- Get panel info from API.
local setPoint = panel.properties.currentTemperature -- Get current set temperature.