Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Notifications
Login / Register
Community
Community
Notifications
close
  • Forums
  • Knowledge Center
  • Events & Webinars
  • Ideas
  • Blogs
Help
Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Login / Register
Sustainability
Sustainability

Join our "Ask Me About" community webinar on May 20th at 9 AM CET and 5 PM CET to explore cybersecurity and monitoring for Data Center and edge IT. Learn about market trends, cutting-edge technologies, and best practices from industry experts.
Register and secure your Critical IT infrastructure

count down timer as a function

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.

cancel
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Home
  • Schneider Electric Community
  • EcoStruxure Building
  • Light and Room Control
  • SpaceLogic KNX Forum
  • count down timer as a function
Options
  • Subscribe to RSS Feed
  • Mark Topic as New
  • Mark Topic as Read
  • Float this Topic for Current User
  • Bookmark
  • Subscribe
  • Mute
  • Printer Friendly Page
Invite a Co-worker
Send a co-worker an invite to the portal.Just enter their email address and we'll connect them to register. After joining, they will belong to the same company.
You have entered an invalid email address. Please re-enter the email address.
This co-worker has already been invited to the Exchange portal. Please invite another co-worker.
Please enter email address
Send Invite Cancel
Invitation Sent
Your invitation was sent.Thanks for sharing Exchange with your co-worker.
Send New Invite Close
Top Experts
User Count
Thomas_Rohde
Sisko Thomas_Rohde Sisko
121
Erwin-vd-Zwart
Sisko Erwin-vd-Zwart Sisko
54
Heribert_Dölger
Lt. Commander Heribert_Dölger Lt. Commander
30
FZetina
Lt. Commander FZetina Lt. Commander
27
View All
Related Products
product field
SpaceLogic KNX - 4ʺ Touch Unit
product field
KNX Push Button Dynamic Labeling, universal
product field
Wiser for KNX : logic controller

Invite a Colleague

Found this content useful? Share it with a Colleague!

Invite a Colleague Invite
Solved Go to Solution
Back to SpaceLogic KNX Forum
Solved
IC_Systems
Captain IC_Systems
Captain

Posted: ‎2021-01-12 07:34 AM . Last Modified: ‎2024-07-14 11:47 PM

0 Likes
10
751
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2021-01-12 07:34 AM

count down timer as a function

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,

Best Regards,
  • Thumbnail of SpaceLogic KNX - 4ʺ Touch Unit
    SpaceLogic KNX - 4ʺ Touch Unit
  • Thumbnail of KNX Push Button Dynamic Labeling, universal
    KNX Push Button Dynamic Labeling, universal
  • Thumbnail of Wiser for KNX : logic controller
    Wiser for KNX : logic controller
View products (3)
Labels
  • Labels:
  • Scripts
  • SpaceLYnk
Tags (1)
  • Tags:
  • english
Reply
  • All forum topics
  • Previous Topic
  • Next Topic

Accepted Solutions
Erwin-vd-Zwart
Sisko Erwin-vd-Zwart Sisko
Sisko

Posted: ‎2021-01-12 09:44 AM

1 Like
7
740
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2021-01-12 09:44 AM

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)

See Answer In Context

Tags (1)
  • Tags:
  • english
Reply
Replies 10
Erwin-vd-Zwart
Sisko Erwin-vd-Zwart Sisko
Sisko

Posted: ‎2021-01-12 07:51 AM

0 Likes
9
746
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2021-01-12 07:51 AM

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...

Tags (1)
  • Tags:
  • english
Reply
IC_Systems
Captain IC_Systems
Captain

Posted: ‎2021-01-12 08:11 AM

0 Likes
8
743
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2021-01-12 08:11 AM

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.

 

Best Regards,
Tags (1)
  • Tags:
  • english
Reply
Erwin-vd-Zwart
Sisko Erwin-vd-Zwart Sisko
Sisko

Posted: ‎2021-01-12 09:44 AM

1 Like
7
741
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2021-01-12 09:44 AM

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)

Tags (1)
  • Tags:
  • english
Reply
IC_Systems
Captain IC_Systems
Captain

Posted: ‎2021-01-13 02:37 AM

0 Likes
6
730
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2021-01-13 02:37 AM

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
Best Regards,
Tags (1)
  • Tags:
  • english
Reply
Erwin-vd-Zwart
Sisko Erwin-vd-Zwart Sisko
Sisko

Posted: ‎2021-01-13 02:45 AM

0 Likes
5
728
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2021-01-13 02:45 AM

Did you create the userlib 'timer' with the corresponding function?

 

userlib.jpg

Tags (1)
  • Tags:
  • english
Reply
IC_Systems
Captain IC_Systems
Captain

Posted: ‎2021-01-13 02:52 AM

0 Likes
4
726
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2021-01-13 02:52 AM

Sorry for that,

No, I add it to an old user lib.

many thanks

regards,

Best Regards,
Tags (1)
  • Tags:
  • english
Reply
Erwin-vd-Zwart
Sisko Erwin-vd-Zwart Sisko
Sisko

Posted: ‎2021-01-13 02:59 AM

1 Like
3
723
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2021-01-13 02:59 AM

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

Tags (1)
  • Tags:
  • english
Reply
IC_Systems
Captain IC_Systems
Captain

Posted: ‎2021-01-14 12:47 AM

0 Likes
2
719
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2021-01-14 12:47 AM

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,

Best Regards,
Tags (1)
  • Tags:
  • english
Reply
Erwin-vd-Zwart
Sisko Erwin-vd-Zwart Sisko
Sisko

Posted: ‎2021-01-14 12:55 AM

1 Like
1
717
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2021-01-14 12:55 AM

Short version: grp.update(rem, os.date('!%H:%M', remain * 60))

Tags (1)
  • Tags:
  • english
Reply
IC_Systems
Captain IC_Systems
Captain

Posted: ‎2021-01-14 01:01 AM

0 Likes
0
714
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

‎2021-01-14 01:01 AM

great @Erwin-vd-Zwart 

very short 🙂

Best Regards,
Tags (1)
  • Tags:
  • english
Reply
Preview Exit Preview

never-displayed

You must be signed in to add attachments

never-displayed

 
To The Top!

Forums

  • APC UPS Data Center Backup Solutions
  • EcoStruxure IT
  • EcoStruxure Geo SCADA Expert
  • Metering & Power Quality
  • Schneider Electric Wiser

Knowledge Center

Events & webinars

Ideas

Blogs

Get Started

  • Ask the Community
  • Community Guidelines
  • Community User Guide
  • How-To & Best Practice
  • Experts Leaderboard
  • Contact Support
Brand-Logo
Subscribing is a smart move!
You can subscribe to this board after you log in or create your free account.
Forum-Icon

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.

Register today for FREE

Register Now

Already have an account? Login

Terms & Conditions Privacy Notice Change your Cookie Settings © 2025 Schneider Electric

This is a heading

With achievable small steps, users progress and continually feel satisfaction in task accomplishment.

Usetiful Onboarding Checklist remembers the progress of every user, allowing them to take bite-sized journeys and continue where they left.

of