Realtime camera streaming without any delay - WebRTC

Thanks for this brilliant tip. Just updated my pop-up to utilise this!

alias: 'PopUp Driveway Cam for 10s'
sequence:      
  - service: browser_mod.popup
    data:
      title: Driveway Action Detected
      deviceID:
        - samsung10_fkb_tabletui
      large: true
      hide_header: false
      card:  
        type: 'custom:webrtc-camera'
        url: !secret driveway_3rd_h264_720
  - delay: 00:00:10
  - service: browser_mod.close_popup
1 Like

Does anyone have this setup in a Synology Virtual Machine? Everything works great except this WebRTC addon. I can add streams and view the bunny video but everything is incredibly choppy. Like its at less than 5fps. I did a fresh install with just WebRTC and again super choppy. Thoughts?

Also, the Frigate stream is absolutely flawless, no buffering and no stuttering.

Turns out it is stuck in MSE mode until I manually change the port settings in the configuration. Each reboot I have to change to a different number and it works. Any ideas on what to do?

Hello guys, i’m trying this great component.

If i’m in my local network it’s all perfect, but outside of my LAN it isn’t working.
Due to the limitation of iOS i’m using the second method mentioned in the documentation.

My HA Core is running on Docker with the host network mode, i put the UDP port range of the integration from 50000 to 50255 and i Forwarded the same ports from my router (using the following setup: from 50000 to 502500, external port 50000, IP= my HA IP address).

But the streaming isn’t working.

This is what I get:
image

Hi I do not understand how to add this component. I am using YAML lovelace


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

this above is not working, also the below not working


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

??Cattura

how and where should I save this?

Hi all,

@AlexxIT excellent work; stream delay was a major issue that you managed to overcome :wink:.

Has anyone managed to utilize the ‘custom’ PTZ config example for a camera?

My issue is the following. I have two cameras for which I have found the URLs for PTZ movement. Examples (for right direction) are:
Camera 1 (wanscam):
PTZ start right: http:// 10.2.124.81:1027/web/cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=right&-speed=45

PTZ stop: http:// 10.2.124.81:1027/web/cgi-bin/hi3510/ptzctrl.cgi?-step=0&-act=stop&-speed=45

Camera 2 (floureon):
PTZ start right: http:// 10.2.124.83/form/setPTZCfg?command=4&ZFSpeed=0&PTSpeed=0&panSpeed=8&tiltSpeed=8&focusSpeed=2&zoomSpeed=2
PTZ stop: http:// 10.2.124.83/form/setPTZCfg?command=0&ZFSpeed=0&PTSpeed=0&panSpeed=8&tiltSpeed=8&focusSpeed=2&zoomSpeed=2

In order to control my cameras via home assistant I have created a script that calls the necessary PTZ actions; and assign these to a button on the UI. For instance the below example works for the right movement - when I assign the ‘balcony_cam_right’ script to a UI button and press it, the camera moves right:

rest_command:
  balcony_cam_start_right:
    url: “http://10.2.124.83/form/setPTZCfg?command=4&ZFSpeed=0&PTSpeed=0&panSpeed=8&tiltSpeed=8&focusSpeed=2&zoomSpeed=2”
  balcony_cam_stop:
    url: “http://10.2.124.83/form/setPTZCfg?command=0&ZFSpeed=0&PTSpeed=0&panSpeed=8&tiltSpeed=8&focusSpeed=2&zoomSpeed=2”

script:
  balcony_cam_right:
    sequence:
      - service: rest_command.balcony_cam_start_right
      - service: rest_command.balcony_cam_stop

Though…. I would like to avoid this and utilize the embedded PTZ controls offered by webrtc plugin.

In the lovelace card I have placed the below code:

type: custom:webrtc-camera
url: rtsp://10.2.124.83:1031/1/h264major
webrtc: true
ptz:
  service: script.camera_ptz
  data_left:
    direction: 3
  data_right:
    direction: 4
  data_up:
    direction: 1
  data_down:
    direction: 2

