Coder Social home page Coder Social logo

djelibeybi / homebridge-button-platform Goto Github PK

View Code? Open in Web Editor NEW
56.0 2.0 3.0 488 KB

A Homebridge platform plugin to create virtual buttons that respond to HTTP requests from things like Flic buttons or an Elgato Stream Deck.

Home Page: https://omg.dje.li/homebridge-button-platform/

License: Apache License 2.0

JavaScript 100.00%
homebridge virtual-buttons flic http rest-api flic-hub-lr homekit-support elgato-stream-deck homebridge-plugin flic-buttons

homebridge-button-platform's Introduction

Button Platform for Homebridge

ARCHIVED This plugin is no longer updated.

This Homebridge platform plugin creates virtual buttons that can be triggered using HTTP requests. It was originally created to provide HomeKit support for Flic smart buttons before the Flic Hub LR got native HomeKit support but can be leveraged by anything that can send HTTP requests.

Flic Hub LR now supports HomeKit: Flic released a firmware update for the Flic Hub LR on 2 December 2020 which included native HomeKit support. Visit https://flic.io/homekit for instructions on how to configure native HomeKit access.

This plugin requires a working home hub.

Before you install, ensure you have setup a HomePod, HomePod mini, Apple TV or iPad as a home hub for HomeKit. A home hub is required to run automations triggered by the button events generated by this plugin.

Install

The simplest method to install and configure this plugin is via homebridge-config-ui-x.

To install manually, run the following command in your Homebridge directory. Depending on how you installed Homebridge, you may need to add the -g and/or the --unsafe-perms parameters:

npm install [-g|--unsafe-perms] homebridge-button-platform

The -g option will install the plugin globally and the --unsafe-perms option is needed for some platforms to install successfully.

Configuration

The plugin can be configured via the homebridge-config-ui-x admin interface.

To configure the plugin manually, add the following configuration to the platforms block of your Homebridge config.json file:

"platforms": [
    {
        "platform": "button-platform",
        "port": 3001,
        "buttons": [
            "My Button",
            "Your Button",
            "Their Button"
        ]
    }
  ]

You can add as many buttons to the array as you need. Each button will get its own URI on which the server will listen for events. You can determine the URI for each button by checking the Homebridge logs for The Event URI for <button name> is: /button-button-name strings.

Note: renaming a button in config.json is the same as deleting the old button and adding a new one, i.e. any configuration will be lost.

Sending events

To trigger a button event, send an HTTP GET request with a specific query string value or an HTTP POST request to your Homebridge hostname or IP address and the port specified in the configuration of the platform, plus the URI for the button.

Using a GET request

The simplest method of triggering an event is to use a simple GET request with the query string parameter of event set to one of the valid event types:

  • click or single-press
  • double-click or double-press
  • hold or long-press

For example, to send a single click event to a button using curl:

$ curl http://<homebridge>:<port>/uri?event=click
Success

You could also use this URL with a normal web browser.

Example Flic button configuration

Here’s a screenshot of what an Internet Request action should look like in the Flic app if your Homebridge server is homebridge.local and the plugin was listening on port 3001:

flic-config

The values are as follows:

Field Value
Hub Action Internet Request
URL http://homebridge.local:3001/button-name?event=click
Type GET

Battery level

The plugin from v1.5 onwards automatically creates a battery service when it detects it's being triggered by a Flic button and will update the battery level with the current value from the Flic whenever the button is pushed.

Example Stream Deck configuration

You can use the "Website" Stream Deck action to trigger an event. In the Stream Deck configuration, drag the "Website" action to a key and configure the URL to be http://homebridge.local:3001/button-name?event=click which uses the same parameters as the GET request above:

streamdeck-key

Top tip: If you enable the GET request in background option, a browser will not open when you hit the key.

Using a POST request

If you use an HTTP POST request you must set the Content-Type header to either application/json or application/x-www-form-urlencoded. The body of the request needs a field named event with a value of one of the event types defined above.

For example, to send a double press event to a button using curl with a JSON payload:

$ curl -X POST \
  -H 'Content-Type: application/json' \
  -d '{"event": "double-click"}' \
  http://<homebridge>:<port>/<uri>

You can also POST with an application/x-www-form-urlencoded payload:

$ curl -X POST \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'event=double-click' \
  http://<homebridge>:<port>/<uri>

This is useful when used in with a larger form-based application.

Troubleshooting

Check the Homebridge logs for any warnings as the plugin will log any attempts to trigger an invalid event or any invalid URIs.

homebridge-button-platform's People

Contributors

