Maximum dimmer level changed at night time?

Discussion in 'Pascal Logic Code Examples' started by lennyb, May 6, 2014.

  1. lennyb

    lennyb

    Joined:
    Feb 25, 2013
    Messages:
    41
    Likes Received:
    0
    Location:
    UK
    Just starting out in the world of logic code. One of the key things I wanted to achieve with logic and my PAC is, at night (say after 11pm) certain lights would, with a click of the button only come on at 30% rather than the 100% at other times of the day.

    So I want there to be a way to press a keypad button for a light using the dimmer function and the single press would set the light to 30% between 11pm and 5am or 100% for any other time of the day.

    The idea behind this being at night time if someone turns on the bathroom light they aren't blinded by the full force of the lights at 100%!
     
    lennyb, May 6, 2014
    #1
  2. lennyb

    Roosta

    Joined:
    Nov 22, 2011
    Messages:
    560
    Likes Received:
    1
    Location:
    Australia
    If you search you should find numerous topics on how to set this up..

    You shouldnt need to use the logic engine just use the inbuilt logic functions in the dimmer module, and a device with schedule capability..
     
    Roosta, May 6, 2014
    #2
  3. lennyb

    lorenthehaloboy

    Joined:
    Nov 18, 2004
    Messages:
    66
    Likes Received:
    0
    I couldnt find logic on the forums to do this either sorry Roosta
     
    lorenthehaloboy, May 8, 2014
    #3
  4. lennyb

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,548
    Likes Received:
    178
    Location:
    Adelaide, Australia
    Create a group called, say, 'Max Intensity'. Define a schedule to set it to 30% at 11pm and 100% in the morning. On the dimmer logic tab, enter this group address in the first logic column, click the entry for whatever channel the light is on (or multiple channels if you want), then select MIN as the function. This will, of course, set the max light level to 30% at night so you can't then dim the light further up from the switch. If you want the initial light level to toggle to different levels day and night plus allow for the entire dim range on the same switch it gets a bit (lot!) more complicated.
     
    Ashley, May 8, 2014
    #4
  5. lennyb

    lorenthehaloboy

    Joined:
    Nov 18, 2004
    Messages:
    66
    Likes Received:
    0
    Mostly commonly asked for, is for the switch if pressed to turn the toilet light on at say 30%, but then if they hold down the dimmer key, increase that to 100% if required at night. If there was an emergency somewhere, or they wanted the lights on full, and it was scheduled, using dimmer logic, they are up the creek (other than having a button to stop the schedule etc)

    Looking for the most simplistic way to have this feature. We have a way we use now, but it is complicated and the logic is bulky, but it works. Trying to think of other ways.
     
    lorenthehaloboy, May 8, 2014
    #5
  6. lennyb

    Roosta

    Joined:
    Nov 22, 2011
    Messages:
    560
    Likes Received:
    1
    Location:
    Australia
    Thanks Ashley for the run through.. :)

    Lorenthehaloboy, would a possible solution be to configure the switch to recall the level you want on a short press, and to ramp on long presses.. Only issue is its not time/schedule bound..
     
    Roosta, May 8, 2014
    #6
  7. lennyb

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,548
    Likes Received:
    178
    Location:
    Adelaide, Australia
    OK, so on your switch set it to Dimmer, then on the Key Functions for the switch change short release from toggle to recall 1. On the blocks tab set Recall 1 to 1%;

    then add the following logic:

    Code:
    //Global  Variables
    
    savedLevel: integer;
    
    / /Initialisation
    
    savedLevel := 0;
    
    // Module
    
    once    GetLightingLevel("Your group") = 1% then
    begin
      if savedLevel > 0 then
        savedLevel := 0
      else if (time > "23:00:00") or (time < "07:00:00") then
        savedLevel := 30%
      else
        savedLevel := 100%;
      SetLightingLevel("Your group", savedLevel, "0s");
    end;
    savedLevel := GetLightingLevel("Your group"); // Added 22-May to fixed observed problem
    
    The code is triggered on a short release. If the group was ON it turns it off (i.e. toggle)
    If it was OFF it turns it on the 30% at night and 100% during the day.
    Dimmer function then works as normal.

    If you wanted you could make the times and night level userSystemIO's and put them on a display to change at will.
    Alternatively, if you wanted to use a schedule, create another group address called say 'Starting Level', set up a schedule to change it between 30% and 100% at the appropriate times, then just
    go savedLevel := "startingLevel" in place of the else if and else.
     
    Last edited by a moderator: May 16, 2017
    Ashley, May 8, 2014
    #7
  8. lennyb

    lorenthehaloboy

    Joined:
    Nov 18, 2004
    Messages:
    66
    Likes Received:
    0
    Ash, thanks for the code, however, I Think there would be a fault.

    Lets see they client dimmed the lights up to 80%. At this point your code has not been triggered, but they then do a short press to turn the light off.

    That recalls it to 1%, the savedLevel would still be 0, so it would then ramp it up to 100% (or 30% if between those hours)?

    Did I miss something, or is this what would happen?

    Thanks.
     
    lorenthehaloboy, May 21, 2014
    #8
  9. lennyb

    lennyb

    Joined:
    Feb 25, 2013
    Messages:
    41
    Likes Received:
    0
    Location:
    UK
    I'll try this out later and see what happens. It may be necessary to add some additional lighting level checks for > 1%
     
    lennyb, May 21, 2014
    #9
  10. lennyb

    lorenthehaloboy

    Joined:
    Nov 18, 2004
    Messages:
    66
    Likes Received:
    0
    Yes, tried it myself this morning, and as suspected, if the light gets dimmed up to whatever level, and then they hit the button to turn it off, it goes down to 1%, and then back up.

    There has to be a clean, simple way to have a short press just turn on and off to variable level, while still retaining dimming. Surely! *grin*
     
    lorenthehaloboy, May 21, 2014
    #10
  11. lennyb

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,548
    Likes Received:
    178
    Location:
    Adelaide, Australia
    Good pick up. I don't usually dim lights up from off. Anyway, I edited to logic to fix the problem. Just add the last line.

    If there is it has eluded everyone so far :)
     
    Last edited by a moderator: May 22, 2014
    Ashley, May 22, 2014
    #11
  12. lennyb

    lorenthehaloboy

    Joined:
    Nov 18, 2004
    Messages:
    66
    Likes Received:
    0
    Thanks Ash, it wasnt just for dimming up. The scenario where a light is on, or at say 60% at 10pm, and then at 11pm this kicks in, the script would have no idea what level the light was at when they hit pushed the button to turn the light off.

    It would go to 1%, assume the light was previously at 0%, and so it would turn them on to 30%.

    I may be missing something, but not sure how that last line of code helps in these situations unfortunately, unless all lights at 11pm were polled to get their status, and store that level maybe?

    It still doesnt help if someone dims a light up to an unknown 46% or something, as when they go to turn it off, it will turn it back on again.
     
    lorenthehaloboy, May 22, 2014
    #12
  13. lennyb

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,548
    Likes Received:
    178
    Location:
    Adelaide, Australia
    When you long press a button with downcycle set (i.e. a dimmer), cbus sends out a ramp to level function with an end of 0 or 255 depending upon the last ramp direction. The switch then internally tracks the ramp level. When you release the button, the endramp function is executed. The switch then sends out a ramp to level at its currently tracked position with a 0 ramp time. This effectively sets the group level to the level the switch thinks it should be. This is why sometimes when you release a dimmer switch the light level changes slightly. Delays on the bus can cause a slight variation in what the switch thinks the level should be relative to what the dimmer unit does. The logic will pick up the level sent from the endramp function and set its internal saved level. The same is true whenever anyone else changes the group. So savedLevel will now track the group where ever it is. Try it, it works.
     
    Ashley, May 22, 2014
    #13
  14. lennyb

    stubbsy

    Joined:
    Jan 28, 2009
    Messages:
    2
    Likes Received:
    0
    There is an error in the code - shd say "savedLevel" not "saved_level"

    That is the only way I could get it to compile and I can't even code (I once did it for 1 hour in 1982)

    Seems to work though - thanks
     
    stubbsy, May 16, 2017
    #14
  15. lennyb

    stubbsy

    Joined:
    Jan 28, 2009
    Messages:
    2
    Likes Received:
    0
    Actually no it does not (at least not all the time).

    A short press to turn off, dims the light but then it straight back up - I think it is somehtging to do with the recalled level
     
    stubbsy, May 16, 2017
    #15
  16. lennyb

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,548
    Likes Received:
    178
    Location:
    Adelaide, Australia
    I fixed up the typo. Thanks for pointing it out.

    It works fine for me. I just loaded it up and tried it again.

    Make sure you have the switch set up properly. On the Key Functions tab you should see:
    Short Press: Idle
    Short release: Recall 1
    Long press: Downcycle
    Long release: Endramp

    On the blocks tab for that switch, recall1 should be set to 1.
     
    Ashley, May 16, 2017
    #16
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.