Jump to content
C4 Forums | Control4

Delayed Turnoff


Recommended Posts

I have a Demo custom button to demo a house. When it's pressed, it turns on fireplaces, music, TV's, everything to demo the house itself. I want to turn off the fireplaces after 45 minutes. How would I go about doing this with conditionals? I am still not very adept at that sort of programming, and I don't even know where to start. Take a look at my attatched picture. At the bottom I was going to add Wait 45 Minutes

Emit IR Code: Fireplaces Off

But if I did that, wouldn't I have to wait 45 minutes to be able to push any buttons again?

I want something like:

When Custom Button DEMO is pressed,

Then delay 45 minutes

Emit IR Code Fireplace Off

Any ideas?

Link to comment
Share on other sites

When that button is pressed set a variable to change. Then in the programming set when that variable changes, wait 45 minutes and turn fireplace off.

That should allow you other functionality while the timer is going.

I would set it for like 60 seconds initially to test it as you are working on the bugs. If when you get it to work you can take screen shots that would be awesome.

Link to comment
Share on other sites

Again, like I said, I am completely new to this type of programming.

Should I create a Boolean Variable Called: fireplace_off

Set it to false (by default)

When custom button DEMO is pressed, set fireplace_off to True

fireplace_off = FIREPLACE OFF

I took 3 screenshots to show how I have it now (in order). I'm going to go test it, but is this something to what it should look like?

Link to comment
Share on other sites

Insanity! That worked. The only thing I changed was that instead of turning fireplace_off to true, i set it to toggle (that way I could press house Demo more than once and it would reset the process)

I'm amazed that worked the first time. Maybe I've just been too afraid to get into these variables and stuff.

Link to comment
Share on other sites

Taylor, the only issue you may have with this code is that onced pressed, you will always get the off to happen after 60 seconds.

If you pressed the button again after 20sec., your turn off will still happen after the initial 60 sec is done. Since the command has already been sent, the second press will send the turn off command at 60 sec, but the first one will still fire before (after the first 60 sec. is up) making the off happen after only 40sec.

I would love to see C4 introduce timed sequences to the programming options. This way, it could be reset evrytime you execute without the need of all the extra code. Very handy when doing auto lights off after a time delay. Ex., everytime a motion is triggered, turn a light on if off, wait 5 minutes and turn off if at the preset intensity. With a timed sequence, you only need to insert the events at the begining and when you want it to turn off. Every motion trigger will restart the sequence from the start. No heavy code to do.

A delay will always execute if fired, there is no stoping it without code in place. So for a timed off, you should code a count down that can be reset by a new press like a post I just read 'Sleep timer'.


Link to comment
Share on other sites

Yeah, I actually ran into another problem. Because the Fireplace codes weren't Discrete (they were all toggles) when someone would press the Demo mode again, before the time sequence finished, it would unsych the system.

I now have to come up with a way to do something like this:

If house demo is presed, execute timed shutdown and set fireplace to true

If fireplace is true, then don't allow fireplace to start sequence again

I dunno if that made sense, but now I have to find a way to make sure the code doesn't get ahead of itself. Like maybe after the 45 minutes set fireplace back to false or something.

Link to comment
Share on other sites

Can you control that fireplace with a relay from HTC or MC (connect to ignitor terminals)? We always do it that way. When shorted NC (terminals that the switch or thermostat to control the fireplace are connected to) they turn on the fireplace and when not shorted NO, they turn it off. This will give you discretes.

As to prevent it from being controlled while your demo is running, the screen shot code can be edited to your specs.

The variable "Demo_On" (boolean) will only allow the code below to execute when False, so you can press it all you want.

The variable "Demo_countdown"(number) is your timer, adjust it to your needs. The 900Millisecond delay instead of 1 second makes it more accurate.

If you want this timer to reset everytime you press the button, remove the first conditional if "Demo_On is false"

Good Luck


Link to comment
Share on other sites

Something to clear up:

I am controlling the Fireplaces VIA Lite Touch lighting system, which is done with serial. I say emit IR code because that's what it's called in the programming. C4 hasn't fixed that yet.

The lite touch system isn't set up for ON or OFF functionality. They could come up there and do it, but as of now it's not worth it for them to do that.

@ Jamman

You lost me on your programming. I know this may be basic for you, but I'm still learning it. I kind of see what you are doing, but if I don't see all steps involved, I think i'm gonna miss something.

Also, I can NEVER make those other variable commands "tab" over. I have tried a few times but still no go.

Link to comment
Share on other sites

Indenting lines in programming:

Click on the green arrow and drag. Once you start to drag you'll see a little arrow in an outlined box. That arrow tells you where that line of code will "drop": either up (above the line it's dragged to), down (below the line it's dragged to), or to the right (indented below the line it's dragged to--and therefore within that loop or if statement).

Indented lines will only be performed it the logic in the if or while statement passes as true.

Link to comment
Share on other sites

Do you want the fireplaces to be turned off 45 minutes after the demo button is pressed and every time the demo button is pushed it starts that 45 minute timer over again? If so then do this:

Create a number variable (we'll call it FireplaceTimer). When the demo button is pressed set that variable to a value of 45.

When that variable changes (when it's set to 45--basically when the demo button is pressed) program the timer countdown. See screenshot (I turned kitchen light off but yours of course would be the fireplace code). Basically it's saying when the value of the integer is greater than 0 wait one second and decrement the value of the timer. You control the length of the timer by the value you gave the integer (in this case 45) and the delay in between decrements.

Now if you need to add "discrete" control then you need to create another variable (let's say FireplaceOnOff--boolean in this case is best) to keep track of when you turned it "on" verses "off". Every time you change the status of the fireplace you need to change the status of the FireplaceOnOff variable. If that's also what you want then let me know and I'll create some more screen shots for you.

Link to comment
Share on other sites

What I want "Revised edition"

1. Press house demo.

2. Starts Fireplaces (not discrete, but a macro that makes sure it is on) I did this by first emiting House OFF (which does discretly turn off all fireplaces) and then I know the current state) I think this could be accomplished better by having something go: When Whole house ALL OFF is pressed, set fireplace to false. That way it is constantly updated as to the state of the fireplaces

3. Once fireplaces are on and DEMO button is pressed, start a 45 minute timer that will turn off the fireplaces after 45 minutes. Even if the button is pressed again, don't do ANYTHING because the sequence has already started. The only way to reset it is to turn house off, reset the variable to false, and then press it again.

4. If someone comes in and presses house demo off, i want the fireplaces to go off, not just emit the current toggle I have set. So something like:

If fireplace is set to false (fireplaces off),

Do nothing

If fireplace is set to true

Emit macro Fireplaces off.

Do you kind of see what I'm getting at?

Link to comment
Share on other sites

First, to keep the 45 second timer from restarting you just need to add a line of logic that tests to see if it's already counting down (i.e. > 0) then don't reset it. See screenshot 1 attached.

Now for the full deal let's chop it up a bit. It sounds like you need four things:

1. FireplaceOn boolean variable for keeping track of when the fireplace is on and when it's off--it must be set each time you change the fireplace.

2. HouseDemoOn boolean variable for keeping track of when the demo is running and when it's not--it must be set each time you change start and stop the house demo

3. FireplaceTimer number variable for creating a timer that starts when the demo button is pressed and turns the fireplace off when timer expires.

4. It's late by the time I thought of the four and got to this one I've already forgot the 4th.

So you know how to create the variables. ...and it sounds like you know how to change them. When house demo button pressed set HouseDemoOn = true. When fireplace turned on set FireplaceOn = true. When house demo button pressed set FireplaceTimer = 45 if it's not already in a countdown.

So let me know if you need any more specific help on it.

Link to comment
Share on other sites


the code from the screen shot is it. The only thing you need to do is create a number variable and a boolean variable. You can call them what you want and then the screen shot uploaded gives you the code which you could insert anywhere in programming to suit your purpose. I called then Demo_On and Demo_countdown.

The "Demo_On" variable prevents the code below it to execute when set to true.

The Demo_countdown Variable sets the delay time and the while loop countsdown to 0, then executes whatever you stick under the conditional within it.

You could also add a if Demo_On is true conditional to prevent it from firing in case you control the state of that variable somewhere else in programming. This can apply to your fireplace or anything else you need to do a delayed command that might be cancelled before it fires.

When you read code, just follow each step one by one.

Is Demo_On true? if not then go below it and see what's there, next condition. Is it true or false, is it set to 0, etc. This will help you follow many different ways of doing the same thing. You need to think like the processor to make it work for you. The more you mess around with code, the more you'll find ways of doing things. One thing to keep in mind is, there are many ways of programming the same thing to happen. Everyone thinks differently, doesn't mean they do it wrong or right. As long as it works. I find that the most logical and least code normally works best, as it doesn't slow down the processor too much. That's just me. I normally spend more time thinking through the solution than I do actually programming it.

The code does work, but if you find a different way of doing it, that's great as well.



Link to comment
Share on other sites


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

  • Create New...