deepsource-autofix[bot] avatar dependabot-preview[bot] avatar dependabot[bot] avatar djelibeybi 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

Watchers

 avatar  avatar

homebridge-button-platform's Issues

via Internet

Hi there,

I want to trigger from outside. I filled out the link with my static fixed internet ip and released port 3001 to the homebrige. but the browser reports "no connection to the server." it works with internal homebridge ip. What did I miss?


Hallo,

ich möchte von ausserhalb auslösen. Ich habe den Link mit meiner statischen festen internet-ip ausgefüllt und den Port 3001 auf die homebrige freigegeben. aber der browser meldet "keine verbindung zum server." mit internen homebridge-ip funktioniert es. Was habe ich übersehen?

LG

Urs

Can't find URI for button

Hi.
I have tried to setup the button-platform, but can't really get it to work.
I have searched through the log and can't find any URI. I have set up a button called button-name. When I try to do a post to http://192.168.0.112:3001/button-name?event=click it returns with a 404.

Here's what it says in the log:
Wed, 28 Oct 2020 19:00:13 GMT finalhandler default 404
Wed, 28 Oct 2020 19:00:13 GMT body-parser:urlencoded skip empty body
Wed, 28 Oct 2020 19:00:13 GMT express:router urlencodedParser : /button-name?event=click
Wed, 28 Oct 2020 19:00:13 GMT body-parser:json skip empty body
Wed, 28 Oct 2020 19:00:13 GMT express:router jsonParser : /button-name?event=click
Wed, 28 Oct 2020 19:00:13 GMT express:router expressInit : /button-name?event=click
Wed, 28 Oct 2020 19:00:13 GMT express:router query : /button-name?event=click
Wed, 28 Oct 2020 19:00:13 GMT express:router dispatching GET /button-name?event=click

My config:
{
"port" : "3001",
"buttons" : [
"button name"
],
"name" : "Button Platform",
"platform" : "button-platform"
}

When I load homebridge this is what it says:
[10/28/2020, 7:02:38 PM] [Button Platform] Listening on port 3001 for inbound button push event notifications
[10/28/2020, 7:02:37 PM] [Button Platform] restored 2 accessories from cache
[10/28/2020, 7:02:37 PM] [Button Platform] homebridge-button-platform v1.1.5, node 11.6.0, homebridge v1.2.3, homebridge-lib v4.7.16
[10/28/2020, 7:02:37 PM] [Button Platform] Initializing button-platform platform...

I hope you can help me to get it work. Thanks in advance!

No reaction

Hi there
It's a great and simple working plugin, thank you for programming. Although not being very skilled, at least I once managed to get it running completely. But out of a sudden, it doesn't work anymore. When I trigger the command (e.g. via Browser) the success is shown by the Homebridge protocol and even by the bumping button in the Home.App. The underlying scene or event actually works perfectly otherwise. Any idea what the problem might be?

npm registry type error for listener argument

Issue see below log - plugin works

[Homebridge] [3/13/2020, 8:48:36 PM] [Button Platform] warning: npm registry: TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type Function. Received type object
    at checkListener (events.js:77:11)
    at ClientRequest.once (events.js:326:3)
    at new ClientRequest (_http_client.js:177:10)
    at Object.request (https.js:309:10)
    at Object.request (/home/hoobs/.hoobs/node_modules/http-proxy-agent/node_modules/agent-base/patch-core.js:25:22)
    at HttpClient.request (/home/hoobs/.hoobs/node_modules/homebridge-lib/lib/HttpClient.js:226:32)
    at HttpClient.get (/home/hoobs/.hoobs/node_modules/homebridge-lib/lib/HttpClient.js:136:17)
    at ButtonPlatform._checkLatest (/home/hoobs/.hoobs/node_modules/homebridge-lib/lib/Platform.js:380:42)
    at ButtonPlatform._heartbeat (/home/hoobs/.hoobs/node_modules/homebridge-lib/lib/Platform.js:290:12)
    at ButtonPlatform._beat (/home/hoobs/.hoobs/node_modules/homebridge-lib/lib/Platform.js:284:42)

(Edited for formatting)

Phantom button press when bridge reboots

I installed this plugin and configured a few buttons.

I am using the buttons to trigger music playing on HomePods.

I am triggering from other software. This part works great.

But for some reason when I reboot the "child bridge" in homebridge, then it is like the buttons get triggered or re-triggered and music starts playing on my homepods even though I have not done anything since the bridge was rebooted to push the buttons.

Nothing too interesting in the logs.

[10/23/2022, 4:13:07 PM] [Button Platform] Child bridge process ended
[10/23/2022, 4:13:07 PM] [Button Platform] Process Ended. Code: 143, Signal: null
[10/23/2022, 4:13:14 PM] [Button Platform] Restarting Process...
[10/23/2022, 4:13:14 PM] [Button Platform] Launched child bridge with PID 91334
[10/23/2022, 4:13:14 PM] Registering platform 'homebridge-button-platform.button-platform'
[10/23/2022, 4:13:14 PM] [Button Platform] Loaded homebridge-button-platform v1.5.1 child bridge successfully
[10/23/2022, 4:13:14 PM] Loaded 4 cached accessories from cachedAccessories.0E716D0970CA.
[10/23/2022, 4:13:14 PM] [Button Platform] homebridge-button-platform v1.5.1, node v16.16.0, homebridge v1.5.0, homebridge-lib v5.6.8
[10/23/2022, 4:13:14 PM] [Button Platform] warning: recommended version: node v16.17.1 LTS
[10/23/2022, 4:13:14 PM] [Button Platform] Listening on port 3001 for inbound button push event notifications
[10/23/2022, 4:13:14 PM] Homebridge v1.5.0 (HAP v0.10.4) (Button Platform) is running on port 57871.
[10/23/2022, 4:13:14 PM] [Button Platform] hardware: Mac mini (M1, 2020)
[10/23/2022, 4:13:14 PM] [Button Platform] os: macOS Monterey 12.4.0 (21F79)
[10/23/2022, 4:13:14 PM] [Button Platform] restored 4 accessories from cache
[10/23/2022, 4:13:15 PM] [Button Platform] The Event URI for Play1 is: /button-play1
[10/23/2022, 4:13:15 PM] [Button Platform] The Event URI for Play2 is: /button-play2
[10/23/2022, 4:13:15 PM] [Button Platform] The Event URI for Play3 is: /button-play3
[10/23/2022, 4:13:15 PM] [Button Platform] The Event URI for Play4 is: /button-play4

Button not found.

Hello,

I just installed the plugin in Homekit, but I'm always getting:
"Button not found" error in Safari.

The output:

[5/19/2020, 09:29:03] [Button Platform] Initializing button-platform platform...
[5/19/2020, 09:29:03] [Button Platform] homebridge-button-platform v1.0.5, node 12.16.2, homebridge v1.1.0, homebridge-lib v4.7.5
[5/19/2020, 09:29:03] [Button Platform] warning: 12.16.2: not using recommended node v12.16.3 LTS
[5/19/2020, 09:29:03] [Button Platform] The Event URI for Test is: /button-test

When I try to reach http://10.0.0.130:3001/button-test, I get this error:
[5/19/2020, 09:29:57] [Button Platform] warning: Received event for unconfigured Button path: /button-test

No URi in Logs

I've just configured the plugin on my Homebridge running on a raspberry pi.
Once generated the button (just one) on the plugin coniguration, it creates two buttons on the accessories page.
The LOGS don't show anything about those accessories so I can't retrieve the URi

Button not triggering the same event twice

Hello,
At first thanks for the great plug in!
I have a weird problem...
when I try to trigger the button with a get request it for example with the “click” event it just works once and only when the prior event was not the same event type.
When I look at the log it says: “received get request to trigger a click event” but nothing happens... if I then for example chance the event to a “double-click” it again works but just for one time.
I also have an additional line in the log which says: “set Programmable switch event from 0 to 1”

is there anything I can do here ?

thanks for your support!

Same problem as #140

I created two virtual test buttons. They show up in the homebridge but they don't show up in the home App. I have 3 hubs (atv 4k + 2 HomePod mini). Did I miss something? Sadly #140 was closed without explaining the solution.

Best regards

(JS-0128) Should not have unused variables

Description

Found variables that are declared but not used anywhere. <!--more--> Variables that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such variables take up space in the code and can lead to confusion by readers. Also, having unused variables affects …

Occurrences

There is 1 occurrence of this issue in the repository.

See all occurrences on DeepSource → deepsource.io/gh/Djelibeybi/homebridge-button-platform/issue/JS-0128/occurrences/

zsh: no matches found

Using terminal on my mac:

Input: curl http://<HB-IP>:<port>/button-door-on?event=click

Output zsh: no matches found: http://<HB-IP>:<port>/button-door-on?event=click

I have tested this on my web browser and the url works fine. What's going on here?

Renamed buttons persisting

A big thank you for creating this plugin, it takes a fairly useless flic system and makes it completely usable!

