Jump to content
C4 Forums | Control4

Question re programming with timers


Recommended Posts

I’m trying to adjust some settings in my daughters' rooms. I currently have timers start during the daytime that turn the lights off after 30 mins (they have a habit of leaving lights on); however, I want the timer stopped when it's near sunset, which happens to coincide with their bedtime at the moment, as we're reading to them, doing homework etc.

 

Have I got the programming right or do I need to indent the 2nd If?

 

? If time is daytime

  Reset Timer....

? If time is within 60 mins before sunset

  Stop timer

Link to comment
Share on other sites


You don't say what you are using to trigger this timer start. In my house it is a motion detector and the light conditionally comes on - this means that each time the motion detector is triggered it will re-engage the logic. 

 

If you are using the light switch to turn on the light, then i am not sure you can achieve what you want - here is why - 

 

You turn on the light and it triggers your entire list of items. If it is 61 minutes away from sunset or more it will set your timer and start it running. There is now nothing that will trigger the "stop the timer' inside of your "window".

 

The only way yours will work is if you turn on the light (or trigger your programming) inside your 60 minute window.

 

I could be wrong here but unless I am misunderstanding how you are triggering this programming I don't see what you are wanting happening.

 

What you COULD do is say - 

 

(pseudo code follows)

 

In the scheduler mode - if time is between window and 9 pm

if my daughters timer is running - stop the timer

 

Just a thought.

Bill

Link to comment
Share on other sites

It doesn't matter if the timer is running after sunset you just don't want the lights to go out, so you can just put an if statement in the programming when the timer expires (runs out).  So where you program when timer expires, just put an if statement there saying if it is daytime turn the lights off, or if it is between x time and y time turn the light out.  You can program off of sunset so you should be able to achieve what you want.  

Link to comment
Share on other sites

OP- For housekeeping reasons, I always set the timer expired event to turn off a light (no conditionals in front of that).  Whether or not it's proper to run a timer needlessly is probably irrelevant but why do it?  Also, your programming is not complete.  You're only going to hit "daytime" once so after that, the light will not be controlled properly.  The primary trigger has to be change of light state (if you are not going to use a motion) then the time of day conditional then a timer reset or stop.

Link to comment
Share on other sites

Thanks for the feedback. I've revised the programming.

 

In the room, I now have: When the light is turned on, Reset timer

 

Under the timer, I now have:

? if time is daytime

  Turn off the light

? If the time is within 60 minutes before sunset

   Set level to 40

Link to comment
Share on other sites

^He doesn't.  That's why he posted here.  I suggested that although his new plan works, it is also possible to stop short of running a timer with no end result.  Of course it will work either way.

Link to comment
Share on other sites

I did have the condition under the event originally. If I did that again and added the ability to keep the light on during dusk, I'm guessing it would look like this:

When the light is turned on,

If time is daytime

Reset timer

If time is 60 minutes before sunset

Stop the timer

(I assume stopping the timer won't trigger its action)

Under the timer, I would have:

Turn off the light

This would leave the light on at dusk til we turn it off at bedtime and lights out

Sent from my iPad using Tapatalk

Link to comment
Share on other sites

Best practice is to limit the number of places you duplicate code.

Therefore when you want to change anything you can do so in one place.

 

for instance:

Use a boolean variable for 'DayTime' and 'Sunset'

Use the scheduler to set these to true/false based on time of the day.

This gives you flexibility to change your definition of these times, instead of relying on actual sunrise and sunset hours. (I have my 'daytime' end 30 mins before sunset, as it is dark enough then for me to want lights on.)

 

Your assumption of stopping the time is correct, this stops the timer at it's current count. It won't trigger the event for when 'timer expires'

 

I use the functions available within variable changes to keep my code simple.

ie: If you have 10 light switches for the lights you want controlled by a timer:

 

use a variable 'Check_Lights' (boolean)

program in the 'when check_lights changes':

 

if check_lights = true

   if timer 'lights' is running

      do stuff

set check_lights = false

 

program on each button click:

set check_lights = true

 

One line of code for each of my buttons or dimmers.

One 'function' used by all button clicks

 

Of course this is only useful in certain situations, but makes my life so much easier.

Link to comment
Share on other sites

^ I may have a macro my dealer put in that I can use.

I like the idea of minimizing. I just need to learn how/when to use macros

Sent from my iPhone using Tapatalk

Link to comment
Share on other sites

Thanks for the feedback. I've revised the programming.

 

In the room, I now have: When the light is turned on, Reset timer

 

Under the timer, I now have:

? if time is daytime

  Turn off the light

? If the time is within 60 minutes before sunset

   Set level to 40

So if it is nighttime it will not automatically turn off.

if it is AFTER sunset it will not only NOT dim but it will not turn off automatically - if that is what you want then you have it.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.