Git Product home page Git Product logo

homebridge-plugin-template's Introduction

Homebridge Platform Plugin Template

Important

Homebridge v2.0 Information

This template currently has a

  • package.json -> engines.homebridge value of "^1.8.0 || ^2.0.0-beta.0"
  • package.json -> devDependencies.homebridge value of "^2.0.0-beta.0"

This is to ensure that your plugin will build and run on both Homebridge v1 and v2.

Once Homebridge v2.0 has been released, you can remove the -beta.0 in both places.

Important

Node v22 Information

This template currently has a

  • package.json -> engines.node value of "^18.20.4 || ^20.16.0 || ^22.5.1"

This is to remind developers that plugins should be supporting Node v22 from October 2024.


This is a template Homebridge dynamic platform plugin and can be used as a base to help you get started developing your own plugin.

This template should be used in conjunction with the developer documentation. A full list of all supported service types, and their characteristics is available on this site.

Clone As Template

Click the link below to create a new GitHub Repository using this template, or click the Use This Template button above.

Setup Development Environment

To develop Homebridge plugins you must have Node.js 18 or later installed, and a modern code editor such as VS Code. This plugin template uses TypeScript to make development easier and comes with pre-configured settings for VS Code and ESLint. If you are using VS Code install these extensions:

Install Development Dependencies

Using a terminal, navigate to the project folder and run this command to install the development dependencies:

npm install

Update package.json

Open the package.json and change the following attributes:

  • name - this should be prefixed with homebridge- or @username/homebridge-, is case-sensitive, and contains no spaces nor special characters apart from a dash -
  • displayName - this is the "nice" name displayed in the Homebridge UI
  • homepage - link to your GitHub repo's README.md
  • repository.url - link to your GitHub repo
  • bugs.url - link to your GitHub repo issues page

When you are ready to publish the plugin you should set private to false, or remove the attribute entirely.

Update Plugin Defaults

Open the src/settings.ts file and change the default values:

  • PLATFORM_NAME - Set this to be the name of your platform. This is the name of the platform that users will use to register the plugin in the Homebridge config.json.
  • PLUGIN_NAME - Set this to be the same name you set in the package.json file.

Open the config.schema.json file and change the following attribute:

  • pluginAlias - set this to match the PLATFORM_NAME you defined in the previous step.

Build Plugin

TypeScript needs to be compiled into JavaScript before it can run. The following command will compile the contents of your src directory and put the resulting code into the dist folder.

npm run build

Link To Homebridge

Run this command so your global installation of Homebridge can discover the plugin in your development environment:

npm link

You can now start Homebridge, use the -D flag, so you can see debug log messages in your plugin:

homebridge -D

Watch For Changes and Build Automatically

If you want to have your code compile automatically as you make changes, and restart Homebridge automatically between changes, you first need to add your plugin as a platform in ~/.homebridge/config.json:

{
...
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "platform": "config"
        },
        {
            "name": "<PLUGIN_NAME>",
            //... any other options, as listed in config.schema.json ...
            "platform": "<PLATFORM_NAME>"
        }
    ]
}

and then you can run:

npm run watch

This will launch an instance of Homebridge in debug mode which will restart every time you make a change to the source code. It will load the config stored in the default location under ~/.homebridge. You may need to stop other running instances of Homebridge while using this command to prevent conflicts. You can adjust the Homebridge startup command in the nodemon.json file.

Customise Plugin

You can now start customising the plugin template to suit your requirements.

Versioning Your Plugin

Given a version number MAJOR.MINOR.PATCH, such as 1.4.3, increment the:

  1. MAJOR version when you make breaking changes to your plugin,
  2. MINOR version when you add functionality in a backwards compatible manner, and
  3. PATCH version when you make backwards compatible bug fixes.

You can use the npm version command to help you with this:

# major update / breaking changes
npm version major

# minor update / new features
npm version update

# patch / bugfixes
npm version patch

Publish Package

When you are ready to publish your plugin to npm, make sure you have removed the private attribute from the package.json file then run:

npm publish

If you are publishing a scoped plugin, i.e. @username/homebridge-xxx you will need to add --access=public to command the first time you publish.

Publishing Beta Versions

You can publish beta versions of your plugin for other users to test before you release it to everyone.

# create a new pre-release version (eg. 2.1.0-beta.1)
npm version prepatch --preid beta

# publish to @beta
npm publish --tag=beta

Users can then install the beta version by appending @beta to the install command, for example:

sudo npm install -g homebridge-example-plugin@beta

Best Practices

Consider creating your plugin with the Homebridge Verified criteria in mind. This will help you to create a plugin that is easy to use and works well with Homebridge. You can then submit your plugin to the Homebridge Verified list for review. The most up-to-date criteria can be found here. For reference, the current criteria are:

  • The plugin must successfully install.
  • The plugin must implement the Homebridge Plugin Settings GUI.
  • The plugin must not start unless it is configured.
  • The plugin must not execute post-install scripts that modify the users' system in any way.
  • The plugin must not contain any analytics or calls that enable you to track the user.
  • The plugin must not throw unhandled exceptions, the plugin must catch and log its own errors.
  • The plugin must be published to npm and the source code available on GitHub.
    • A GitHub release - with patch notes - should be created for every new version of your plugin.
  • The plugin must run on all supported LTS versions of Node.js, at the time of writing this is Node.js v16 and v18.
  • The plugin must not require the user to run Homebridge in a TTY or with non-standard startup parameters, even for initial configuration.
  • If the plugin needs to write files to disk (cache, keys, etc.), it must store them inside the Homebridge storage directory.

Useful Links

Note these links are here for help but are not supported/verified by the Homebridge team

homebridge-plugin-template's People

Contributors

ahorvat avatar bwp91 avatar cclauss avatar chriscn avatar christiantschoerner avatar clemlatz avatar dependabot[bot] avatar dkerr64 avatar donavanbecker avatar godley avatar jctim avatar jstastny avatar kyle-seongwoo-jun avatar ncovercash avatar northernman54 avatar o-lukas avatar oznu avatar takeyaqa avatar yasuoza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

homebridge-plugin-template's Issues

Error. No plugin was found for the platform. Cannot find module.

I have similar problem that #55.

I'm using plugin template, updated 4 days ago by @bwp91 (update plugin template to be es module).

My repo: https://github.com/mkz212/homebridge-virtual-device.

Installing to Homebridge directly from github repo using Homebridge Terminal command: npm install mkz212/homebridge-virtual-device. On FTP, it looks like all files have installed correctly, including the 'dist' directory (in package.json i have script: "prepare": "npm run build"). In the UI in the plugin tab it is displayed (there is only no author and website). But in the logs after restart, it shows a message:

IMG_6054

or

IMG_6055

Installing original plugin template shows similar errors.

Installing with '-g' argument causes an error already at the installation stage - can not be installed at all. Has anything changed? In the past you could easily install straight from github repo. Now no plug works like that. E.G. commands in terminal: npm install -g eibenp/homebridge-gree-airconditioner or nom install -g https://github.com/eibenp/homebridge-gree-airconditioner.

Zrzut ekranu 2024-05-31 o 09 23 34

Creating a plugin from a template

Describe Your Problem:
Hello, I am trying to create a plugin using your homebridge/homebridge-plugin-template and I am a novice but having some success but also striking some roadblocks and wanted some advice. I created a repository as per your homebridge README.md and have been working my way through your procedure, Update package.json seems OK, Update Plugin Defaults OK, Build Plugin - npm run build, I ran this in "Terminal" as I didn't know if there was some way to run in Github desktop ?? Anyhow it created the dist and src folders etc. and when I use the "npm link" command in Terminal it creates the plugin in the Homebridge app which is I guess progress but THIS IS WHERE MY PROBLEMS BEGIN, I am assuming because I haven't Customised Plugin that Homebridge cannot communicate with my Lenovo Smart Plug to switch it on and off. I have tried tweaking the src/platform.ts, src/platformAccessory.ts and the config.scema.json files but I thinking I am screwing this up. I tried doing changes but I am getting confused because I am trying to edit on Github but that's obviously not editing my files on my computer. is it possible to create everything on Github and eventually end up with a file that I can use e.g. npm install -g homebridge-myplugin name-platform ???? I assume I will eventually be able to create and import the plugin but completing the plugin or package has got me a bit stumped at the moment if you can offer advice thanks

Wayne

  • Plugin Version:
  • Homebridge Version: homebridge -1.2.3
  • Node.js Version: node -v12.18.4
  • NPM Version: npm -v6.14.8
  • Operating System: macOS

Add devcontainer definition

Is your feature request related to a problem? Please describe:
The main benefit of the devcontainers for me is that I have everything set up and ready to go after a few minutes and do not have to struggle with setting up node, homebridge, etc. So I went with creating a devcontainer which contains a basic homebridge instance already set up and ready to use.

Describe the solution you'd like:
Add a ready-to-use devcontainer definition.

Describe alternatives you've considered:
None

Additional context:
I prepared a branch which contains the definition files needed to get it working. I can not push it because of permissions but you can check this repository for the definition I used for my first plugin. If you tell me how to publish the branch I prepared I can do this of course so you can see the definition without my plugin specific stuff.

