Skip to content

Instantly share code, notes, and snippets.

@Jxck-S
Created September 3, 2018 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jxck-S/f05046d374826bfdaba083a5d6a11fb5 to your computer and use it in GitHub Desktop.
Save Jxck-S/f05046d374826bfdaba083a5d6a11fb5 to your computer and use it in GitHub Desktop.
outlet_accessory.js
// HomeKit types required
var request = require('request');
var types = require("./types.js");
var exports = module.exports = {};
exports.accessory = {
displayName: 'Weaved SmartPlug',
username: "C2:32:3F:EG:AE:F1",
pincode: "031-45-154",
services: [{
sType: types.ACCESSORY_INFORMATION_STYPE,
characteristics: [{
cType: types.NAME_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "Outlet",
supportEvents: false,
supportBonjour: false,
manfDescription: "Name of the accessory",
designedMaxLength: 255
},{
cType: types.MANUFACTURER_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: 'Weaved Inc.',
supportEvents: false,
supportBonjour: false,
manfDescription: "Manufacturer",
designedMaxLength: 255
},{
cType: types.MODEL_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "Rev-1",
supportEvents: false,
supportBonjour: false,
manfDescription: "Model",
designedMaxLength: 255
},{
cType: types.SERIAL_NUMBER_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "A1S2NASF88EW",
supportEvents: false,
supportBonjour: false,
manfDescription: "SN",
designedMaxLength: 255
},{
cType: types.IDENTIFY_CTYPE,
onUpdate: null,
perms: ["pw"],
format: "bool",
initialValue: false,
supportEvents: false,
supportBonjour: false,
manfDescription: "Identify Accessory",
designedMaxLength: 1
}]
},{
sType: types.OUTLET_STYPE,
characteristics: [{
cType: types.NAME_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: 'SmartPlug Control',
supportEvents: false,
supportBonjour: false,
manfDescription: "Name of service",
designedMaxLength: 255
},{
cType: types.POWER_STATE_CTYPE,
onUpdate: function(value)
{
console.log("Change:",value);
if (value) {
request('http://192.168.0.10/cgi-bin/devOn.sh', function (error, resp, body) {
if (!error) {
console.log("On Success");
};
});
} else {
request('http://192.168.0.10/cgi-bin/devOff.sh', function (error, resp, body) {
if (!error) {
console.log("Off Success");
};
});
}
},
perms: ["pw","pr","ev"],
format: "bool",
initialValue: false,
supportEvents: false,
supportBonjour: false,
manfDescription: "Change the power state of the outlet",
designedMaxLength: 1
}]
}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment