How retrieve list of the "Upcoming schedules" ???

Hello,

I would find a way to retrieve the informations of “Upcoming schedules” (in overview)
the idea is to use them to make a kind of widget (for MyVera software)

Thank you in advance for your help
Alex.

I think you will have to reverse-engineer it with a JavaScript debugger. There is no published API for the overview page.

It is available from the User Data
Refer Scenes > timers > next_run

VeraIP/data_request?id=user_data&output_format=xml

Below is the function from the Overview page:

function get_overview_schedules(){
    try{
        var scenesNo=jsonp.ud.scenes.length;
        var countTimers = 0;
        var schedulesArray = [];
        for(var i=0;i<scenesNo;i++){
            if(jsonp.ud.scenes[i].timers!=undefined&&jsonp.ud.scenes[i].timers!="undefined"&&(jsonp.ud.scenes[i].timers.length!=0)){
                for(var j=0;j<jsonp.ud.scenes[i].timers.length;j++){
                    try {
                        if(parseInt(jsonp.ud.scenes[i].timers[j].autogen)!=1){
                            var info = get_schedule_info(jsonp.ud.scenes[i].id,j);
                            if(info.next_run>jsonp.lu.TimeStamp){
                                countTimers++;

                                var scheduleLine = ''
                                + '<tr>'
                                + '	<td>' + jsonp.ud.scenes[i].name + '</td>'
                                + '	<td>' + info.name + '</td>'
                                + ' 	<td>' + cms_timestamp_to_local_date(info.next_run,get_unit_date_format()+' h:I:s') + '</td>'
                                + ' 	<td width="20" align="right"><input type="button" class="btn_mini" value="..." onClick="editAutomationSchedule('+jsonp.ud.scenes[i].id+','+j+');"></td>'
                                + '</tr>';

                                schedulesArray.push(
                                {
                                    "next_run":info.next_run,
                                    "html_content":scheduleLine
                                }
                                );
                            }
                        }
                    } catch(err){

                    }
                }
            }
        }

        if(countTimers==0){
            return "No upcoming schedules";
        }else{
            // sort scheduleArray by next_run
            schedulesArray.sort(sortByNextRun);
            var schedulesHTML = '';
            for(var i=0; i<countTimers; i++){
                schedulesHTML += schedulesArray[i].html_content;
            }
        }

        var html = '<table width="100%" cellpadding="1" cellspacing="0">'
        + '<tr class="table_head">'
        + '		<td>' +"Scene" + '</td>'
        + '		<td>' + "Name" + '</td>'
        + ' 	<td>' + "Next run" + '</td>'
        + ' 	<td>'+"Setup"+'</td>'
        + '</tr>';
        html += schedulesHTML;
        html += '</table>';

        return html;

@ Brientim
Thank you very much for the elements of answers!
I’m not really at ease in programming, :-[
To get a result in a php pages could you tell me more?

ThX!

I believe you can suck the entire data state down from Vera using:

http://YourVeraIPAddress:3480/data_request?id=user_data2&output_format=json
It’s a lot of data … buried in it are the tidbits you are looking for …
Reviewing the code from @Brientim will help you navigate some the details of the data structure.

This is not a trivial exercise … but you will learn a lot about Vera’s data structures if you continue to pursue it.

You might look for a web based JSON pretty printer to format the data in a more user friendly manner. It’s difficult to see the structure other wise.

Here is a php code to display the future programmed scenes.
It display “today”, “tomorrow” or the date followed by the scene name; according to the event date registered in the scene.

Just change the LOGIN/PASS/ID variables to fit your unit.

[code]<?php
function veraConnect($usr, $pwd, $id) {
// Search the right fwd server
$units = json_decode(file_get_contents(‘https://sta1.mios.com/locator_json.php?username=’ . $usr));
if (!empty ($units)) {
foreach ($units->units as $unit) {
if ($unit->serialNumber == $id) {
// If the vera ID is the same than the one we want to connect to
$data = json_decode(file_get_contents(‘https://’ . $unit->active_server . ‘/’ . $usr . ‘/’ . $pwd . ‘/’ . $id . ‘/data_request?id=user_data2’));
if (empty($data)) {
// If the result is empty, we try again (maybe we can be stuck here, need to add a counter and an exit)
$data = veraConnect($usr, $pwd, $id);
}
}
}
}
return $data;
}

// Init connect variables
$veraUsr = ‘LOGIN’;
$veraPwd = ‘PASS’;
$veraId = ‘ID’;

// Init weekdays array
$daysInFrench = array(
‘0’ => ‘Sunday’,
‘1’ => ‘Monday’,
‘2’ => ‘Tuesday’,
‘3’ => ‘Wednesday’,
‘4’ => ‘Thursday’,
‘5’ => ‘Friday’,
‘6’ => ‘Saturday’,
‘7’ => ‘Today’,
‘8’ => ‘Tomorrow’
);

// Connect the Vera via fwd
$veraData = veraConnect($veraUsr, $veraPwd, $veraId);
if (!empty($veraData)) {
// Init an array if there is something to fetch
$incommingShedules = array();

foreach ($veraData->scenes as $scene) {
// For every scene
if ($scene->timers != null) {
// If the scen got a timer
foreach ($scene->timers as $timer) {
// For every timer
$incommingShedules[$timer->next_run] .= ($incommingShedules[$timer->next_run] != ‘’ ? ‘|’ : ‘’) . $scene->name;
}
}
}
if (count($incommingShedules) > 0) {
// If there are timers
if (ksort($incommingShedules) == true) {
// If the sort goes well
while (list($key, $value) = each($incommingShedules)) {
// For each timer
$valueExploded = explode(‘|’, $value);
foreach ($valueExploded as $sceneName) {
// For each scene name
if (date(‘w’, $key) == date(‘w’)) {
// If the day in the scene is today
$dayInFrench = ‘7’;
}
else if (date(‘w’, $key) == date(‘w’, strtotime(‘+1 day’))) {
// SOf if it is tomorrow
$dayInFrench = ‘8’;
}
else {
// Else, it is another future day
$dayInFrench = date(‘w’, $key);
}
echo $daysInFrench[$dayInFrench] . ’ ? ’ . date(‘H:i’, $key) . ’ : ’ . $sceneName . ‘
’;
}
}
} else {
echo ‘Sort error’;
}
} else {
echo ‘No event’;
}
} else {
echo ‘Not able to connect to Vera n?’ . $veraId;
}
?>[/code]