Plugins

Plugin architecture that allows you to create your own device integerations.

Remarks

The Home Remote has many device integrations already built into the software. Please check the compatibility list first to see if whether you actually need a custom plugin.

The plugin interacts with the app through Device Objects. A user can have any number of Device Objects configured for the plugin. It's the Plugin's responsibility to set a the device's state through its attributes. Each attribute is a property on the Device Object. You will typically update this state information in the OnPoll event or OnConnect event. When a user tries to control a plugin device from a button click, for example, the Plugin OnChangeRequest will fire. It is here that you should send your control commands. At this point, the device object's attributes haven't been updated. The requested values sent by the button are supplied as parameters to the event.

The top of the JavaScript plugin should contain all of your initialization code:
-Set event handlers & properties on the "plugin" object
-Initialize any global variables
-Do not try to send any network requests outside of a JavaScript function. Most of your code should reside in the plugin event handlers.

Useful functions available include:
-sleep(milliseconds)
-console.log(string)

Example

plugin.Name = "VirtualDeviceExample";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 1000;
function onChangeRequest(device, attribute, value) {
switch (attribute) {
case "Switch":
device.Switch = value;
break;
default:
break;
}
}
function onConnect() {
console.log("connected");
}
function onDisconnect() {
console.log("disconnected");
}
function onPoll() {
console.log("polling");
}
function onSynchronizeDevices() {
var virtualSwitch = new Device();
virtualSwitch.Id = "1";
virtualSwitch.DisplayName = "Virtual Switch";
virtualSwitch.Capabilities = ["Switch"];
virtualSwitch.Attributes = [];
plugin.Devices[virtualSwitch.Id] = virtualSwitch;
}

Properties

PropertyDescription
DevicesCollection of Device objects configured by the user. The plugin can provide an initial or default set by handling the OnSynchronizeDevices event. If you don't handle that event, each device can be configured manually by the user.
PollingIntervalInterval in milliseconds in between consecutive polling calls.
SettingsThis is a collection of settings that can be configured in the app. Editing of the JavaScript won't be possible in the app. So use the Settings collection to store settings that will vary by user. You would typically use this property to store items like an IP addresses, ports, etc. You should provide default values for these Settings at the top of your JavaScript file with the rest of your initialization code.

Events

EventDescription
OnConnectRaised when app opens or resumes.
OnDisconnectRaised when app closes or suspends. Typically used to close any connections that may be open.
OnPollRaised when PollingInterval elapses. If PollingInterval is -1 this event will only fire 1 time after connect.
OnChangeRequestRaised when user attempts to change a device variable/attribute from the UI.
OnSynchronizeDevicesRaised when user invokes the "Synchronize Devices" function from the App or Designer control menu. If you implement this handler you should populate the "plugin.Devices" array with all available devices for your plugin.