'use strict'; // // HomeSeer Platform Shim for HomeBridge // V0.1 - Jean-Michel Joudrier (stipus at stipus dot com) - 2015/10/07 // - Initial version // V0.2 - Jean-Michel Joudrier (stipus at stipus dot com) - 2015/10/10 // - Occupancy sensor fix // V0.3 - Jean-Michel Joudrier (stipus at stipus dot com) - 2015/10/11 // - Added TemperatureUnit=F|C option to temperature sensors // - Added negative temperature support to temperature sensors // V0.4 - Jean-Michel Joudrier (stipus at stipus dot com) - 2015/10/12 // - Added thermostat support // V0.5 - Jean-Michel Joudrier (stipus at stipus dot com) - 2015/10/12 // - Added Humidity sensor support // V0.6 - Jean-Michel Joudrier (stipus at stipus dot com) - 2015/10/12 // - Added Battery support // - Added low battery support for all sensors // - Added HomeSeer event support (using HomeKit switches...) // // // Remember to add platform to config.json. // // You can get HomeSeer Device References by clicking a HomeSeer device name, then // choosing the Advanced Tab. // // Example: // "platforms": [ // { // "platform": "HomeSeer", // Required // "name": "HomeSeer", // Required // "host": "http://192.168.3.4:81", // Required - If you did setup HomeSeer authentication, use "http://user:password@ip_address:port" // // "events":[ // Optional - List of Events - Currently they are imported into HomeKit as switches // { // "eventGroup":"My Group", // Required - The HomeSeer event group // "eventName":"My Event", // Required - The HomeSeer event name // "name":"Test" // Optional - HomeSeer event name is the default // } // ], // // "accessories":[ // Required - List of Accessories // { // "ref":8, // Required - HomeSeer Device Reference (To get it, select the HS Device - then Advanced Tab) // "type":"Lightbulb", // Optional - Lightbulb is the default // "name":"My Light", // Optional - HomeSeer device name is the default // "offValue":"0", // Optional - 0 is the default // "onValue":"100", // Optional - 100 is the default // "can_dim":true // Optional - true is the default - false for a non dimmable lightbulb // }, // { // "ref":9 // This is a dimmable Lightbulb by default // }, // { // "ref":58, // This is a controllable outlet // "type":"Outlet" // }, // { // "ref":111, // Required - HomeSeer Device Reference for your sensor // "type":"TemperatureSensor", // Required for a temperature sensor // "temperatureUnit":"F", // Optional - C is the default // "name":"Bedroom temp", // Optional - HomeSeer device name is the default // "batteryRef":112, // Optional - HomeSeer device reference for the sensor battery level // "batteryThreshold":15 // Optional - If sensor battery level is below this value, the HomeKit LowBattery characteristic is set to 1. Default is 10 // }, // { // "ref":113, // Required - HomeSeer Device Reference of the Current Temperature Device // "type":"Thermostat", // Required for a Thermostat // "name":"Température Salon", // Optional - HomeSeer device name is the default // "temperatureUnit":"C", // Optional - F for Fahrenheit, C for Celsius, C is the default // "setPointRef":167, // Required - HomeSeer device reference for your thermostat Set Point. // "setPointReadOnly":true, // Optional - Set to false if your SetPoint is read/write. true is the default // "stateRef":166, // Required - HomeSeer device reference for your thermostat current state // "stateOffValues":[0,4,5], // Required - List of the HomeSeer device values for a HomeKit state=OFF // "stateHeatValues":[1], // Required - List of the HomeSeer device values for a HomeKit state=HEAT // "stateCoolValues":[2], // Required - List of the HomeSeer device values for a HomeKit state=COOL // "stateAutoValues":[3], // Required - List of the HomeSeer device values for a HomeKit state=AUTO // "controlRef":168, // Required - HomeSeer device reference for your thermostat mode control (It can be the same as stateRef for some thermostats) // "controlOffValue":0, // Required - Value for OFF // "controlHeatValue":1, // Required - Value for HEAT // "controlCoolValue":2, // Required - Value for COOL // "controlAutoValue":3, // Required - Value for AUTO // "coolingThresholdRef":169, // Optional - Not-implemented-yet - HomeSeer device reference for your thermostat cooling threshold // "heatingThresholdRef":170 // Optional - Not-implemented-yet - HomeSeer device reference for your thermostat heating threshold // }, // { // "ref":115, // Required - HomeSeer Device Reference for a device holding battery level (0-100) // "type":"Battery", // Required for a Battery // "name":"Roomba battery", // Optional - HomeSeer device name is the default // "batteryThreshold":15 // Optional - If the level is below this value, the HomeKit LowBattery characteristic is set to 1. Default is 10 // } // ] // } // ], // // // SUPORTED TYPES: // - Lightbulb (can_dim, onValue, offValue options) // - Fan (onValue, offValue options) // - Switch (onValue, offValue options) // - Outlet (onValue, offValue options) // - Thermostat (temperatureUnit, setPoint, state, control options) // - TemperatureSensor (temperatureUnit=C|F) // - ContactSensor (0=no contact, 1=contact - batteryRef, batteryThreshold option) // - MotionSensor (0=no motion, 1=motion - batteryRef, batteryThreshold option) // - LeakSensor (0=no leak, 1=leak - batteryRef, batteryThreshold option) // - LightSensor (HomeSeer device value in Lux - batteryRef, batteryThreshold option) // - HumiditySensor (HomeSeer device value in % - batteryRef, batteryThreshold option) // - OccupancySensor (0=no occupancy, 1=occupancy - batteryRef, batteryThreshold option) // - SmokeSensor (0=no smoke, 1=smoke - batteryRef, batteryThreshold option) // - Battery (batteryThreshold option) // - Door var Service = require("HAP-NodeJS").Service; var Characteristic = require("HAP-NodeJS").Characteristic; var request = require("request"); function httpRequest(url, method, callback) { request({ url: url, method: method }, function (error, response, body) { callback(error, response, body) }) } function HomeSeerPlatform(log, config){ this.log = log; this.config = config; } HomeSeerPlatform.prototype = { accessories: function(callback) { var that = this; var foundAccessories = []; if( this.config.events ) { this.log("Creating HomeSeer events."); for( var i=0; i