WebRTC Camera

repository·master·Indexed 24 days ago

https://github.com/alexxit/webrtc

A Home Assistant integration providing low-latency WebRTC streaming for IP cameras. It utilizes go2rtc as a streaming server to support features such as two-way audio, PTZ, and snapshots. The integration includes a custom Lovelace card (`custom:webrtc-camera`) for displaying streams via RTSP URLs, go2rtc stream names, or Home Assistant camera entities.

Tokens
7.6K
Snippets
6
Records
9
Agent score
30%

What's inside WebRTC Camera

  1. How go2rtc works as a streaming server

    master

    Starting with version 3, the WebRTC component uses go2rtc as its streaming server.

    Installation Options for go2rtc:

    • Basic users: The component automatically downloads and runs the latest version of go2rtc.
    • Advanced users: Install the go2rtc or Frigate 12+ add-on.
    • Hakers: Install go2rtc as a binary or Docker container on any server in your LAN.

    Configuration: You can customize go2rtc settings by adding a go2rtc.yaml file to your Home Assistant configuration folder.

    Security Warning: go2rtc runs a web interface on port 1984 without a password. Anyone on your LAN can access active camera streams via this interface. You can disable this in the go2rtc configuration.

  2. Configure the WebRTC Integration

    master

    To set up the integration in the Home Assistant UI:

    1. Go to Settings > Devices & Services.
    2. Click Add Integration.
    3. Search for WebRTC.

    Note: If the integration does not appear in the list, clear your browser cache. This component does not create devices or entities; it only provides two services and the Lovelace custom card.

  3. Stream Audio to Cameras via Media Players

    master

    You can play audio files (TTS, music, etc.) on cameras that support two-way audio by creating virtual media_player entities in your configuration.yaml.

    1. Ensure the camera supports the required audio codec.
    2. Configure the stream in go2rtc.yaml.
    3. Define the media player in Home Assistant:
    media_player:
      - platform: webrtc
        name: Dahua Camera
        stream: dahua
        audio: pcmu/48000
      - platform: webrtc
        name: Tapo Camera
        stream: tapo
        audio: pcma
  4. Install WebRTC Camera via HACS or Manual

    master

    You can install the WebRTC Camera component using one of two methods:

    Method 1: HACS (Recommended)

    1. Open HACS in Home Assistant.
    2. Navigate to Integrations.
    3. Click the Plus (+) icon.
    4. Search for and select WebRTC.
    5. Click Install.

    Method 2: Manual Installation

    1. Download the latest release from the GitHub releases page.
    2. Copy the webrtc folder into your /config/custom_components directory.

    Note for YAML UI users: If you manage your Home Assistant UI via YAML, you must manually register the custom card by adding the following to your UI resources:

    url: /webrtc/webrtc-camera.js
    type: module

    Then, refresh your browser.

  5. Enable Two-Way Audio in WebRTC

    master

    To use two-way audio, you must meet these requirements:

    1. Use a source supported by go2rtc for two-way audio.
    2. Use WebRTC mode.
    3. Your Home Assistant instance must be accessible via HTTPS (required by browsers for microphone access).
    4. Add microphone to the media parameter.

    You can define multiple streams, such as one for video/audio and one specifically including the microphone:

    type: 'custom:webrtc-camera'
    streams:
      - url: go2rtc_stream
      - url: go2rtc_stream
        mode: webrtc
        media: video,audio,microphone
  6. Use the WebRTC Custom Card

    master

    The custom:webrtc-camera card is used to display camera streams in Lovelace. You must provide at least one of url, entity, or streams.

    Basic Usage Examples

    Using a direct RTSP URL:

    type: 'custom:webrtc-camera'
    url: 'rtsp://rtsp:12345678@192.168.1.123:554/av_stream/ch0'

    Using a go2rtc stream name:

    type: 'custom:webrtc-camera'
    url: 'camera1'  # name from go2rtc.yaml

    Using a Home Assistant camera entity:

    type: 'custom:webrtc-camera'
    entity: camera.generic_stream

    Using multiple streams (e.g., HD and SD):

    type: 'custom:webrtc-camera'
    streams:
      - url: go2rtc_stream_hd
        name: HD
        mode: webrtc
        media: video
      - url: go2rtc_stream_sd
        name: SD
        mode: mse
        media: audio
  7. Use JavaScript Templates in WebRTC Card

    master

    As of v3.6.0, the shortcuts, style, and ptz options in the WebRTC card support JavaScript templates. You can use the states object for Home Assistant states or this.streamName/this.streamID for PTZ-related templates.

    Example: Dynamic Icon in Shortcuts

    shortcuts:
      - name: Barn Light
        icon: ${ states['light.yeelight_lamp'].state === 'on' ? 'mdi:outdoor-lamp':'mdi:lamp' }
        service: light.toggle
        service_data:
          entity_id: light.yeelight_lamp

    Example: Dynamic Message in PTZ

    ptz:
      service: notify.persistent_notification
      data_left:
        message: Left for ${ this.streamName } clicked
      data_right:
        message: Rigth for ${ this.streamID } clicked
  8. Configure WebRTC Custom Card Options

    master

    The custom:webrtc-camera card supports several advanced configuration options:

    OptionDescription
    urlProtocol supported by go2rtc (rtsp, rtmp, http, onvif, etc.), a stream name from go2rtc, or a Jinja2 template.
    entityAlmost any camera entity from Home Assistant.
    posterAn http link, a camera entity, a go2rtc stream name, or a Jinja2 template.
    modeStreaming technology (webrtc, webrtc/tcp, mse, hls, mjpeg). Default is all.
    mediaSelect tracks (video, audio). Default is both.
    serverCustom go2rtc server address (default is empty).
    uiEnables custom video controls (default false).
    digital_ptzConfigures digital zoom/pan. Set to false to disable all.
    titleOptional card title.
    mutedInitial mute state (default false).
    intersectionAuto-stop stream threshold (e.g., 0.75 for 75% visibility).
    backgroundRun stream when not displayed (default false).
    shortcutsCustom action buttons.
    styleCSS for styling the card elements.
  9. Reference RTSP URLs for known cameras

    master

    This table provides known working RTSP stream URLs for various camera brands and models to help configure WebRTC streams. Use these patterns to construct your stream URLs in the configuration.

    | Brand        | Models                                                                               | Comment                                                                                                                                                                                                                              |
    |--------------|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
    | ActiveCam    | AC-D2121IR3                                                                          |                                                                                                                                                                                                                                      |
    | ActiveCam    | AC-D7121IR1W                                                                         | support sound                                                                                                                                                                                                                        |
    | Android      | [IP Webcam Pro][1]                                                                   | support sound, `rtsp://192.168.1.123:8080/h264_ulaw.sdp`                                                                                                                                                                             |
    | C-tronics    | CTIPC-690C                                                                           | support sound, main : `rtsp://username:password@192.168.1.xx:554/11` or `onvif://username:password@192.168.1.xx:8080?subtype=MainStreamProfileToken`                                                                                              |
    | Dahua        | DH-IPC-HDPW1431FP-AS-0280B, VTO2211G-P                                               | support sound                                                                                                                                                                                                                        |
    | Dahua        | VTO2202F-P-S2                                                                        | [read more](https://github.com/blakeblackshear/frigate/discussions/2572)                                                                                                                                                             |
    | EZVIZ        | C3S                                                                                  | `rtsp://admin:pass@192.168.1.123:554/h264/ch01/main/av_stream` and `/h264/ch01/sub/av_stream`                                                                                                                                         |
    | EZVIZ        | C3W, C3WN, C6CN, C6T                                                                | `rtsp://admin:pass@192.168.1.123:554/h264_stream`                                                                                                                                                                                    |
    | EZVIZ        | C8C                                                                                  | `rtsp://admin:pass@192.168.1.123:554/channel80`                                                                                                                                                                                       |
    | Foscam       | C1                                                                                   | `rtsp://user:pass@192.168.1.123:554/videoMain`                                                                                                                                                                                        |
    | Foscam       | C2M, R2M                                                                             | `rtsp://user:pass@192.168.1.123:88/videoMain`                                                                                                                                                                                        |
    | GW Security  | GW5088IP                                                                             | `rtsp://192.168.1.123:554/mpeg4cif?username=admin&password=123456`                                                                                                                                                                   |
    | GW Security  | GW5078IP                                                                             | `rtsp://192.168.1.123:554/stream0?username=admin&password=123456`                                                                                                                                                                    |
    | GW Security  | GW5071IP                                                                             | Not working yet, something similar to `rtsp://admin:123456@192.168.0.207:554/live/main` or `rtsp://192.168.0.207:554/live/main?username=admin&password=123456`                                                                                              |
    | Hikvision    | DS-2CD2T47G1-L, DS-2CD1321-I, DS-2CD2143G0-IS                                        | `rtsp://user:pass@192.168.1.123:554/ISAPI/Streaming/Channels/102`                                                                                                                                                                    |
    | Hikvision    | IPC-HDW3849H-AS-PV, IPC-EW5531-AS                     | wired to nvr DHI-NVR2108HS-8P-I using [custom component](https://github.com/rroller/dahua)                                                                                                                                                            |
    | Imou         | IPC-F42-B2E3 (Bullet 2C 4MP)                          | `rtsp://admin:password@192.168.1.123:554/cam/realmonitor?channel=1&subtype=0`                                                                                                                                                            |
    | QNAP         | QUSBCam2                                                                             | `rtsp://username:password@192.168.1.123:554/channel1` [docs](https://www.qnap.com/en/how-to/faq/article/what-is-the-qusbcam2-rtsp-url-format)                                                                                        |
    | Raspberry Pi | PiCam                                                                                | [read more](https://github.com/AlexxIT/WebRTC/issues/261)                                                                                                                                                                            |
    | Reolink      | RLC-410, RLC-410W, RLC-510WA, E1 Pro, E1 Zoom, 4505MP | RLC-510WA support sound, E1 Zoom support sound, PTZ and zoom                                                                                                                                                                         |
    | Reolink      | E1                                                                                   | `rtsp://admin:password@192.168.1.123:554/h264Preview_01_main`                                                                                                                                                                                        |
    | Sonoff       | GK-200MP2-B                                           | support sound and [PTZ](https://github.com/AlexxIT/SonoffLAN#sonoff-gk-200mp2-b-camera), `rtsp://rtsp:12345678@192.168.1.123:554/av_stream/ch0` and `/av_stream/ch1`                                                                                                |
    | SriHome      | SH035                                                                                | `rtsp://192.168.xxx.xxx:8554/profile0` and `/profile1` and `/profile2`                                                                                                                                                               |
    | Topvico      |                                                                                      | `rtsp://192.168.1.123:8554/stream0` or `rtsp://192.168.1.123:554/ch0_0.264`                                                                                                                                                                                         |
    | TP-Link      | Tapo C100/C200/C210/C220/C310                         | `rtsp://user:pass@192.168.1.123:554/stream1` and `/stream2`                                                                                                                                                                                                         |
    | TVT/Secutech | NVR-0808B2-8P                                                                        | `rtsp://user:pass@192.168.1.123:554/chID=1&streamType=main` and `chID=2&streamType=main`                                                                                                                                                                            |
    | TVT/Secutech | IPC5-DF28SN                                                                           | `rtsp://user:pass@192.168.1.123:554/profile1` and `/profile2`                                                                                                                                                                                                       |
    | Unifi        | G4 Dome, G4 doorbell, G3 Bullet, G3 Flex              | Copy the rtsps link from the camera's settings in Unifi Protect, but change the link to `rstp://` (it defaults to rstps://), change the port to `7447`, and remove any query params                                                                                 |
    | Wyze         | Cam v2/v3, Cam Pan v1/v2                              | support sound                                                                                                                                                                                                                        |
    | Xiaomi       | Dafang                                                                               | [with hack](https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks), `rtsp://192.168.1.123:8554/unicast` <br> Video: H264, size: 1920x1080, bitrate: 1000, format: VBR, frame rate: 10 <br> Audio: PCMU, rate in: 8000, rate out: 44100 |
    | Yale         | SV-4CFDVR-2, SV-DAFX                                                                 | `rtsp://admin:password@192.168.1.123/cam/realmonitor?channel=1&subtype=0`                                                                                                                                                            |
    | Yale         | SV-DPFX                                                                              | `rtsp://admin:password@192.168.1.123/cam/realmonitor?channel=1&subtype=1`                                                                                                                                                            |
    | Yi           | Hi3518e Chipset                                                                      | [with hack](https://github.com/alienatedsec/yi-hack-v5)                                                                                                                                                                              |
    | Yi           | MStar Infinity Chipset                                                               | [with hack](https://github.com/roleoroleo/yi-hack-MStar)                                                                                                                                                                              |