Battery Service
UUID: 00000096-0000-1000-8000-0026BB765291
Required Characteristics
Optional Characteristics
Example
The example below is automatically generated and may not be a complete example of what is required to create a working "Battery Service" Homebridge plugin. Note
// Example Battery Service Plugin module.exports = (api) => { api.registerAccessory('ExampleBatteryServicePlugin', ExampleBatteryServiceAccessory); }; class ExampleBatteryServiceAccessory { constructor(log, config, api) { this.log = log; this.config = config; this.api = api; this.Service = this.api.hap.Service; this.Characteristic = this.api.hap.Characteristic; // extract name from config this.name = config.name; // create a new Battery Service service this.service = new this.Service(this.Service.BatteryService); // create handlers for required characteristics this.service.getCharacteristic(this.Characteristic.BatteryLevel) .on('get', this.handleBatteryLevelGet.bind(this)); this.service.getCharacteristic(this.Characteristic.ChargingState) .on('get', this.handleChargingStateGet.bind(this)); this.service.getCharacteristic(this.Characteristic.StatusLowBattery) .on('get', this.handleStatusLowBatteryGet.bind(this)); } /** * Handle requests to get the current value of the "Battery Level" characteristic */ handleBatteryLevelGet(callback) { this.log.debug('Triggered GET BatteryLevel'); // set this to a valid value for BatteryLevel const currentValue = 1; callback(null, currentValue); } /** * Handle requests to get the current value of the "Charging State" characteristic */ handleChargingStateGet(callback) { this.log.debug('Triggered GET ChargingState'); // set this to a valid value for ChargingState const currentValue = 1; callback(null, currentValue); } /** * Handle requests to get the current value of the "Status Low Battery" characteristic */ handleStatusLowBatteryGet(callback) { this.log.debug('Triggered GET StatusLowBattery'); // set this to a valid value for StatusLowBattery const currentValue = 1; callback(null, currentValue); } }