[homebridge-eufy-security] This plugin slows down Homebridge. The write handler for the characteristic 'Selected RTP Stream Configuration' on the accessory 'Office E464' didn't respond at all!. Please check that you properly call the callback! See https://homebridge.io/w/JtMGR for more info.

Describe The Bug:
I am receiving an error when trying to open camera streams for the Eufy cameras.

To Reproduce:
Attempt to open a camera stream in Apple HomeKit.

Expected behavior:
Steam would work consistently every time I open a stream.

Logs:

[7/2/2022, 3:47:11 PM] [homebridge-eufy-security] This plugin slows down Homebridge. The write handler for the characteristic 'Selected RTP Stream Configuration' on the accessory 'Office E464' didn't respond at all!. Please check that you properly call the callback! See https://homebridge.io/w/JtMGR for more info.

Plugin Config:

{
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "platform": "config",
            "auth": "form",
            "tempUnits": "c",
            "lang": "auto",
            "theme": "dark-mode"
        },
        {
            "enableCamera": true,
            "pollingIntervalMinutes": 30,
            "ignoreDevices": [
                ""
            ],
            "hkAway": 0,
            "username": "[email protected]",
            "platform": "EufySecurity",
            "hkHome": 1,
            "hkNight": 3,
            "ignoreStations": [
                ""
            ],
            "hkOff": 63,
            "enableDetailedLogging": 0,
            "password": "password",
            "country": "US",
            "_bridge": {
                "username": "MAC:ADDRESS",
                "port": 59101
            },
            "cameras": [
                {
                    "serialNumber": "SN",
                    "enableCamera": true,
                    "enableButton": true,
                    "motionButton": true,
                    "rtsp": true,
                    "unbridge": true,
                    "forcerefreshsnap": false,
                    "useCachedLocalLivestream": false,
                    "videoConfig": {
                        "audio": true
                    }
                },
                {
                    "serialNumber": "SN",
                    "enableCamera": true,
                    "enableButton": true,
                    "motionButton": true,
                    "rtsp": true,
                    "unbridge": true,
                    "forcerefreshsnap": false,
                    "useCachedLocalLivestream": false,
                    "videoConfig": {
                        "audio": true
                    }
                },
                {
                    "serialNumber": "SN",
                    "enableCamera": true,
                    "enableButton": true,
                    "motionButton": true,
                    "rtsp": true,
                    "unbridge": true,
                    "forcerefreshsnap": false,
                    "useCachedLocalLivestream": false,
                    "videoConfig": {
                        "audio": true
                    }
                },
                {
                    "serialNumber": "SN",
                    "enableCamera": true,
                    "enableButton": true,
                    "motionButton": true,
                    "rtsp": false,
                    "unbridge": true,
                    "forcerefreshsnap": false,
                    "useCachedLocalLivestream": false,
                    "videoConfig": {
                        "audio": true
                    }
                },
                {
                    "serialNumber": "SN",
                    "enableCamera": true,
                    "enableButton": true,
                    "motionButton": true,
                    "rtsp": true,
                    "unbridge": true,
                    "forcerefreshsnap": false,
                    "useCachedLocalLivestream": false,
                    "videoConfig": {
                        "audio": true
                    }
                },
                {
                    "serialNumber": "SN",
                    "enableCamera": true,
                    "enableButton": true,
                    "motionButton": true,
                    "rtsp": true,
                    "unbridge": true,
                    "forcerefreshsnap": false,
                    "useCachedLocalLivestream": false,
                    "videoConfig": {
                        "audio": true
                    }
                }
            ]
        },
        {
            "name": "Wemo",
            "mode": "auto",
            "platform": "Wemo"
        },
        {
            "email": "[email protected]",
            "password": "password",
            "name": "myQ",
            "platform": "myQ"
        },
        {
            "name": "TplinkSmarthome",
            "addCustomCharacteristics": true,
            "broadcast": "IP",
            "deviceTypes": [
                "plug",
                "bulb"
            ],
            "platform": "TplinkSmarthome"
        },
        {
            "name": "Nest",
            "refreshToken": "token",
            "platform": "Nest"
        },
        {
            "refreshToken": "token",
            "options": {
                "ffmpegCodec": "libx264",
                "streamQuality": 2,
                "alertCheckRate": 10,
                "alertCooldownRate": 180,
                "importantOnly": true,
                "motionDetection": true,
                "streamingSwitch": true,
                "announcementsSwitch": true,
                "audioSwitch": true,
                "fieldTest": false
            },
            "platform": "Nest-cam",
            "_bridge": {
                "username": "MAC:ADDRESS",
                "port": 34408
            }
        },
        {
            "name": "Govee",
            "username": "[email protected]",
            "password": "password",
            "apiKey": "api-key",
            "apiWhitelist": true,
            "debug": false,
            "_bridge": {
                "username": "MAC:ADDRESS",
                "port": 49718
            },
            "platform": "Govee"
        }
    ],
    "accessories": [],
    "bridge": {
        "pin": "home-pin",
        "name": "Homebridge 693E",
        "bind": [
            "ens160",
            "ens192"
        ],
        "port": 52238,
        "username": "MAC:ADDRESS",
        "advertiser": "bonjour-hap"
    },
    "disabledPlugins": [
        "homebridge-wemo",
        "homebridge-google-nest-sdm",
        "homebridge-gsh"
    ]
}

Screenshots:
n/a

Environment:

  • Plugin Version: 2.0.1
  • Homebridge Version: 1.50
  • Node.js Version: 16.13.1
  • NPM Version: 8.1.2
  • Operating System: docker on top of Ubuntu 18.04.6 LTS

Possible to controle already existing device ?

Hi , Hum... I don't know anything actually about making HB plugins,
But i have Camera that i added to Homekit with the RTSP plugin and with it got a dummy motion sensor.
Since i can use ONVIF request to get real values from the camera's motion sensor.
I got it to work on python with pyhomebridge but it was not a very good idea since it use HTTP request to trigger the switch (making a request on the same computer is not the best idea) and it use python what is not the final goal..
Is there a way to get access to switches and other devices from homebridge and controlling them.

thanks

What is that ?

Describe Your Problem:
I want to add this, can you tell me the name or give me the doc page about this: (screenshot)

PS: If you can show me the code โค

Logs:

โŒ

Plugin Config:

โŒ

Screenshots:
image

Environment:

  • Plugin Version: โŒ
  • Homebridge Version: 1.4.1
  • Node.js Version: v16
  • NPM Version: v6
  • Operating System: Raspbian

Addidional accessories

A really great template and everything is very understandable. I only have two questions:

  1. How to set a different name for an additional accessory?

That way?:

motionSensorOneService.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'name we want');

This causes a warning to be displayed in the logs that this is an optional characteristic but adds it anyway.

  1. Do the name and identifier of this additional accessory have to be unique but only for the main device for which they are added or for the entire plugin?

Debug logs is not shown without adding plugin to homebridge configuration

Describe The Bug:

I followed the instructions in the README, but when running (with npm run watch) no logs from my plugin were printed to stdout.

Expected behavior:

The plugin should load and logs should be shown. I expect the instructions for this to happen (change the config) to be in the README.

Plugin Config:

The problem was solved by adding a platform in my config. This was not mentioned anywhere in the README.

{
    "bridge": {
        "name": "******",
        "username": "*******",
        "port": *****,
        "pin": "*****"
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "platform": "config"
        },
        {
            "name": "Platform name",
            "platform": "<plugin platform name>"
        }
    ]
}

Environment:

  • Plugin Version:
  • Homebridge Version: 1.4.0
  • Node.js Version: v17.8.0
  • NPM Version: 8.5.5
  • Operating System: macOS

It would be helpful for beginners to provide instructions about this. I found the solution by accident on the homebridge Discord but it could be a blocker for people when starting out :)

Array in custom characteristic

Describe Your Problem:
I'm trying to create a custom characteristic that shows an array of string.
I'm using the home+ 6 app, which are able to show custom characteristics.

I've created the characteristic based on this issue: #20 (as linked in the README file)

I'm able get the custom characteristic to show, but only if I'm not using the "array" format

I've tried to lookup how saturation in the lightbulb works, however I could only find the definitions.

Code:

import { Formats, Perms, CharacteristicProps } from 'homebridge';

export = (homebridge) => {
  const Charact = homebridge.hap.Characteristic;

  return class EffectCharacteristic extends Charact {
    public static readonly UUID: string = 'f8d871fa-a67a-43fe-872d-5250f055d17c';
      constructor() {
          
        const options: CharacteristicProps = {
            format: Formats.ARRAY, // UINT16 works
            unit: '',
            validValues: [0,1,2,3,4,5,6,7], // Also tried with strings. Removing this allows the accessory to be shown, but not edited
            perms: [Perms.PAIRED_READ, Perms.NOTIFY],
        }
        
        super('Effect', EffectCharacteristic.UUID, options);
        this.value = 0; // And with a string down here
    }
  };
};

Github repo:
https://github.com/Julius-Bendt/homebridge-hyperion

Logs:
None - no errors thrown

Plugin Config:

{
    "name": "HyperionJub",
    "url": "http://192.168.1.107",
    "port": "8090",
    "priority": 50,
    "platform": "HyperionJub"
}

Screenshots:

image

Environment:

  • Plugin Version:
  • Homebridge Version: 1.6.1
  • Node.js Version: 18.17.1
  • NPM Version: 10.0.0
  • Operating System: Windows

