|
|
|
The following page was printed from RemoteCentral.com:
Topic: | Action depending on time This thread has 12 replies. Displaying all posts. |
|
Post 1 made on Monday July 26, 2010 at 02:40 |
miwi Long Time Member |
Joined: Posts: | December 2004 34 |
|
|
Hello all,
my new 9400 becomes more and more evil as I am figuring out how many things I am able to do with it and how time consuming the programming is.
My latest idea is to do different actions on one button depending on the time of the day.
In detail I want to make a macro for watching movies via projector. As I have windows in room I need to close the blinds in order to see the screen. Now when the movie is over I press the power button and all devices power off and the blind open. So far so good. Now, lets say in the time between 9pm and 7am I want to power off the devices after the movie but leave the blind closed.
Is there a way to make a pronto scripts with if/then or true/false for this action?
Thanks in advance
miwi
|
Miwi |
|
Post 2 made on Monday July 26, 2010 at 02:48 |
danieljgor Long Time Member |
Joined: Posts: | December 2008 105 |
|
|
uses a twlight sensor / light sensor on the relay will only open when there is light outside.
|
|
Post 3 made on Monday July 26, 2010 at 03:02 |
BluPhenix Long Time Member |
Joined: Posts: | December 2008 371 |
|
|
use the time() class and alikes (see in the prontoscript guide for the full list). and then do conditional jumps based on the time.
|
|
OP | Post 4 made on Monday July 26, 2010 at 08:38 |
miwi Long Time Member |
Joined: Posts: | December 2004 34 |
|
|
I will give it a try. In any case I will post the PS for learning or debug purpose.
Thanks,
miwi
|
Miwi |
|
Post 5 made on Monday July 26, 2010 at 09:13 |
Guy Palmer Active Member |
Joined: Posts: | June 2008 648 |
|
|
The method depends on whether you want your conditions to be constant throughout the year or to vary according to the time of year.
If the former, then do as BluPhenix says.
If the latter, find a site which gives today's sunset and sunrise times, write a script to access this site and download these times into global variables, set this script up to run in the middle of the night, and then use the global variables to control the conditional jumps. This is what I do for my electronically-controlled curtains and it works flawlessly.
|
|
OP | Post 6 made on Monday July 26, 2010 at 10:17 |
miwi Long Time Member |
Joined: Posts: | December 2004 34 |
|
|
If the latter, find a site which gives today's sunset and sunrise times, write a script to access this site and download these times into global variables, set this script up to run in the middle of the night, and then use the global variables to control the conditional jumps. This is what I do for my electronically-controlled curtains and it works flawlessly. Guy, I am just a simple German guy and not a rocket scientist.. What you describe sounds great but I doubt that I will be able to do it in that perfection with my limited PS knowledge. So I first try to work on the constant version..... Thanks, miwi
|
Miwi |
|
Post 7 made on Monday July 26, 2010 at 14:40 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 12,992 |
|
|
Look at string returned by GUI.getDisplayTime(), parse it, and then execute one of 2 widgets using executeActions(). Somewhere in this forum is the logic I use to extract time via regular expressions that accounts for 24 hour clock. Search for posts by me that also contain GUI.getDisplayTime(). Here's the code I spoke of... I'm sure there is more information you may want to see from the above search as well so have a look at search results too, please. [Link: remotecentral.com]
Last edited by Lyndel McGee on July 26, 2010 17:58.
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
OP | Post 8 made on Thursday July 29, 2010 at 10:13 |
miwi Long Time Member |
Joined: Posts: | December 2004 34 |
|
|
I tried to understand to logic behind the following script and do not see the mistake in it, as unfortunatly it is not working at all on my Pronto.
Am I correct with the following assumotions in red:
var myTime = GUI.getDisplayTime(); var "JUST ANY NAME I WANT is requesting the time in format HH:MM
if(myTime.substring(2, 3) == ":") {myHour = myTime.substring(0,2);} This is for the hours from 10 to 24 in order to count under "myHour" the digits at position "0"? and 2 (shouldn´t there be digits 1 and 2 counted ?)
else if(myTime.substring(1, 2) == ":") {myHour = myTime.substring(0,1);} This is for the hours from 0 to 9 in order to count under "myHour" the single remaining hour digit (whatfor the "0" is standing there?)
myHour=1*myHour; This is to make a logic number out of the myHour text ?
if (myHour<7 || myHour>=18){CF.widget("Button A","page","Activity").executeActions();} If result of myHour is bigger than 18 or smaller than 7 the execute the action that is on button A
else {CF.widget("Button B","page",Activity").executeActions();} If result is not as described in the row before than execute action stored under button B
I am pretty sure that the activitiy, page and button do have the right ProntoScript name mentioned in the script, so has anyone an idea where the mistake(s) is/are ?
Thanks in advance for helping a "script dummy"
miwi
|
Miwi |
|
Post 9 made on Thursday July 29, 2010 at 10:43 |
Guy Palmer Active Member |
Joined: Posts: | June 2008 648 |
|
|
Miwi,
Yes, the basic logic and syntax of your script is right.
A few minor comments about good practice:
1. If statements based on hardcoded positions are a bit error prone. Rather, I would search for ":" and then substring up to there. So, for example:
EndPos = myTime.indexOf(":") myHour=myTime.substring(0,EndPos);
2. myHour=myHour-0 is apparently a more efficient way of turning a string into a number than myHour=1*myHour.
Finally, to debug: by using the System.print() command in your script, you can run the script in the simulator and see the values that your variables are taking.
|
|
OP | Post 10 made on Thursday July 29, 2010 at 13:13 |
miwi Long Time Member |
Joined: Posts: | December 2004 34 |
|
|
Guy,
still no luck with the script:
Now I tried
var myTime = GUI.getDisplayTime(); EndPos = myTime.indexOf(":") myHour=myTime.substring(0,EndPos); myHour=myHour-0; if (myHour<7 || myHour>=18){CF.widget("A","Page","Activity").executeActions();} else {CF.widget("B","Page",Activity").executeActions();}
Error message in the console I receive is:
ProntoScript error: SyntaxError: unterminated string literal Offending button script: Tag: 'test' Offending line #6: "else {CF.widget("B","Page",Activity").executeActions();}"
What am I doing wrong?
Regards
miwi
|
Miwi |
|
Post 11 made on Thursday July 29, 2010 at 13:59 |
Guy Palmer Active Member |
Joined: Posts: | June 2008 648 |
|
|
You need a extra double quote in the second executeActions, like you have in the first.
else {CF.widget("B","Page","Activity").executeActions();} - correct
else {CF.widget("B","Page",Activity").executeActions();} - syntax error
|
|
OP | Post 12 made on Thursday July 29, 2010 at 14:31 |
miwi Long Time Member |
Joined: Posts: | December 2004 34 |
|
|
Guy,
all the small things....
Now it is working perfect. Thanks for your debugging support !!!!
miwi
|
Miwi |
|
Post 13 made on Thursday July 29, 2010 at 17:31 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 12,992 |
|
|
Miwi,
Search for try catch debugging and you will get some debugging tips as well.
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
|
Before you can reply to a message... |
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now. |
Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.
|
|