This project turns appliances and such On/off using Apple's homekit and a node.js server on raspberry pi (https://github.com/KhaosT/HAP-NodeJS). So Light_accessory.js, when vaule is true(1), turns a lamp(relay) on using a child process and wiring pi. It also needs to turn the lamp off (gpio write 7 1) when value is false(0). I have tried adding IF statements to it (near the end), but I keep getting syntax errors from the if statements.. Don't know why. //frustrated.
// HomeKit types required
var types = require("./types.js")
var exports = module.exports = {};
var exec = require('child_process').exec;
var execute = function(accessory, characteristic, value) {
console.log("executed accessory: " + accessory + ", and characteristic: " + characteristic + ", with value: " + value + ".");
}
exports.accessory = {
displayName: "Light",
username: "1A:2B:4A:4D:5E:FF",
pincode: "031-45-154",
services: [{
sType: types.ACCESSORY_INFORMATION_STYPE,
characteristics: [{
cType: types.NAME_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "Light 0",
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255
}, {
cType: types.MANUFACTURER_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "Oltica",
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255
}, {
cType: types.MODEL_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "Rev-1",
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255
}, {
cType: types.SERIAL_NUMBER_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "A1S2NASF88EW",
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
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.LIGHTBULB_STYPE,
characteristics: [{
cType: types.NAME_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "Light 1",
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255
}, {
cType: types.POWER_STATE_CTYPE,
onUpdate:
if ((function(value)) == 1) {
exec('gpio write 7 0' + value,function(error, stdout, stderr) {}
},
if ((function(value)) == 0) {
exec('gpio write 7 1' + value,function(error, stdout, stderr) {}
},
);
},
perms: ["pw", "pr", "ev"],
format: "bool",
initialValue: false,
supportEvents: false,
supportBonjour: false,
manfDescription: "Turn On the Light",
designedMaxLength: 1
},
}]
}]
}