Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Topic:
time based action help needed
This thread has 13 replies. Displaying all posts.
Post 1 made on Sunday February 12, 2023 at 05:37
Fischi
Long Time Member
Joined:
Posts:
January 2011
114
Hi,

I want to use an action that is triggering at 07:00 (24 h format).

Now I have created a library as follows :

/*!
@title time_based_action
@version 1.0
@author V Fischer

*/
var myTime = GUI.getDisplayTime();
EndPos = myTime.indexOf(":")
myHour=myTime.substring(0,EndPos);
myHour=myHour-0;
if (myHour==7){CF.widget("A4","B","C").executeActions();}

I've putted the library into the PS Lybraries on the System level.

I was hoping that the action runs at 07:00 but nothing happens.

What's going wrong ?

Best regards,
Fischi
Post 2 made on Monday February 13, 2023 at 18:31
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,995
1. Pronto does not have an embedded real-time clock as you likely have already surmised and you are resorting to using the displayTime from GUI.
2. Pronto Script does not run while the Pronto is not docked and the screen goes off. The pronto wakes up every 55 seconds or so to only keep wifi active. If you listen closely to the speaker on the back, you'll hear a small 'tick' when this happens.

3. Looks like you did not declare a variable using var for EndPos. i.e.

var EndPos = myTime.indexOf(":");

4. Did you put a try/catch around this script and actually debug it to see if it was causing any errors?
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 3 made on Thursday February 16, 2023 at 12:20
Fischi
Long Time Member
Joined:
Posts:
January 2011
114
Thanks again Lyndel,
I want to run a function 'time' recurring in the background.
That must be stable and independent.
I've created a library to run an intervalTimer every 60 seconds.
I've putted the library at system level.

/*!
@title test5.v-Fischer
@version 1.0
@author v Fischer
*/

var updateInterval = 60 * 1000; // 1 min; in msec

function getDate() {
d = new Date();
return d.getFullYear() + "-" + ("0" + Number(d.getMonth()+1)).slice(-2)+"-"+ d.getDate() + "T" + GUI.getDisplayTime() + ":" + ("0" + d.getSeconds()).slice(-2);
}

function time() {
var timePattern = new RegExp('(\\d+):(\\d+)((am|pm)*)','g');
GUI.getDisplayTime().match(timePattern);


var hour = parseInt(RegExp.$1,10);
var minute = parseInt(RegExp.$2,10);

if (hour === 3 && minute === 55) {CF.widget("A4","B","C").executeActions();}

var ampm = RegExp.$3;
var seconds = new Date().getSeconds();
}
time();

/*
schedule periodic updates for when the TSU sits in the charging dock
and it is powered on.
*/
function periodicUpdate_2(activity) {
System.setDebugMask(9);
System.print(getDate() + " [ScheduleAfter]_____TIMER");
time();
activity.scheduleAfter(updateInterval, periodicUpdate_2, activity);
}





Embedded is a function 'time' that parses the hours and minutes out
and a condition if (hour === 3 && minute === 55) .

After invoking from a button with the button script periodicUpdate_2(CF.activity()); the stuff is running OK every 60 seconds.

When the time is reached (3:55)
{CF.widget ("A4","B","C").scheduleActions();} is running OK

After that or after jumping to another activity/page the intervalTimer stops although the library is at system level.

I ever thought it would be running over the whole system on all pages and activities because the library is system level but it isn't so.

What's going wrong ?

Regards,
Fischi
Post 4 made on Saturday February 18, 2023 at 01:05
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,995
Note that I edited the response below to hopefully make the explanation more cohesive.

What's wrong with the script? User error! ;-)

You only defined functions in your Global Library with the exception of a single call to your time() function. To your point, a Global Library does execute each time you change activities, however, when your library is compiled, the code only calls time(); (see below)

var seconds = new Date().getSeconds();
}
time()

As this is the case, no timers are started by the invocation of the Global Library.

Note that you stated to get the recurring timer started first time through, you pressed a button with script that called periodicUpdate_2(CF.activity()).

Exercise to see how pressing button 10 times will eventually cause an error - If you press that button more than 1 time as each time you do, you create yet another timer. I bet if you press it more than 10 or 20 times, you'd see an error as there is a limit to the number of timers Pronto can have (see Dev Guide notes on scheduleAfter).

That single press of your button is good only while in the current activity as when activity changes, even though a script may be defined as a global library, the entire Javascript stack is blown away (see Dev Guide about Scopes - System Activity, Page, Button). Any variables, etc. from a Global Library go away each time an activity changes.

Think of a Global Library as just a placeholder for common scripts (added by PEP2 developers to make things a bit easier) that a user can choose to include (check box) for activities rather than having to add JS file to each activity.

In order to restart your timer for every activity, you'd need to have the Global Library both define and call the periodicUpdate_2 function.

From what I'm seeing above, modify your library to add the 2 lines below to the end. Note that you might also want to remove the cited call above to time().

// Kick off new timer for the current activity.
periodicUpdate_2(CF.activity());

Last edited by Lyndel McGee on February 18, 2023 12:23.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 5 made on Saturday February 18, 2023 at 12:25
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,995
Try this.

/*!
@title test5.v-Fischer
@version 1.0
@author v Fischer
*/

var updateInterval = 60 * 1000; // 1 min; in msec

function getDate() {
d = new Date();
return d.getFullYear() + "-" + ("0" + Number(d.getMonth()+1)).slice(-2)+"-"+ d.getDate() + "T" + GUI.getDisplayTime() + ":" + ("0" + d.getSeconds()).slice(-2);
}

function time() {
var timePattern = new RegExp('(\\d+):(\\d+)((am|pm)*)','g');
GUI.getDisplayTime().match(timePattern);


var hour = parseInt(RegExp.$1,10);
var minute = parseInt(RegExp.$2,10);

if (hour === 3 && minute === 55) {CF.widget("A4","B","C").executeActions();}

var ampm = RegExp.$3;
var seconds = new Date().getSeconds();
}

//removed per reasons in previous post
//time();

/*
schedule periodic updates for when the TSU sits in the charging dock
and it is powered on.
*/
function periodicUpdate_2(activity) {
System.setDebugMask(9);
System.print(getDate() + " [ScheduleAfter]_____TIMER");
time();
activity.scheduleAfter(updateInterval, periodicUpdate_2, activity);
}

// Kick off new timer for the current activity.
periodicUpdate_2(CF.activity());

Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 6 made on Sunday February 19, 2023 at 06:04
Fischi
Long Time Member
Joined:
Posts:
January 2011
114
Thanks again Lyndel,

there is still a problem :
When the time is reached (3:55) {CF.widget ("A4","B","C").executeActions();} is running OK
but then there comes the error message "Busy playing actions"
and the periodic udates stop again.

The actions in CF.widget are as follows:
-Beep
-Delay 1 sec
-Jump Hilfstimer - new page
-Delay 5 sec
-Jump Timer _ Timers
-Delay 5 sec
-Jump Home

Might it have something to do with the jumps ?

I've also tried with scheduleActions instead of executeActions but then

the actions in the button A4 are running and running frequently without stopping.

Have a nice Sunday
Fischi

Last edited by Fischi on February 19, 2023 07:18.
Post 7 made on Sunday February 19, 2023 at 19:54
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,995
Looks like you have many timers running and they are all attempting to execute the same actionlist all within that 1 minute timeframe as you did not code any logic to prevent this.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 8 made on Sunday February 19, 2023 at 20:01
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,995
Search this forum or the dev guide for the error you are seeing to hopefully get more ideas as to how to fix.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 9 made on Monday February 20, 2023 at 12:45
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,995
So, while you can use Global Libraries, the things you might want to do in them can quickly become rather complex.

I was thinking more about your issue. The issue you are likely having is as follows:

1. You are in Activity #1 when the time matches to 3:55. You begin schedule or execute of the actionlist.

2. The actionlist then causes a jump to another activity which relaunches your timer via your Global Library running in Activity #2. Your script then immediately sees the time match. Result: You have the error about currently executing actionlist.

One way you could solve this would be through the use of System Globals as the Pronto can maintain state across activities only by using them. You'd need to keep 'state' across activities and prevent the time from running except for only 2 times per day irrespective of the activity.

I'm not in a position to write this code as I'm not aware of all your use cases and the complexity of such a solution.

By complexity, I mean
1. There are 2 activities involved and this makes it harder to save state as you move around.

2. There is no way to modify a System Global via an actionlist (i.e. when actionlist is complete, set or clear a System Global that would allow your timer to continue execution). To do something like that, the last action in your list would have to be a Jump to a page and this page would have to have the Page Script to clean up the global.

Best of luck on this one.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 10 made on Monday February 20, 2023 at 13:05
Fischi
Long Time Member
Joined:
Posts:
January 2011
114
Many thanks again Lyndel,

I think I've found a solution, I have modified Sebastian's HA script that I'm also using for sending Battery and WiFi status from my Prontos to HomeSeer.

/*!
@title test10.v-fischer
@version 1.0
@author v Fischer
*/

var updateInterval = 60 * 1000; // 1 min; in msec

function getDate() {
d = new Date();
return d.getFullYear() + "-" + ("0" + Number(d.getMonth()+1)).slice(-2) + "-" + d.getDate() + "T" + GUI.getDisplayTime() + ":" + ("0" + d.getSeconds()).slice(-2);
}
function time() {
var timePattern = new RegExp('(\\d+):(\\d+)((am|pm)*)','g');
GUI.getDisplayTime().match(timePattern);


var hour = parseInt(RegExp.$1,10);


var minute = parseInt(RegExp.$2,10);


if (hour === 3 && minute === 55) {CF.widget("A4","B","C").executeActions();}
var ampm = RegExp.$3;
var seconds = new Date().getSeconds();
}


/*
schedule periodic updates for when the TSU sits in the charging dock
and it is powered on.
*/
function periodicUpdate_2(activity) {
System.setDebugMask(9);
System.print(getDate() + " [ScheduleAfter] TIMER");
time();
activity.scheduleAfter(updateInterval, periodicUpdate_2, activity);
}

((function () {
//debugging
System.setDebugMask(9);
// the current activity.
var myActivity = CF.activity();
myActivity.onEntry = function () {
last = System.getGlobal('time_last_update');
ts = Date.now();
if (last === null) {
System.print(getDate() + " [Wake up]");

time();

System.setGlobal('time_last_update', ts);
}
};
System.print(getDate() + " Setting up scheduled updates for TIMER");
myActivity.scheduleAfter(updateInterval, periodicUpdate_2, myActivity);
System.print("Done.");



}()));

I'm using onEntry to kick off the new timer.

Will do some more tests, but it seems that all is working fine now.
I'm using the stuff to put the sunrise/sunset data into Schmuzli's Prontotimer because the weather.com data aren't available nomore.

(BTW: Barry's Pronto Pro Debugger shows 'Action list error' but that can be ignored)

Thanks,
Fischi
Post 11 made on Monday February 20, 2023 at 14:14
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,995
It won’t show that error if you change to using scheduleActions.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 12 made on Monday February 20, 2023 at 14:47
Fischi
Long Time Member
Joined:
Posts:
January 2011
114
On February 20, 2023 at 14:14, Lyndel McGee said...
It won’t show that error if you change to using scheduleActions.

Now it works flawless.
I've also added a 10 sec delay at the BEGINNING of the action list, I think that was the reason for the 'Busy playing actions' are gone now but I don't know.
It was a long way to get it running and now I let it go like this.

Thanks again
Post 13 made on Monday February 20, 2023 at 16:21
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,995
Glad you have it working.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 14 made on Monday February 20, 2023 at 16:23
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,995
On February 20, 2023 at 14:47, Fischi said...
Now it works flawless.
I've also added a 10 sec delay at the BEGINNING of the action list, I think that was the reason for the 'Busy playing actions' are gone now but I don't know.
It was a long way to get it running and now I let it go like this.

Thanks again

That was not the reason but since it works now. No further need to discuss it.
Lyndel McGee
Philips Pronto Addict/Beta Tester


Jump to


Protected Feature 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.

Hosting Services by ipHouse