I have tried to write the proper code in the yalm file but with no luck. Basically I do not know how I can retrieve the “direction” parameter in the below code. Since each camera has its own PTZ functions (e.g. for right direction, one camera uses the “0” command, where the another one the “right” tag) I would like to create a script by which I can define these.

script:
  camera_ptz:
    sequence:
      - service: >
          {% if {{direction}} == 4 %} script.balcony_cam_right 
          {% else %} script.balcony_cam_down {% endif %}

If I manage to fix the above code, then I can enhance the ‘if’ statements so as to include all directions. Any help on the above ‘camera_ptz’ script would be appreciated.
Thank you.

solved it :slight_smile: Below is my config in case someone else faces same difficulties…

in Lovelace

type: custom:webrtc-camera
url: rtsp://10.2.124.83:1031/1/h264major
webrtc: true
ptz:
  service: script.camera_ptz
  data_left:
    direction: left
  data_right:
    direction: right
  data_up:
    direction: up
  data_down:
    direction: down

in yalm

rest_command:
  balcony_cam_start_right:
    url: “http://10.2.124.83/form/setPTZCfg?command=4&ZFSpeed=0&PTSpeed=0&panSpeed=8&tiltSpeed=8&focusSpeed=2&zoomSpeed=2”

<...similar for other directions...>

  balcony_cam_stop:
    url: “http://10.2.124.83/form/setPTZCfg?command=0&ZFSpeed=0&PTSpeed=0&panSpeed=8&tiltSpeed=8&focusSpeed=2&zoomSpeed=2”

script:
  camera_ptz:
    sequence:
      - service: '{% if direction == "left" %} rest_command.balcony_cam_start_left
           {% elif direction == "right" %} rest_command.balcony_cam_start_right 
           {% elif direction == "up" %} rest_command.balcony_cam_start_up 
           {% elif direction == "down" %} rest_command.balcony_cam_start_down 
           {% endif %}'
      - service: rest_command.balcony_cam_stop

between the movement & the stop ptz you can also add a delay to increase the stepping (in case you do not want to change url or camera’s config speed.

2 Likes

How can I have the default camera entity Still Image functionality with this?

How can I have the default camera entity Still Image functionality with this?

what do you mean? webrtc (if I am not mistaken) is for streaming, not for still images.

This card doesn’t actually use the hass cameras, it talks directly to the camera using RTSP and converts that to WebRTC for display in the card. If you want to use hass cameras, you will need to use the standard cards like the picture entity card.

@geolos @scstraus

What would be great a [custom?] card that shows the camera card’s default still image url with a custom action to launch the WebRTC steam/webRTC card when clicking on the default card.

How about Picture Entity Card - Home Assistant ?
This card can show the still image. And you can define a tap action.

Just read this in the changelog for 2021.11

@allenporter blew our minds this release by adding initial support for WebRTC streams and cameras to Home Assistant.

Someone already tested it?

It is not handling rtsp to webrtc conversion, it is expecting that camera/device is already publishing as WebRTC. So not feasible for many of us.

I am using a conditional card, when camera is not streaming showing picture card, when streaming showing WebRTC card.

There’s also a script to start streaming in click event of picture card.

hi, personally I would be more interested of not loosing the PTZ buttons when you see full screen the cameras; though the idea that Se7enair has shared might look valuable to others.

I started with Frigate and then noticed the lagginess of the RTSP feed was back. Turns out WebRTC is already setup as a source in the Frigate Card. Also - I am using Tailscale and just tested with the wifi turned off on the phone - All 7 cams in almost realtime. Not sure what made me so lucky but maybe try Tailscale (no port forwarding needed)

1 Like

Tailscale is awesome. Been using it awhile now and it makes things super easy to setup.

1 Like

hello all,

I try to setup this component but get eroor that WEBrtc server is not reachable. I opened an issue on Github:

ERROR - WebRTC Server not available ¡ Issue #160 ¡ AlexxIT/WebRTC (github.com)