Humidistat Fan Control With Key Overide and Fallback

Discussion in 'Pascal Logic Code Examples' started by muppets, Nov 12, 2007.

  1. muppets

    muppets

    Joined:
    Oct 26, 2007
    Messages:
    98
    Likes Received:
    0
    Hi everyone,

    My first code example please don't pick it to pieces however any comments/suggestions will be greatly accepted. ;)

    This code was designed so that an exhaust fan can be switched by a sensor with standard n/o n/c contacts but can also be overriden for a length of time or until repressed (some alteration for this to occur). After timing out will go back to the initial controlling sensor.

    A similar event can be set up with the toolkit gui however the fallback event, as I found out, would not implement correctly.

    enjoy

    Code:
    {Constants}
    
    { This is the timer used by the Ensuite Fan key input }
    ensuiteFanKeyTimer = 2;
    
    
    
    { module }
    
    { Makes the ensuite fan turn off or on for a
      specified time depending on what inputs are
      active and will return to the state of the
      humidistat or vice versa giving complete
      control from either input with overiding
      command from key input }
    
    { Similar coding could be used to step multiple
      functions from one key input ie fan control or
      any other function up to 256 different steps -
      if key pressed and trigger 0 then triggerlevset
      = 1 etc }
    
    { 40 is the key input, 38 is the aux input (steam
      sensor n/o contacts), 19 is the fan relay tag,
      trigger 001 is a trigger control that depicts what
      the key press was to do (on/off or go to middle "idle"
      state idle meaning neither off nor on) }
    
    { ensuiteFanKeyTimer is the timer that returns control to the
      aux input on expiry, the aux input also has a custom
      timer set up as: sp = on key
                            sr = retrig
                            lp = on key
                            lr = retrig
      with the timer time selected through the block and off
      key for expiry, the key input is configured as a bell
      press. }
    
    { Two scenes created for fan on and fan off - this was
      only opted for as a warning developed from sending
      multiple c-bus commands if the setcbusstate 19 was
      used? The state should only be sent with the once
      as far as I can tell. }
    
    
    once GetCBusState(254, "Lighting", 40) = ON then
      begin
      if GetCBusState(254, "Lighting", 19) = OFF then
       begin
       SetTriggerLevel(001, 255);
       TimerStart(ensuiteFanKeyTimer)
       end
       else if GetCBusState(254, "Lighting", 19) = ON then
         SetTriggerLevel(001, 0);
         TimerStart(ensuiteFanKeyTimer);
       end;
    
       { Have left timertime 10s for example/testing }
    
    if TimerTime(ensuiteFanKeyTimer) = "00:00:10" then
      begin
      TimerStop(ensuiteFanKeyTimer);
      SetTriggerLevel(001, 127);
      end;
    
    once GetCBusState(254, "Lighting", 38) = ON then
       if GetTriggerLevel(001) = 0
       then if GetCBusState(254, "Lighting", 19) = ON
       then SetScene("Ensuite Fan OFF");
    
    
    once GetCBusState(254, "Lighting", 38) = ON then
       if GetTriggerLevel(001) = 255
       then if GetCBusState(254, "Lighting", 19) = OFF
       then SetScene("Ensuite Fan ON");
    
    
    once GetCBusState(254, "Lighting", 38) = OFF then
       if GetTriggerLevel(001) = 127
       then if GetCBusState(254, "Lighting", 19) = ON
       then SetScene("Ensuite Fan OFF");
    
    
    once GetCBusState(254, "Lighting", 38) = OFF then
       if GetTriggerLevel(001) = 255
       then if GetCBusState(254, "Lighting", 19) = OFF
       then SetScene("Ensuite Fan ON");
    
    
    once GetCBusState(254, "Lighting", 38) = OFF then
       if GetTriggerLevel(001) = 0
       then if GetCBusState(254, "Lighting", 19) = ON
       then SetScene("Ensuite Fan OFF");
    
    
    once GetCBusState(254, "Lighting", 38) = ON then
       if GetTriggerLevel(001) = 127
       then if GetCBusState(254, "Lighting", 19) = OFF
       then SetScene("Ensuite Fan ON");
    
       { Extra statements with reverse conditions don't
         know if this is needed/helpful however code is
         working at present and I don't want to spend
         any more time messing with it. }
    
    once GetTriggerLevel(001) = 0 then
       if GetCBusState(254, "Lighting", 38) = ON
       then if GetCBusState(254, "Lighting", 19) = ON
       then SetScene("Ensuite Fan OFF");
    
    
    once GetTriggerLevel(001) = 255 then
       if GetCBusState(254, "Lighting", 38) = ON
       then if GetCBusState(254, "Lighting", 19) = OFF
       then SetScene("Ensuite Fan ON");
    
    
    once GetTriggerLevel(001) = 127 then
       if GetCBusState(254, "Lighting", 38) = OFF
       then if GetCBusState(254, "Lighting", 19) = ON
       then SetScene("Ensuite Fan OFF");
    
    
    once GetTriggerLevel(001) = 255 then
       if GetCBusState(254, "Lighting", 38) = OFF
       then if GetCBusState(254, "Lighting", 19) = OFF
       then SetScene("Ensuite Fan ON");
    
    
    once GetTriggerLevel(001) = 0 then
       if GetCBusState(254, "Lighting", 38) = OFF
       then if GetCBusState(254, "Lighting", 19) = ON
       then SetScene("Ensuite Fan OFF");
    
    
    once GetTriggerLevel(001) = 127 then
       if GetCBusState(254, "Lighting", 38) = ON
       then if GetCBusState(254, "Lighting", 19) = OFF
       then SetScene("Ensuite Fan ON");
    
    Let me know if there is any way I can improve it.

    I ended up using a humidistat from rs components - only decent looking one I could find though not cheap nice small footprint. http://www.rsaustralia.com/cgi-bin/...mghgdifecefeceeldgondhgn.0&cacheID=aunetscape
     
    Last edited by a moderator: Nov 12, 2007
    muppets, Nov 12, 2007
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.