C-Bus Forums  

Go Back   C-Bus Forums > C-Bus Products > Logic Code Examples

The C-Bus Community Forums is place where C-Bus users can share information and help others with C-Bus. From time to time you will see Clipsal staff on the forums, but this is not an official support channel. If you really need help contact the official support services of Clipsal. More information about the purpose of this forum is available here.

Reply
 
Thread Tools Display Modes
  #1  
Old 04 Jan 17, 10:11 AM
magic8 magic8 is offline
Member
 
Join Date: Jan 2009
Posts: 34
Default Timer Logic

First time trying a timer logic in wiser 2
Entered below in wiser project and ran with no errors
Transferred project to wiser2 unit and timer side of all logics will not work
Anyone have any idea why not
Probably me being stupid!!!!
Thanks

once (GetLightingState("Dining Room Lts") = ON)
then timerstart(3);
begin
once timertime(3) > 2
then SetLightingState("Dining Room Lts", OFF);
begin timerstop(3);
end;
end
Reply With Quote
  #2  
Old 04 Jan 17, 10:42 AM
NickD's Avatar
NickD NickD is offline
Senior Member
 
Join Date: Nov 2004
Location: Adelaide
Posts: 1,153
Default

Code:
once (GetLightingState("Dining Room Lts") = ON)
then timerstart(3);
begin
once timertime(3) > 2
then SetLightingState("Dining Room Lts", OFF);
begin timerstop(3);
end;
end
I think you've got a few more semicolons than you need.

The semicolon terminates the once statement so what you effectively have is

Code:
once (GetLightingState("Dining Room Lts") = ON)
then timerstart(3);
Which starts the timer when the group goes on.

Followed by

Code:
once timertime(3) > 2
then SetLightingState("Dining Room Lts", OFF);
Which turns the group off when the timer exceeds 2 seconds.

Followed by

Code:
timerstop(3);
Which stops the timer, always.

As a C programmer I find the optional semicolon and optional begin/end in pascal confusing so I like to always put in begins and ends and indent to make the code clearer (in my mind anyway).

It's not entirely clear what you are intending to happen (putting comments as to what you are intending to do also help (even for yourself when you come back 5 years later and wonder what the hell you were thinking)), but if you're trying to also stop the timer at the same time as you are turning off the group then you need to put begin and end around the statements after then "then".

Code:
{Start the timer when the group turn on}
once (GetLightingState("Dining Room Lts") = ON) then 
  begin
    timerstart(3)
  end;

{Stop the timer and turn off the group when the timer has run for > 2 seconds}
once (timertime(3) > 2) then 
  begin
    SetLightingState("Dining Room Lts", OFF);
    timerstop(3);
  end;
Nick
Reply With Quote
  #3  
Old 04 Jan 17, 10:44 AM
Ashley Ashley is offline
Senior Member
 
Join Date: Dec 2005
Location: Adelaide, Australia
Posts: 526
Default

Your begin/ends are all wrong, so the timer is stopped as soon as it starts. If you format it correctly you can see what's happening more clearly. The second ONCE only executes the setLightingState. The timerstop is outside of that ONCE.

Code:
once (GetLightingState("Dining Room Lts") = ON) then timerstart(3);

once timertime(3) > 2 then SetLightingState("Dining Room Lts", OFF);
begin // does nothing!
   timerstop(3);  // Executed every scan !
end;
try

Code:
once (GetLightingState("Dining Room Lts") = ON) then timerstart(3);

once timertime(3) > 2 then 
begin 
   SetLightingState("Dining Room Lts", OFF);
   timerstop(3);
end
or better still

Code:
once (GetLightingState("Dining Room Lts") = ON) then
 pulseCBusLevel("Local", "Lighting", "Dining Room Lts", 100%, "0s", "0:03:00", 0%);
In most cases timers aren't required. I have written thousand of lines of logic and never used a timer.

Also, you can do this in the switch without logic


Obviously Nick types faster than me

Last edited by Ashley; 04 Jan 17 at 10:51 AM.
Reply With Quote
  #4  
Old 04 Jan 17, 11:16 AM
magic8 magic8 is offline
Member
 
Join Date: Jan 2009
Posts: 34
Default

Thanks for replies
Will try and see if I can get timer to work ok
This was a simple test timer to try to explain what I was doing wrong
The customer wants quite a complicated function involving an exhaust fan that comes on when light comes on and stays on for 1 minute after light switched off. Also if the light is left on for > 10 minutes to switch light off and fan off after 1 minute[I guess its being left on!!!!]
Thanks again for info
Reply With Quote
  #5  
Old 04 Jan 17, 11:21 AM
magic8 magic8 is offline
Member
 
Join Date: Jan 2009
Posts: 34
Default

Its on an EDLT so no "blocks" to use
Thanks
Reply With Quote
  #6  
Old 04 Jan 17, 11:36 AM
NickD's Avatar
NickD NickD is offline
Senior Member
 
Join Date: Nov 2004
Location: Adelaide
Posts: 1,153
Default

To do that it's probably easier to use the "PulseCBusLevel" function..

Here's a copy and paste of something similar from my own touchscreen project.. (note the fan is on a dimmer in my case).

Code:
{ Turns fan on low when light is turned on, then sets it to 
   high for 3 minutes once light is turned off }

once (GetLightingState("Toilet") = ON) then
begin
  SetLightingLevel("Toilet Fan", 70%, "0s");
end;

once (GetLightingState("Toilet") = OFF) then
begin
  PulseCBusLevel("WIRED", "Lighting", "Toilet Fan", 100%, "0s", "0:03:00", 0%);
end;


{If fan is on when light is turned off, let it run for a few minutes}

once (GetLightingState("Ensuite") = OFF) then
begin
  if (GetLightingState("Ensuite Fan") = ON) then
    begin
      PulseCBusLevel("WIRED", "Lighting", "Ensuite Fan", 100%, "0s", "0:03:00", 0%);
    end;
end;

Last edited by NickD; 04 Jan 17 at 11:41 AM.
Reply With Quote
  #7  
Old 04 Jan 17, 12:45 PM
magic8 magic8 is offline
Member
 
Join Date: Jan 2009
Posts: 34
Default

copied and pasted what you suggested and works perfectly
thanks for all the replies
All good
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wiser Socket Reciving issue Matt C-Bus Wiser 2 4 25 Apr 16 10:35 PM
PAC Logic Timer Lucky555 C-Touch/HomeGate/SchedulePlus/PICED 7 21 Jan 09 07:20 PM
PAC and the serial killer Potemkin C-Touch/HomeGate/SchedulePlus/PICED 18 25 Nov 05 02:24 PM
Expiring a timer in a switch/SENPIRSS from the logic engine Charlie Crackle C-Touch/HomeGate/SchedulePlus/PICED 1 22 Aug 05 02:02 AM
Toolkit : Logic functions in output units george Quick Tutorials (Read Only) 0 07 Jan 05 11:30 AM


All times are GMT +10.5. The time now is 05:53 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.