homebridge-mvc
Homebridge-mvc is a Plugin for Homebridge. This Example-plugin is based on MVC (Model-View-Controller) pattern.
Have a look at homebridge-mqtt for a practical implementation.
Installation
If you are new to homebridge, please follow the instructions in homebridge for the homebridge server installation.
Install homebridge-mvc:
sudo npm install -g homebridge-mvc
Configuration
Add the platform in config.json in your home directory inside .homebridge
.
API
- addAccessory()
- addService()
- removeAccessory()
- removeService()
- setValue()
- getAccessories()
- updateReachability()
- setAccessoryInformation()
- get()
- set()
- identify()
Howto examples
- Define your homebridge platform in index.js:
var platform_name = "myPlatform";
Note: remeber to change config.json
for your platform.
- Modify the functions for your plugin in model.js
add accessory
accessory = {"name": "flex_lamp", "service_name": "light", "service": "Switch"};result = addAccessory;
add service
Note: an accessory with the same name must be added before.
accessory = {"name": "multi_sensor", "service_name": "Humidity", "service": "HumiditySensor"};result = addService;
remove accessory
accessory = {"name": "flex_lamp"};result = removeAccessory;
remove service
accessory = {"name": "multi_sensor", "service_name": "Humidity"};result = removeService;
get accessory/accessories
The purpose of this function is to retrieve accessory definitions.
accessory = {"name": "outdoor_temp"};result = getAccessories;
accessory = {"name": "*"};result = getAccessories;
set value
accessory = {"name": "flex_lamp", "service_name": "light", "characteristic": "On", "value": true};result = setValue;
update reachability
accessory = {"name": "flex_lamp", "reachable": true};oraccessory = {"name": "flex_lamp", "reachable": false};result = updateReachability;
set accessory information
accessory = {"name": "flex_lamp", "manufacturer": "espressif", "model": "esp8266-12", "serialnumber": "4711"};result = setAccessoryInformation;
get (from homebridge)
Model.prototype.get = function {...}
set (from homebridge)
Model.prototype.set = function {...}
identify (from homebridge)
Model.prototype.identify =
define characterstic
The required characteristics are added with the default properties. If you need to change the default, define the characteristic-name with the properties. e.g.:
accessory = ;result = addAccessory;
To add an optional charachteristic define the characteristic-name with "default" or with the properties. e.g.:
accessory = ;result = addAccessory;
accessory = ;result = addAccessory;
HomeKitTypes.js describes all the predifined Services, Characteristcs, format and properties for the value
e.g.:
/**
* Service "Contact Sensor"
*/
Service.ContactSensor = function(displayName, subtype) {
Service.call(this, displayName, '00000080-0000-1000-8000-0026BB765291', subtype);
// Required Characteristics
this.addCharacteristic(Characteristic.ContactSensorState);
// Optional Characteristics
this.addOptionalCharacteristic(Characteristic.StatusActive);
this.addOptionalCharacteristic(Characteristic.StatusFault);
this.addOptionalCharacteristic(Characteristic.StatusTampered);
this.addOptionalCharacteristic(Characteristic.StatusLowBattery);
this.addOptionalCharacteristic(Characteristic.Name);
};
/**
* Characteristic "Contact Sensor State"
*/
Characteristic.ContactSensorState = function() {
Characteristic.call(this, 'Contact Sensor State', '0000006A-0000-1000-8000-0026BB765291');
this.setProps({
format: Characteristic.Formats.UINT8,
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
inherits(Characteristic.ContactSensorState, Characteristic);
Characteristic.ContactSensorState.UUID = '0000006A-0000-1000-8000-0026BB765291';
// The value property of ContactSensorState must be one of the following:
Characteristic.ContactSensorState.CONTACT_DETECTED = 0;
Characteristic.ContactSensorState.CONTACT_NOT_DETECTED = 1;
Derived from this:
service = ContactSensor
characteristic = ContactSensorState
format = UINT8
property = 0 or 1