SpaceLogic KNX Forum
Schneider Electric SpaceLogic KNX forum to get support and share knowledge including selection, installation and troubleshooting for spaceLYnk, Wiser for KNX, eConfigure KNX, SpaceLogic KNX Hybrid module and other topics.
Link copied. Please paste this link to share this article on your social media post.
hello
I have multiple AC units, I want to add a timer for each one to turn off the AC with remain time and reset.
in order not to repeat the same script multiple times I think the function will be more optimized.
Is there any example of this using function?
regards,
Link copied. Please paste this link to share this article on your social media post.
You could try this:
User library called user.timer:
function settimer(addr, ena, res, rem, time, event, scriptname)
if event.dst == res and grp.getvalue(res) == false then
return
end
tpid = storage.get('PID:' .. scriptname)
if tpid == nil then
pid = os.getpid()
storage.set('PID:' .. scriptname, pid)
else
pid = os.getpid()
storage.set('PID:' .. scriptname, pid)
os.kill(tpid, signal.SIGKILL)
end
if grp.getvalue(ena) == false then
storage.delete('PID:' .. scriptname)
grp.write(rem, 0)
grp.write(addr, false)
return
end
grp.write(addr, true)
for i = 0, time - 1, 1 do
grp.write(rem, time - i)
os.sleep(60)
end
grp.write(rem, 0)
grp.write(addr, false)
storage.delete('PID:' .. scriptname)
end
Event based script triggered by tag on the enable and reset object
require('user.timer')
output = '6/0/0' ' -- bit object NO TAG !!
enable = '6/0/1' -- bit object with TAG to trigger this script
reset = '6/0/2' -- bit object with TAG to trigger this script
remaining = '6/0/3' -- byte object
delay = 10 -- in minutes
settimer(output, enable, reset, remaining, delay, event, _SCRIPTNAME)
Link copied. Please paste this link to share this article on your social media post.
What do you want to achieve with it?
When running a function from an event you load the same code as when running separate scripts, as events do run in parallel
From performance point of view you won’t gain anything...
Link copied. Please paste this link to share this article on your social media post.
hello @Erwin-vd-Zwart
I liked the function Just to make the script shorter instead of repeating the same code multiple times.
the idea is to let the user:
- set a timer to turn off the AC unit, we have around 20 units.
- Enable disable the timer
- reset the timer
- remain time
the user still could turn off the AC from Vis or by leaving seen.
Link copied. Please paste this link to share this article on your social media post.
You could try this:
User library called user.timer:
function settimer(addr, ena, res, rem, time, event, scriptname)
if event.dst == res and grp.getvalue(res) == false then
return
end
tpid = storage.get('PID:' .. scriptname)
if tpid == nil then
pid = os.getpid()
storage.set('PID:' .. scriptname, pid)
else
pid = os.getpid()
storage.set('PID:' .. scriptname, pid)
os.kill(tpid, signal.SIGKILL)
end
if grp.getvalue(ena) == false then
storage.delete('PID:' .. scriptname)
grp.write(rem, 0)
grp.write(addr, false)
return
end
grp.write(addr, true)
for i = 0, time - 1, 1 do
grp.write(rem, time - i)
os.sleep(60)
end
grp.write(rem, 0)
grp.write(addr, false)
storage.delete('PID:' .. scriptname)
end
Event based script triggered by tag on the enable and reset object
require('user.timer')
output = '6/0/0' ' -- bit object NO TAG !!
enable = '6/0/1' -- bit object with TAG to trigger this script
reset = '6/0/2' -- bit object with TAG to trigger this script
remaining = '6/0/3' -- byte object
delay = 10 -- in minutes
settimer(output, enable, reset, remaining, delay, event, _SCRIPTNAME)
Link copied. Please paste this link to share this article on your social media post.
hello @Erwin-vd-Zwart
I got this error:
User script:1: module 'user.timer' not found: no field package.preload['user.timer'] no file './user/timer' no file 'Library user/timer' no file 'User library timer' no file 'Library user/timer.so' no file 'Library user.so' stack traceback: [C]: in function 'require' User script:1: in main chunk
Link copied. Please paste this link to share this article on your social media post.
Did you create the userlib 'timer' with the corresponding function?
Link copied. Please paste this link to share this article on your social media post.
Sorry for that,
No, I add it to an old user lib.
many thanks
regards,
Link copied. Please paste this link to share this article on your social media post.
You can add the function settimer() to another user lib, or even common functions but in that case you need to adjust require('user.timer') to the other user lib name or when adding settimer to common functions you can remove the require() completely
Link copied. Please paste this link to share this article on your social media post.
hello @Erwin-vd-Zwart
thank you for the great support.
is this the correct (optimal) way to convert the remaining time to hh:mm format?
for i = 0, time - 1, 1 do
local remain = time - i
grp.update(rem, string.format("%02.f", math.floor(math.abs(remain)/60) )..':'..string.format("%02.f", math.fmod(math.abs(remain), 60) ) )
regards,
Link copied. Please paste this link to share this article on your social media post.
Short version: grp.update(rem, os.date('!%H:%M', remain * 60))
Link copied. Please paste this link to share this article on your social media post.
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.