I am running into an issue however. I renamed a button using the ConfigX UI and I am now seeing two buttons show-up in my homekit UI and in the Config UI. When I look at the config.json I don't see the values for the previously named button. I'm guessing this is being cached somewhere in another file?

Is there another place I should be looking for to delete the older virtual buttons?

Thanks!

Platform is issuing warning: heartbeat drift errors

Button platform is logging the following type of errors:

[15/12/2021, 19:25:27] [Button Platform] warning: heartbeat 0, drift 485

[15/12/2021, 19:25:37] [Button Platform] warning: heartbeat 9, drift 558

Issue with Flic Button Setup

Hey thanks in advance for your help! I'm new to homebridge so this may be a rookie mistake...

I previously had my flic buttons set up and working via Homebridge but it suddenly stopped working. I just set up static IP addresses but am still getting some errors.

In this example I have a flic button called "nurseryflic) and I've got the Flic app set up with settings:
Type: Post
URL: http://192.168.68.105:3001/button-nurseryflic
Content Type: application/x-www-form-urlencoded

For a single click it works great but for a double and hold action I get the error "Internet Request: Request failed: internal server error 500". Any chance anyone is familiar with that error? Thanks!

Here is the log created in Homebridge.

[5/20/2021, 11:04:43 AM] [Flic Buttons] Received POST request on /button-nurseryflic to trigger a [double-click] event for Nurseryflic
TypeError: accessory.switchService.triggerEvent.triggerEvent is not a function
    at /usr/local/lib/node_modules/homebridge-button-platform/lib/ButtonPlatform.js:155:50
    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/homebridge-button-platform/node_modules/express/lib/router/layer.js:95:5)
    at next (/usr/local/lib/node_modules/homebridge-button-platform/node_modules/express/lib/router/route.js:137:13)
    at middleware (/usr/local/lib/node_modules/homebridge-button-platform/node_modules/express-validator/src/middlewares/one-of.js:36:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Eve App Shows Low Battery Warnings for Non-Flic Buttons

It appears that the default state for all buttons is 0% battery. While this doesn't cause any warnings in Apple's Home app, the Eve app takes it upon itself to display warnings that the battery is low.

It would be nice to have the option to disable the battery service for buttons that will never be used with Flic. (Looking through the source I see I could pass a 'button-battery-level' header as part of the HTTP request, but I'd like to just remove the battery information completely.)

Eve Low Battery

"warning: Received event for unconfigured Button path"

Thank you for making this!

Are there limits on button names (characters or string limits)? I'm getting the following error:

[Button Platform] warning: Received event for unconfigured Button path: /vacuum_kitchen

and same thing, if I append "button-"

[Button Platform] warning: Received event for unconfigured Button path: /button-vacuum_kitchen

I must be missing something!

Thanks again.

Toggle Switch

Is there a way to set up a toggle switch. So rather than one click for on, double click for off. One click could know the state of a device then toggle the state?

Battery status present even without Flick button

Hi there,

I don't own a Flick button but the plugin still adds a battery accessory. I guess it thinks I'm using one. This is my config, what else would you need to trouble-shoot this?

{ "name": "Button Platform", "port": 3001, "buttons": [ "Office Button" ], "platform": "button-platform" }

Thank you for the work! I find this plugin very useful. I try to program a few things in Python and appreciate how much goes into even simple apps. So, thank you. :)

Button resetting without renaming!

Hey,
everytime I restart my Homebridge server, my button got a reset without renaming!
I Had set an Scene to a single press but this is lost every time I restart the Homebridge server!

Create battery service for Flic buttons

The Flic 2 buttons send their current battery level, serial number and name in the HTTP headers of an Internet request. That information should inform/update a battery service for each button.

Using the "Convert To Shortcut" feature

Using the "Convert To Shortcut" feature and writing a short shortcut that first checks for the Power State and then decides whether to turn on or off a switch worked for me initially.
However, for a few days now it doesn't work anymore.
Directly switching a switch on or off still works, though.
But I use an Elgato Streamdeck to toggle-switch some lights and really don't want to use two StreamDeck buttons for one light.
What changed? Con anyone confirm that it's not working anymore?

Originally posted by @metawops in #2 (comment)

Trying to use this plugin to control a smart switch from Stream Deck. But the virtual devices don't show up in the Home app

Basically title.

I've installed the plugin and setup the virtual button. I can see it in the accessories page on the Homebridge UI. But the virtual button doesn't show up in HomeKit. Therefor I can't link it to anything. Unless I'm missing something?

Currently I have the button on my streamdeck setup to control the virtual button and that works. But like I said I can't seem to link the virtual button to anything since it doesn't show up in HomeKit/the Home app

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.