Jump to content
C4 Forums | Control4

Sleep timer script for bedroom touch screen


gmaniax

Recommended Posts

Great forum guys!

I'm trying to develop a custom button (I think this is what I need) and script that can turn power off the room that is playing music (audio from digital cable tv music channel) after 30 mins (choice of 30, 60, 90 mins would be great). I'd lke to run this by touching a button on the mini touch screen in the bedroom

any help would be greatly appreciated

thanks

GM

Link to comment
Share on other sites


Hey Gmaniax you can do this pretty easily.

Create a Variable. Call it Sleep_Timer_1. Set it as an integer value.

In the programming choose a keypad button and the on push event take variable Sleep_Timer_1 and set it to Sleep_Timer_1 + 30.

(This increases the value of the variable to an additional 30)

Then in the programming choose under the variables on the left Sleep_Timer_1, the on change event enter the following programming.

* Notes

** "//" are comments, do not try to program them into the code

*** I'm doing this by memory not by actually looking in composer so if some things are a little different don't worry.

Wait 3 Seconds // This is the time the system should wait for additional keypresses.

If Sleep_Timer_1 = 30 // 30 Minute Option

Set Keypad_1_Button_1 = Red

Wait 30 Minutes

Turn Room Off

Sleep_Timer_1 = 0

Set Keypad_1_Button_1 = Blue

Break

If Sleep_Timer_1 = 60 // 60 Minute Option

Set Keypad_1_Button_1 = Red

Wait 60 Minutes

Turn Room Off

Sleep_Timer_1 = 0

Set Keypad_1_Button_1 = Blue

Break

If Sleep_Timer_1 = 90 // 90 Minute Option

Set Keypad_1_Button_1 = Red

Wait 90 Minutes

Turn Room Off

Sleep_Timer_1 = 0

Set Keypad_1_Button_1 = Blue

Break

* Some quick notes.

**You may want to set the Sleep_Timer_1 variable to 0 before you do the actual Wait, It would take a best practice test to see how someone interacts with it.

***I had the color of the light change to red when the program was running, and blue when it was set back. This is optional and a better way might be to have it blink 3, 6, or 9 times to let the user know what they selected.

****You may have to use the other programming function besides Break, Maybe End I can't remember.

This script is definately not perfect, it's just a guide to get you started. If you can't figure it out let me know and I will actually code it and screen shot it to show you.

Link to comment
Share on other sites

Dan,

What you have there will work but there is a much easier way to do this. Just create the Tab "Sleep timers" and the custom buttons "30 min, 45 min, 1 Hr, etc" then in programming:

when custom button "30 min" is pressed:

>Delay 30 in

>Turn room master Bedroom off

The delay and the room off are already built into C4.

This will show up on the min-touch and the system remote, works great in my master.

-Jeff

Premier Sight and Sound

Link to comment
Share on other sites

OK. Well I certainly agree that from a usability standpoint that jmf's solution is best but 2 things:

1. What happens if you hit 30, then before the 30 expires you hit 60? You would have to add programming to check for that.

2. You know how most things work with sleep timers, you keep hitting the button it adds x number of minutes to the timer? ...like Dan's solution. Well I just had to play some more to get my version of that working here's what I did.

SleepTimer integer variable

Custom Button Tab for SleepTimer Button (which toggles by adding each time you hit it), and 30, 60, 90 second buttons too (again just playing at this point).

Screenshot 1

If SleepTimer button is pressed it adds x (whatever increment you choose) to the variable. Also, you can set a threshold like I did here at 120 to set it back to 0...again just like other devices work. But when adding this you will need to add more programming (not in scope of this initial post) because setting the variable to 0 is the trigger to turning the room off

If 30, 60, 90 is hit then the variable is set to that number (not incremented or anything just set to that number).

Screenshot 2

Now when that variable changes is where all the real work goes on.

Basically it says while the timer has a value greater than 0 decrement the value every second (could be minute, etc.)

Then when it gets to 0 turn "whatever" off

The problem with Screenshot 2 is that it doesn't work. ...and even though It's late and I can barely see through my foggy contacts I think it should work. Tell me if my logic is wrong. I think the problem is that the decrment action is not firing the variable change event so it's not acting recursively which I adamately think it should. So if I move the if statement inside the while, it works.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...