Attached is a Plugin that can read & write to Fibaro Global Variables.
https://manuals.fibaro.com/knowledge-base-browse/rest-api/#bkb-h22
To install the plugin, use the Plugin Import utility in the Designer. The import process will ask you for the Host, Port, Username, & Password of the Fibaro controller.
Included is a generic Tile Template for this device. To add this to your project, simply download the file & then copy and paste it into the Pages folder with the other XAML files.
GlobalVariableTile.xaml (1.2 KB)
Here is the plugin code:
FibaroGlobalVariables.plugin (1.9 KB)
plugin.Name = "FibaroGlobalVariables";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 5000;
plugin.DefaultSettings = { "Host": "192.168.1.100", "Port": "80", "Username": "", "Password": "" };
var http = new HTTPClient();
var baseURL = null;
var credentials = {}
function onChangeRequest(device, attribute, value) {
switch (attribute) {
case "VariableValue":
http.put(baseURL + "/globalVariables/" + device.Id, { name: device.Id, value: value, readOnly: false, isEnum: false }, { auth: credentials });
break;
default:
break;
}
}
function onConnect() {
baseURL = "http://" + plugin.Settings["Host"] + ":" + plugin.Settings["Port"] + "/api";
credentials = {
username: plugin.Settings["Username"],
password: plugin.Settings["Password"]
}
}
function onDisconnect() {
}
function onPoll() {
var r = http.get(baseURL + "/globalVariables", { auth: credentials });
var variables = r.data;
for (var v in variables) {
var variable = variables[v];
var pluginDevice = plugin.Devices[variable.name];
if (pluginDevice) {
pluginDevice.VariableValue = variable.value;
}
}
}
function onSynchronizeDevices() {
var r = http.get(baseURL + "/globalVariables", { auth: credentials });
var variables = r.data;
for (var v in variables) {
var variable = variables[v];
var device = new Device();
device.Id = variable.name;
device.DisplayName = variable.name;
device.DeviceType = "GlobalVariable";
device.Attributes = ["VariableValue"];
device.TileTemplate = "GlobalVariableTile.xaml";
plugin.Devices[device.Id] = device;
}
}