13.06.2022, 19:50
(13.06.2022, 07:00)admin Wrote: Line 19 should have timer.outvalue instead of timer.value:
Code:if timer.outvalue < timer.onvaluelow then
Thanks for reaction. I have changed this, but error is the same:
Code:
if not client then
timers = {
{
input = '9/0/1', -- binary PIR status
output = '1/1/7', -- dimmer control (0..100%)
onvaluehigh = 90, -- high output value in %
onvaluelow = 10, -- low output value in %
timeout = 5, -- in seconds
}
}
function setinputvalue(timer, event)
local value = busdatatype.decode(event.datahex, dt.bool)
if not value then
return
end
if timer.outvalue < timer.onvaluelow then
value = timer.onvaluelow
elseif timer.outvalue < timer.onvaluehigh then
value = timer.onvaluehigh
else
value = nil
end
if not timer.ticks and value then
grp.write(timer.output, value, dt.scale)
end
timer.ticks = timer.timeout
end
function setoutputvalue(timer, event)
timer.outvalue = busdatatype.decode(event.datahex, dt.scale)
timer.ticks = nil -- stop timer
end
for _, timer in ipairs(timers) do
timer.outvalue = grp.getvalue(timer.output)
end
sender = 'tm'
grp.sender = sender
client = require('localbus').new(0.1)
client:sethandler('groupwrite', function(event)
if event.sender == sender then
return
end
for _, timer in ipairs(timers) do
if timer.input == event.dst then
setinputvalue(timer, event)
elseif timer.output == event.dst then
setoutputvalue(timer, event)
end
end
end)
end
client:loop(1)
for _, timer in ipairs(timers) do
if timer.ticks then
timer.ticks = timer.ticks - 1
if timer.ticks == 0 then
grp.write(timer.output, timer.outvalue, dt.scale)
timer.ticks = nil
end
end
end
Resident script:19: attempt to compare nil with number
stack traceback:
Resident script:19: in function 'setinputvalue'
Resident script:54: in function <Resident script:47>
Library localbus: in function ''
Library localbus: in function ''
Libbrarary localbus: in function 'loop'