Skip to content

Cast or share camera stream

Alex X edited this page Feb 22, 2024 · 4 revisions

Home Assistant Cast

Show camera stream on Chromecast, Android TV or Google Smart Screen.

You can cast lovelace view with cast.show_lovelace_view service or with entities card:

type: entities
entities:
  - type: cast
    name: Cast all cameras
    dashboard: lovelace
    view: cameras  # View URL: https://myhass.duckdns.org/lovelace/cameras
  - type: cast
    name: Cast main camera
    dashboard: lovelace-cameras
    view: sonoff  # View URL: https://myhass.duckdns.org/lovelace-cameras/sonoff

Up to 4 cameras fit on a regular lovelace view. If you switch the lovelace view to panel mode, one camera will be displayed in full screen.

This way will work only if you has public HTTPS access to your Home Assistant!

DashCast

WebRTC component provide it's own webrtc.dash_cast service for casting single camera stream with DashCast application.

It works even if you has only HTTP local access to your Home Assistant.

script:
  dash_cast_camera:
    alias: DashCast camera
    sequence:
      - service: webrtc.dash_cast
        entity_id: media_player.mibox4  # change to you chromecast media player
        data:
          # url: rtsp://rtsp:12345678@192.168.1.123:554/av_stream/ch0
          entity: camera.sonoff  # you can use camera entity_id or url
          extra:  # optional settings for custom card (like in readme)
            mode: webrtc,mse

HTML page

Component also provide webrtc.create_link service. The service will create a link to a special web page:

https://myhass.duckdns.org/webrtc/embed?url=0744316855362345991470607097031665424279

The page will be accessible from anywhere without a login and password to Home Assistant! You can specify either a random or a permanent link_id.

By default this page can be opened only one time and will stop opening in a minute after creation. So you can use it securely in any notification service without worrying that your private data will be leaked somewhere. But remember, the link has the public address to your Home Assistant. Also with WebRTC the viewer can get your real IP address, even if you use NabuCasa or a similar service.

script:
  create_camera_link:
    alias: Create temporary camera link
    sequence:
      - variables:
          link_id: "0{% for _ in range(39) %}{{ range(10)|random }}{% endfor %}"

      - service: webrtc.create_link
        data:
          link_id: "{{ link_id }}"  # create a random or permanent link ID
          # url: rtsp://rtsp:12345678@192.168.1.123:554/av_stream/ch0
          entity: camera.sonoff  # you can use camera entity_id or url
          open_limit: 1  # how many times a link can be opened (0 - unlimit, 1 - default)
          time_to_live: 60  # how many seconds will the link live (0 - unlimit, 60 - default)

      - service: persistent_notification.create
        data:
          message: '<a href="/webrtc/embed?url={{ link_id }}" target="_blank">Open Camera</a>' 

If necessary, you can disable the open_limit and time_to_live settings, specify a permanent link_id and share the camera link publicly with family and friends. Without having to share access to Home Assistant. The camera connection settings are also not available publicly.

Example: you can use this link in PiPup application for Android TV.

DIY

If you are a web developer, you can develop your own web interface and use the REST API with permanent token to get the camera stream.

Example: module to MagicMirror project.

Clone this wiki locally