Skip to main content

Switching between projects

Configuring automatic switching between projects in i3 pro.

Documentation updated 04.6.2021

Automatic project switching starts another project in response to a predefined event. The event can be the user's selection from the list of projects downloaded to the panel, connection to a specified Wi-Fi network that automatically loads a project, or receipt of predefined coordinates by the device.

Important

Project switching works only with projects downloaded to the panel from the cloud.

Configuring project selection from the list downloaded to the panel​

  1. Download the example project.

  2. Merge the example into your project to transfer its data.

DesignSwitch1.png

An additional page with a List item appears in the project. It displays all projects downloaded to the panel from the cloud. Clicking a list item switches to the selected project.

Note

To return to the original project or select another project, you also need to add list-based project switching to the additional project.

DesignSwitch2.png

Example script:

IR.AddListener(IR.EVENT_START, 0, function()  // Actions are performed at start
{
// getting the number of projects
var l_iCount = IR.GetDesignsCount();
//get a list
var list = IR.GetItem("Page 1").GetItem("Item 1");

// making a list of projects
for(var i = 0; i < l_iCount; i++)
{
// get a link to the project
var l_sName = IR.GetDesignByIndex(i);
//сhecking that the project is downloaded from the cloud
if(l_sName.CloudID > 0){
// create a list item (ListItem)
var item = list.AddItem("Popup 1", {
Name: {
Text: l_sName.OriginalName
}
});
//setting custom data to a list item
item.SetData({name: l_sName.OriginalName, id: l_sName.CloudID})
// execute a function when the button is released
item.SetReleaseAction(function(in_item, in_subItem){
var name = in_item.Data.name;
var id = in_item.Data.id;
//switch to the selected project
IR.DesignSwitch(name, id);
IR.Log(name + " " + id);
});
}
}
});

Methods used:

  • IR.GetDesignsCount - counts the visualization projects in the application's memory;
  • IR.GetDesignByIndex - returns a project reference as an object, using its index in the list of downloaded projects;
  • IR.DesignSwitch - switches between visualization projects in the panel's memory.

Configuring automatic project switching by Wi-Fi network name​

  1. Download the example project.

  2. Merge the example into your project to transfer its data, or copy the example script into your project.

DesignSwitch1.png

  1. Open the example script and change:
  • the project name Project1 to the project that will load when connected to the Wi-Fi network ssid1;
  • the Wi-Fi network name ssid1 to the network that should trigger Project1 when connected;
  • the project name Project2 to the project that will load when connected to the Wi-Fi network ssid2;
  • the Wi-Fi network name ssid2 to the network that should trigger Project2 when connected;
  • the project name Project3 to the name of the project that will load when connected to other Wi-Fi networks or mobile internet.

This solution enables automatic switching between automation projects (for example, projects for several apartments, a vacation home, and so on). If needed, you can modify the project script to add more projects and Wi-Fi network names.

Note

For switching to work, all linked projects must contain this script with identical parameter values.

Example script:

(function(){

/**
* Auto project selector
*/
function ProjectSelector(projects)
{
this.trigger = "System.Net.SSID";
this.projects = projects;

IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, this.select, this);
IR.SubscribeTagChange(this.trigger);
IR.AddListener(IR.EVENT_START, 0, this.analize, this);
}

/**
* Select project by trigger
*/
ProjectSelector.prototype.select = function()
{
var selectID = 0;
var selectName = "";
var ssid = IR.GetVariable(this.trigger);
var unknownItem;
for(var j = 0; j < this.projects.length; j++)
{
var item = this.projects[j];
if(item.CloudID == 0)
IR.Log("ProjectSelector: " + item.projectName + " is not found");

if(item.ssid == undefined)
unknownItem = item;

if(item.ssid == ssid && item.CloudID)
{
selectID = item.CloudID;
selectName = item.projectName;
break;
}
}

// не один проект не подошел
if(selectID == 0 && unknownItem != undefined)
{
selectID = unknownItem.CloudID;
selectName = unknownItem.projectName;
}

var currentProject = IR.GetCurrentDesign();
if(currentProject)
{
if(selectID != currentProject.CloudID)
{
IR.Log("ProjectSelector: " + selectName + " will be selected");
IR.DesignSwitch(selectName, selectID);
}
else
IR.Log("ProjectSelector: " + selectName + " selecte skipped, is already started");
}
}

/**
* Analize project names and find his clouds ids
*/
ProjectSelector.prototype.analize = function()
{
var count = IR.GetDesignsCount();
for(var i = 0; i < count; i++)
{
var project = IR.GetDesignByIndex(i);
for(var j = 0; j < this.projects.length; j++)
{
var item = this.projects[j];
if(item.projectName == project.OriginalName)
item.CloudID = project.CloudID;
}
}

this.select();
}

/**
* Make instance
*/
new ProjectSelector([
{
ssid: "ssid1",
projectName: "Project1",
},
{
ssid: "ssid2",
projectName: "Project2",
},
{
/* unknown ssid */
projectName: "Project3",
}
]);
})();

Methods used:

  • IR.GetDesignsCount - counts the visualization projects in the application's memory;
  • IR.GetDesignByIndex - returns a project reference as an object, using its index in the list of downloaded projects;
  • IR.GetVariable - selects the token that triggers the event (this example uses the Wi-Fi network identifier, "System.Net.SSID");
  • IR.DesignSwitch - switches between visualization projects in the panel's memory;
  • IR.SetGlobalListener - creates a global listener;
  • IR.SubscribeTagChange - subscribes to a tag.