Skip to content

Instantly share code, notes, and snippets.

@jarrodbell
Last active August 29, 2015 14:10
Show Gist options
  • Save jarrodbell/6b0078091eb398f081ab to your computer and use it in GitHub Desktop.
Save jarrodbell/6b0078091eb398f081ab to your computer and use it in GitHub Desktop.
Fibaro device ID value processing
// Map a Fibaro device ID to a join number
// The join number should be prefixed by the join type (a = analog, d = digital, s = serial, etc)
var joinIDMap = {
"12": "a1002",
"1": "a1015",
"45": "a1043",
"23": "a1008"
};
// Eg. doCommand("callAction", 168, "turnOn");
function doCommand(method, deviceId, name) {
CF.request("http://192.168.1.5/api/"+method+"?deviceID="+deviceId+"&name="+name, {"Authorization": "Basic YWRtaW46YWRtaW4="}, processResponse);
}
function processResponse (status, headers, body) {
if (status == 200) {
var data = JSON.parse(body);
// Loop through each device in the response data
for (var device in data) {
// Check if there is a join mapped to the device ID
if (joinIDMap.hasOwnProperty(device.id)) {
// Get the join number from the map object
var join = joinIDMap[device.id];
// Update a join in the GUI, based on the join type and value returned
if (join.substr(0, 1) == "a") {
// The join being updated is analog, so perform some conversion of the data ready for analog guage/slider display
var value = Math.round(device.properties.value*655.36);
// Update the join in the GUI
CF.setJoin(join, value);
} else {
// The join is either digital or serial, so just update the value directly
CF.setJoin(join, device.properties.value);
}
}
}
CF.log("Fibaro : Command Send OK, Devices Returned: " + data.length);
} else {
CF.log("Fibaro : Command Send ERROR");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment