From a2a4ef2a14765b11853cd1eefd6cfea95f160408 Mon Sep 17 00:00:00 2001 From: naps62-yolo Date: Tue, 5 May 2026 17:49:55 +0000 Subject: [PATCH] Initial commit: WebRTC Doorbell Card v0.4.0 --- .gitignore | 4 + LICENSE | 21 ++++ README.md | 77 +++++++++++++ hacs.json | 5 + webrtc-doorbell-card.js | 240 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 347 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 hacs.json create mode 100644 webrtc-doorbell-card.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9451024 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +dist/ +.DS_Store +*.log diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dccb172 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Miguel Palhas + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..869c171 --- /dev/null +++ b/README.md @@ -0,0 +1,77 @@ +# WebRTC Doorbell Card + +A Home Assistant Lovelace card that wraps [AlexxIT/WebRTC](https://github.com/AlexxIT/WebRTC)'s `webrtc-camera` and adds a proper doorbell-style call UX: + +- **Answer / Hangup** buttons that toggle *both* directions of audio at once (incoming via `video.muted`, outgoing via the mic track's `enabled` flag) — unlike the bare WebRTC card whose mute button only affects the incoming stream. +- **Configurable unlock button** that fires any HA action (`call-service` / `perform-action`). +- **Haptic + visual feedback** on tap — vibration where supported, scale + flash + checkmark on the unlock button. +- **Mic captured up-front** but kept disabled until you press Answer, so there's no permission prompt mid-call. + +## Requirements + +- [AlexxIT/WebRTC](https://github.com/AlexxIT/WebRTC) integration installed (this card delegates the actual WebRTC streaming to its `webrtc-camera` card). +- A camera entity that supports two-way audio via go2rtc (Frigate cameras work, as do Dahua VTOs and many others — see the AlexxIT docs). + +## Installation + +### HACS (custom repository) + +1. HACS → Frontend → ⋮ → Custom repositories +2. Add `https://git.naps.pt/naps62/ha-webrtc-doorbell-card`, category **Lovelace** +3. Install **WebRTC Doorbell Card**, then hard-refresh your browser. + +### Manual + +Copy `webrtc-doorbell-card.js` into `/config/www/` and register it as a Lovelace resource of type `module` pointing at `/local/webrtc-doorbell-card.js`. + +## Usage + +```yaml +type: custom:webrtc-doorbell-card +entity: camera.doorbell # any camera that webrtc-camera can stream +unlock_action: # optional — omit to hide the unlock button + action: perform-action + perform_action: dahua.vto_open_door + data: + door_id: 1 + target: + entity_id: camera.doorbell_main +unlock_icon: mdi:key # optional, defaults to mdi:key +mode: webrtc # optional, passed through to webrtc-camera +``` + +A `panel: true` view works best: + +```yaml +title: Doorbell +path: doorbell +icon: mdi:doorbell-video +panel: true +cards: + - type: custom:webrtc-doorbell-card + entity: camera.doorbell + unlock_action: + action: perform-action + perform_action: dahua.vto_open_door + data: { door_id: 1 } + target: { entity_id: camera.doorbell_main } +``` + +## How it works + +The card creates an inner `webrtc-camera` configured with `media: video,audio,microphone` and `ui: false`, then overlays its own three buttons. + +- **Mic capture** — a one-time monkey-patch of `navigator.mediaDevices.getUserMedia` stores a reference to the mic stream and starts every audio track disabled. Pressing Answer flips the tracks' `enabled` flag. +- **Incoming audio** — toggled via `video.muted` on the inner card's `