Plugin / accessory logging

The readme says:

You can now start Homebridge, use the -D flag, so you can see debug log messages in your plugin

which is nice and all, but I can't see any clear way of how to see only the related messages in the log - does logging use the debug module under the cover, so that it is possible to use the variable DEBUG= e.g. DEBUG=my-plugin:* to filter, or something like that? Either way I think it would be helpful during troubleshooting for both users and devs if the best practice logging was described a just a wee bit more in this template.

What's the best way to implement custom characteristics ("class ElectricPower extends Characteristic")

Describe Your Problem:

Hi. I want to use custom characteristics in my plugin ("homebridge-homematicip"). Since I'm quite new to TypeScript I would like to know what is the best way to implement a custom Characteristic on plugin-level. Here is my code:

import {Characteristic, Formats, Perms} from 'homebridge';

export class ElectricPower extends Characteristic {

  static readonly UUID: string = 'E863F10D-079E-48FF-8F27-9C2605A29F52';

  constructor() {
    super('Electric Power', ElectricPower.UUID);
    this.setProps({
      format: Formats.UINT16,
      perms: [Perms.NOTIFY, Perms.PAIRED_READ],
      maxValue: 100000,
      minValue: 0,
      minStep: 1,
    });
    this.value = this.getDefaultValue();
  }
}

Unfortunately, when I try to transpile this, I get the following error:

error TS1362: 'Characteristic' cannot be used as a value because it was exported using 'export type'.

This is true, since homebridge exports those classes as a type only. I could include hap-nodejs as a direct dependency, but this might lead to conflicts as you stated in several places. If I just remove the dependency after transpiling, I get the logs shown below.

So my question: What is the best way of doing this? I have seen several plugins just creating the characteristics at runtime, but can't you just do it like this above somehow? You mentioned something like this above yourself in another issue:

homebridge/homebridge#1453 (comment)

You can also look at the full source code for my plugin over here:

https://github.com/marcsowen/homebridge-homematicip

Thanks a lot for your help!

Logs:

[2/5/2021, 8:21:50 AM] ====================
[2/5/2021, 8:21:50 AM] ERROR LOADING PLUGIN homebridge-homematicip:
[2/5/2021, 8:21:50 AM] Error: Cannot find module 'hap-nodejs'
Require stack:
- /usr/lib/node_modules/homebridge-homematicip/dist/EveCharacteristics.js
- /usr/lib/node_modules/homebridge-homematicip/dist/devices/HmIPSwitchMeasuring.js
- /usr/lib/node_modules/homebridge-homematicip/dist/HmIPPlatform.js
- /usr/lib/node_modules/homebridge-homematicip/dist/index.js
- /usr/lib/node_modules/homebridge/lib/plugin.js
- /usr/lib/node_modules/homebridge/lib/pluginManager.js
- /usr/lib/node_modules/homebridge/lib/api.js
- /usr/lib/node_modules/homebridge/lib/server.js
- /usr/lib/node_modules/homebridge/lib/cli.js
- /usr/lib/node_modules/homebridge/bin/homebridge
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/usr/lib/node_modules/homebridge-homematicip/src/EveCharacteristics.ts:1:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
[2/5/2021, 8:21:50 AM] ====================

Environment:

  • Plugin Version: [email protected]
  • Homebridge Version: 1.1.7
  • Node.js Version: 15.7.0
  • NPM Version: 7.5.2
  • Operating System: macOS 11.2

No plugin was found for the platform "HomebridgeInkbirdWifiGateway" in your config.json.

Current Behavior

