question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Custom services and characteristics

See original GitHub issue

Hi, One easy way is to expand HomeKitTypes.js I’m using:

  1. build a file HomeKitTypes-Custom.js with your custom characteristics and services e.g.:
var inherits = require('util').inherits;
var Characteristic = require('../Characteristic').Characteristic;
var Service = require('../Service').Service;


/**
  * Characteristic "Current Air Pressure"
  */

Characteristic.CurrentAirPressure = function() {
  Characteristic.call(this, 'CurrentAirPressure', '00000102-0000-1000-8000-0026BB765291');
  this.setProps({
    format: Characteristic.Formats.UINT16,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
  });
  this.value = this.getDefaultValue();
};

inherits(Characteristic.CurrentAirPressure, Characteristic);

Characteristic.CurrentAirPressure.UUID = '00000102-0000-1000-8000-0026BB765291';

/**
 * Service "Air Pressure Sensor"
 */

Service.AirPressureSensor = function(displayName, subtype) {
  Service.call(this, displayName, '00000101-0000-1000-8000-0026BB765291', subtype);

  // Required Characteristics
  this.addCharacteristic(Characteristic.CurrentAirPressure);

  // Optional Characteristics
  this.addOptionalCharacteristic(Characteristic.Name);
};

inherits(Service.AirPressureSensor, Service);

Service.AirPressureSensor.UUID = '00000101-0000-1000-8000-0026BB765291';
  1. copy HomeKitTypes-Custom.js into the same hap-nodejs folder as HomeKitTypes.js (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/gen)

  2. add this line a the end of HomeKitTypes.js

var HomeKitTypesCustom = require('./HomeKitTypes-Custom');
  1. restart homebridge

The disadvantage using this method: you have to copy/edit the files after updating homebridge/hap-nodejs. A user friendly solution would be to be able to store HomeKitTypes-Custom.js inside .homebridge.

Any other suggestions?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:26 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
nfarinacommented, Dec 8, 2019

You should not be editing Homebridge - I apologize if it seems like I’m asking you to do that. The code I pasted is plugin code. If you are developing a custom accessory and wishing to expose it to HomeKit, then you need to either run your own HAP-NodeJS server inside your accessory, or write a plugin for Homebridge so that other end-users can use your accessory by way of Homebridge.

You can make a Lightbulb contain as many characteristics as you want—custom or otherwise—provided you are writing a plugin for Homebridge, you can define your accessory to be whatever you’d like.

So there are three pieces here:

  • Homebridge, the open source platform that end-users must install and run themselves
  • Homebridge Plugin, which the end-user must install and set up themselves
  • Your hardware accessory (lightbulb), which the end-user gets (somehow) and sets up themselves.

Provided that the user sets up those three components, your plugin can do whatever it wishes within the known limits of the HomeKit API.

Am I making sense or just making things more confusing?

1reaction
iangray001commented, Dec 8, 2019

Sorry Nick, I really do appreciate you taking time here, but I don’t think you’re engaging with what I’m saying.

I’m not aiming to, and shouldn’t have to, touch the code of Homebridge. I’m an accessory developer trying to use Homekit features that it appears are not supported by Homebridge.

I think the source of the confusion here is that you seem to be under the misapprehension that Lightbulb may only ever contain the four characteristics. This is not true. Lightbulb may contain any number of characteristics. One mandatory, three defined optional, and as many other custom ones as the accesssory defines.

It is possible for an accessory to talk to an entirely standard Homekit server and say “I support a Lightbulb but it has a uint8 parameter called WhateverIWant”.

People keep telling me to edit Homebridge, but this makes no sense because what I want to do is standard Homekit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature request: Custom services and characteristics #1453
Hi, One easy way is to expand HomeKitTypes.js I'm using: build a file HomeKitTypes-Custom.js with your custom characteristics and services e.g.:.
Read more >
Bluetooth GATT: How to Design Custom Services ... - Novel Bits
That's where custom profiles, services, and characteristics come in. ... It is the device that sends commands and requests and accepts incoming ...
Read more >
Chapter 4. GATT (Services and Characteristics) - O'Reilly
The Generic Attribute Profile (GATT) establishes in detail how to exchange all profile and user data over a BLE connection. In contrast with...
Read more >
BLE GATT | Adafruit Feather M0 Bluefruit LE
The following commands can be used to create custom GATT services and characteristics on the BLEFriend, which are used to store and exchange...
Read more >
How do you name a Custom Service
For instance - I have a custom service named DIAGNOSTICS. It has 3 custom characteristics. They are Version, Voltage, and Status. On the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found