ERROR LOADING PLUGIN homebridge-inkbird-wifi-gateway:
[4/21/2023, 8:27:39 AM] Error: Cannot find module '/usr/local/lib/node_modules/homebridge-inkbird-wifi-gateway/src/index.js' imported from /usr/local/lib/node_modules/homebridge/lib/plugin.js
at new NodeError (node:internal/errors:399:5)
at finalizeResolution (node:internal/modules/esm/resolve:326:11)
at moduleResolve (node:internal/modules/esm/resolve:945:10)
at defaultResolve (node:internal/modules/esm/resolve:1153:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ESMLoader.import (node:internal/modules/esm/loader:525:22)
at importModuleDynamically (node:internal/modules/cjs/loader:1186:29)
at importModuleDynamicallyWrapper (node:internal/vm/module:429:21)
[4/21/2023, 8:27:39 AM] ====================

Expected Behavior

Homebridge Plugin into the Inkbird Wifi Gateway "model": "IBS-M1S",and control the bluetooth devices connected to it through HomeKit

Steps To Reproduce

In this environment...HomeKit
With this config...
Name of the sensor *
homebridge-inkbird-wifi-gateway

Model number (i.e. IBS-M1S, leave empty if not sure) *

Bluetooth MAC address for temperature sensor - WiFi gateway (xx:xx:xx:xx:xx:xx). If empty, then first sensor to be found will be used - see log for MAC found.

Update interval in seconds

Storage of history values (filesystem or googleDrive)

The log level at start - smaller number less messages (0 = Fatal, 1 = Error, 2 = Warning, 3 = Info (default), 4 = Debug)

Run '...'
See error...
Environment

npm: 9.6.5
Node.js: 18.16.0
OS Name: Monterey 12.6.5
System Model Name: Mac Mini
npm config:
; copy and paste output from npm config ls here


//registry.npmjs.org/:_authToken = (protected) 

; node bin location = /usr/local/bin/node
; node version = v18.16.0
; npm local prefix = /Users/richjagger
; npm version = 9.6.5
; cwd = /Users/richjagger
; HOME = /Users/richjagger
; Run `npm config ls -l` to show all defaults.

EACCES: permission denied

Describe Your Problem:
I have installed homebridge from the package manager (latest Ubuntu), however when I try to link the template plugin I get permission denied. I used sudo hb-service link command.

Logs:

image

Plugin Config:

There are no plugins installed, I am trying to develop my first plugin using the default template.

Environment:

  • Plugin Version: Default templage
  • Homebridge Version: 1.6.1
  • Node.js Version: v21
  • NPM Version: 10.2
  • Operating System: Ubuntu

More detail for 'First-Timers'

Describe the solution you'd like:
As someone who is trying to create their first proper plug-in and has very limited skills, I find the template README has a lot of assumed knowledge. I was wondering if more detailed steps could be provided in more of a tutorial sort of way? In my case, I have got as far as the 'build' section but am unsure if the command to be run in the terminal is supposed to be from VS Code terminal (which fails) or if this was meant to be from somewhere else. Could more detailed steps or even a tutorial on creating a simple plug-in for first-timers be created?

Describe alternatives you've considered:
Not creating a plug-in, which I may be told that if I am already stuck at this stage then maybe I should not try; but I would really like to learn.

Additional context:
I have tried to reading over many posts and a couple 'guides' online but am not able to make the jump in how a lot of this connects.

Disable current plugin?

  1. Is there any documentation available for homebridge?
  2. How could I disable the current plugin, for instance if the login function failed?

Thanks <3

Good Examples of Multi Accessory Platform Plugins To Follow

Describe Your Problem:

I am starting to work on my very first plug-in off this template and have the template all up and running; first with the dummy accessories and now have started testing the waters of changing those accessories to type Switch with a Temperature Sensor service added that is actually reading from my device.

Eventually I will need to create a Thermostat accessory, a Fan accessory and many more. I know that it is said that we are to create a separate platformAccessory.ts for each accessory but am not finding good examples of plug-ins that do multiple accessories in this manner. The Homebridge example plug-ins do not follow the method of this plug-in template and a lot of older plug-ins put all logic in one index.js file.

What I am after is an example of a plug-in that uses platform.ts for device setup and discovery and has multiple versions of the platformAccessory.ts file for accessory logic; preferably an example that Homebridge would endorse and like new devs to follow.

Logs:

N/A

Plugin Config:

N/A

Screenshots:

Environment:

  • Plugin Version: N/A
  • Homebridge Version: N/A
  • Node.js Version: N/A
  • NPM Version: N/A
  • Operating System: N/A

NEO Gateway not supported

Describe Your Problem:
The recently released Neo Gateway (with HomeKit compatibility) is not supported.

Logs:

[23/2/2023, 23:22:37] [TuyaPlatform] [TuyaOpenAPI] Request:
method = get
endpoint = https://openapi.tuyaeu.com
path = /v1.0/devices/bf854ab103d915f3dbuwdl/specifications
query = undefined
headers = {
  "t": "1677190957982",
  "client_id": "n7qxrj9epxpredqetgc4",
  "nonce": "53305997-ad92-46f6-ac2d-68234536b172",
  "Signature-Headers": "client_id",
  "sign": "39CD637D93B64A1180F80AE91D27E255035B052A4ECCABCE08119BF5D9F381BC",
  "sign_method": "HMAC-SHA256",
  "access_token": "e82790aefc9cd64fbbd8e3ca2f1c03a1",
  "lang": "en",
  "dev_lang": "javascript",
  "dev_channel": "homebridge",
  "devVersion": "1.7.0-beta.28"
}
body = null
[23/2/2023, 23:22:39] [TuyaPlatform] [TuyaOpenAPI] Response:
path = /v1.0/devices/bf854ab103d915f3dbuwdl/specifications
data = {
  "code": 2009,
  "msg": "not support this device",
  "success": false,
  "t": 1677190959340,
  "tid": "950157b2b3c811edad0316dc0085482e"
}
[23/2/2023, 23:22:39] [TuyaPlatform] [TuyaDeviceManager] Get device specification failed. devId = bf854ab103d915f3dbuwdl, code = 2009, msg = not support this device

Plugin Config:

{
"options": {
"projectType": "2",
"accessId": "xxx",
"accessKey": "xxx",
"countryCode": 34,
"username": "xxx",
"password": "xxx",
"appSchema": "tuyaSmart",
"deviceOverrides": [
{
"schema": [
{
"type": "Boolean"
}
]
}
]
},
"platform": "TuyaPlatform"


**Screenshots:**
<!-- If applicable, add screenshots to help explain your problem. -->

**Environment:**

* **Plugin Version**:v1.7.0-beta.28
* **Homebridge Version**: v1.6.0
* **Node.js Version**: [v18.13.0]
* **NPM Version**: <!-- npm -v -->
* **Operating System**: Raspbian

Warning to log if nodes upgraded to version 20...

Plugins built from this template generate a warning error in Homebridge log after nodejs is upgraded to version 20, which is now the default...

The plugin "<name-your-pligin>" requires Node.js version of ^18.17.0 which does not satisfy the current Node.js version of v20.9.0. You may need to upgrade your installation of Node.js - see https://homebridge.io/w/JTKEF

The package.json file in this template should be updated to permit higher nodejs versions by default.

Remove existing accessory from cache

Great template. But there is no function that removes existing accessories from the cache when they are no longer in the setup. Currently, there are only two options: get from cache or add new ones.

The README section "Update package.json" should note the "name" should not be mixed case.

Is your feature request related to a problem? Please describe:
When I tried to "npm unpublish homebridge-bigAssFans-i6 --force" it failed silently. I contacted support the following day because the package was not unpublished. Per [email protected]: "Please keep in mind that package names are case sensitive and mixed case names are not supported. That might be why your attempt to unpublish homebridge-bigAssFans-i6 failed."

Describe the solution you'd like:
In the README where it says the name should "contain no spaces or special characters apart from a dashes" perhaps it should say "contain no spaces or special characters apart from dashes, nor be mixed case" or some such. By the way "a dashes" looks like a typo.

Describe alternatives you've considered:
none

Additional context:
thank you

device/!device example is confusing

Describe Your Problem:

I'm updating an old plugin to be structured like this plugin template. The platform example has a confusing part where device is checked. However, the !device block is dead code - the device won't ever be null in this example. In what case would we want to unregister an accessory, or know that a device that used to exist no longer exists?

NodeJS version 18.x in GitHub actions

Is your feature request related to a problem? Please describe:
For verification of homebridge plugin one must support the node LTS versions 14.x, 16.x and 18.x (see requirements). The GitHub actions template contains versions 12.x, 13.x, 14.x, 15.x, 16.x but not 18.x.

Describe the solution you'd like:
Version 18.x should be added to the actions as well.
Maybe 12.x, 13.x and 15.x could be removed as they are not mandatory?

Describe alternatives you've considered:
None

Creating 2 identical Services in a single accessory

I have a WindowCovering (shades) plugin and I am trying to add 2 switches (Services) to act as simple open/close buttons within the WindowCovering accessory code. This is not ideal, but I can't find any other Service that meets the need. The plugin is based on this template. The addition of the 2 switches is done via code copied from the comment on line 39 of platformAccessory.ts.

Here's the code:

this.swServiceOpen = this.accessory.getService(this.platform.Service.Switch)
                || this.accessory.addService(this.platform.Service.Switch, this.displayName + ' Open', 'Open');
this.swServiceClose = this.accessory.getService(this.platform.Service.Switch)
                || this.accessory.addService(this.platform.Service.Switch), this.displayName + ' Close', 'Close';
this.swServiceOpen.displayName = this.displayName + ' Open';
this.swServiceOpen.subtype = 'Open';
this.swServiceClose.displayName = this.displayName + ' Close';
this.swServiceClose.subtype = 'Close';

I added the last 4 lines because I saw that "solution" in an Issue comment. It did not help. When I look at the Accessories on the Homebridge UI, I see only the Open switches, not the Close ones. The single switches that appear are at first "within" the WindowCovering icon, but can be separated with a setting.

It also appears that when a get or set is called on the switch from Homekit, the listener for both switches is being called. When the second listener calls the callback, it crashes with the "already called that callback" error. So, I have simply removed temporarily one of the two callbacks so I can keep debugging. This seems to keep me afloat for now.

I posted this first as an issue under Homebridge itself, but was just pointed at code that looks just like mine. This has not helped so far.

How do I properly set the subtype? Clearly these two Switch service creations are not properly differentiated in the code.

Add further documentation to npm link

From the README.md it seems one should run npm link while he is in the project folder. (as its directly after building the project and its never specified to change directory)

But from the experience I just had, you need to run it from the homebridge path (/var/lib/homebridge) like that npm link /path/to/project

.npmignore should not exclude dist

Describe The Bug:
When you want to publish your plugin (npm publish) it cannot be installed by other npm users because the dist-directory is excluded from the tar-ball.

To Reproduce:
npm publish on dev machine
npm install on user machine

Expected behavior:
plugin is correctly installed and can be loaded by homebridge

Logs:

[11/14/2021, 11:58:39 PM] ERROR LOADING PLUGIN homebridge-xxx:
[11/14/2021, 11:58:39 PM] Error: Cannot find module '/usr/lib/node_modules/homebridge-xxx/dist/index.js'
Require stack:
- /usr/lib/node_modules/homebridge/lib/plugin.js
- /usr/lib/node_modules/homebridge/lib/pluginManager.js
- /usr/lib/node_modules/homebridge/lib/server.js
- /usr/lib/node_modules/homebridge/lib/cli.js
- /usr/lib/node_modules/homebridge/bin/homebridge
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Plugin.load (/usr/lib/node_modules/homebridge/src/plugin.ts:192:73)
    at PluginManager.initializeInstalledPlugins (/usr/lib/node_modules/homebridge/src/pluginManager.ts:131:22)
    at Server.start (/usr/lib/node_modules/homebridge/src/server.ts:156:5)

Plugin Config:
na

Screenshots:
na

Environment:

  • Plugin Version: na
  • Homebridge Version: na
  • Node.js Version: v17.0.1
  • NPM Version: 8.1.0
  • Operating System: macOS

Is there a method I can call to tell Homebridge that my device is offline / not responding?

Sorry, this issue should have been raised in the homebridge repo not the template.

Describe Your Problem:

I am creating a plugin to control a swimming pool heat pump. To do this I am using the Thermostat service. Sometimes the heat pump will disconnect from the WiFi network and when that happens I would like my plugin to be able to tell Homebridge that the accessory is offline.

How I imagine this working is that when Homebridge or the Home app attempts to fetch new data for the accessory from the plugin, an initial condition checks the Heat Pump API to see if the device is online or offline. What I would like to know is if there is anything in the Homebridge API that I can call to report back that the device is offline? I'd preferably like to do this once for the whole accessory instead of having to implement it in every single Characteristic getter and setter.

Sorry if this is a blindingly obvious question. I'm still trying to get comfortable with your API!

Logs:

NA

Plugin Config:

{
  "pluginAlias": "NorsupHomebridgePlugin",
  "pluginType": "platform",
  "singular": true,
  "schema": {
    "type": "object",
    "properties": {
      "username": {
        "title": "Aqua Temp Username",
        "type": "string",
        "required": true,
        "default": ""
      },
      "passwordHash": {
        "title": "MD5 Hashed Password",
        "type": "string",
        "required": true,
        "default": ""
      }
    }
  }
}

Screenshots:

Environment:

  • Plugin Version:
  • Homebridge Version: 1.1.6
  • Node.js Version: 14.7
  • NPM Version: 6.14.7
  • Operating System: macOS

HOOBS compatibility

Describe The Bug:
Plugins generated from this are not working on HOOBS,
The Error is:
The requested platform "XXXXXX" was not registered by any plugin. Your config.json is requesting the platform

To Reproduce:
Use Hoobs, install a plugin such as:
homebridge-z2m
homebridge-magichome-led

Expected behavior:
plugin loads

Logs:

2.9.2020, 17:25:03 The requested platform "MagicHomeLED" was not registered by any plugin.
2.9.2020, 17:25:03 Your config.json is requesting the platform "MagicHomeLED" which has not been published by any installed plugins.

Plugin Config:

{
      "platform" : "MagicHomeLED"
    }

Screenshots:

Environment:

  • Plugin Version:
  • Homebridge Version: HOOBS 3.2.6
  • Node.js Version: v12.18.3
  • NPM Version: 6.14.6
  • Operating System: Raspbian

How to get/retrieve the name of a device from homekit?

Hello together,

i would like to get the name of a device from homkit, because i want to use the current name in homekit for processing an action.
This would be very good for the messenger plungin (https://github.com/potrudeau/homebridge-messenger), because this plugin send a message with the subject = device-name from the configfile.
So if you want change the message subject you have to change the name in the config and restart homebridge.
Changing in homekit app would be more flexible.
So: Is it possible to get the changed device name from homekit in a homebridge plugin?

kind regards,
Peter

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.