{"id":13585112,"url":"https://github.com/felipecrs/hass-expose-camera-stream-source","last_synced_at":"2025-04-05T19:09:34.282Z","repository":{"id":110560576,"uuid":"563352814","full_name":"felipecrs/hass-expose-camera-stream-source","owner":"felipecrs","description":"Allows to import Home Assistant cameras into go2rtc and Frigate","archived":false,"fork":false,"pushed_at":"2024-11-02T16:39:37.000Z","size":212,"stargazers_count":120,"open_issues_count":3,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T18:05:57.679Z","etag":null,"topics":["custom-component","home-assistant","homeassistant"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/felipecrs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["felipecrs"]}},"created_at":"2022-11-08T12:45:15.000Z","updated_at":"2025-03-26T17:50:12.000Z","dependencies_parsed_at":"2023-04-19T21:31:51.305Z","dependency_job_id":"21a514bf-fdee-4e03-be6a-b10ddadc55b4","html_url":"https://github.com/felipecrs/hass-expose-camera-stream-source","commit_stats":{"total_commits":41,"total_committers":4,"mean_commits":10.25,"dds":"0.14634146341463417","last_synced_commit":"cf4627df2ce1b9eef6c7b5af1c653bf0eb977732"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":"ludeeus/integration_blueprint","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipecrs%2Fhass-expose-camera-stream-source","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipecrs%2Fhass-expose-camera-stream-source/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipecrs%2Fhass-expose-camera-stream-source/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipecrs%2Fhass-expose-camera-stream-source/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/felipecrs","download_url":"https://codeload.github.com/felipecrs/hass-expose-camera-stream-source/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247386263,"owners_count":20930618,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["custom-component","home-assistant","homeassistant"],"created_at":"2024-08-01T15:04:44.930Z","updated_at":"2025-04-05T19:09:34.165Z","avatar_url":"https://github.com/felipecrs.png","language":"Python","funding_links":["https://github.com/sponsors/felipecrs"],"categories":["Python"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\r\n⭐\u003cb\u003ePlease star this integration in GitHub if it helps you!\u003c/b\u003e⭐\r\n\u003c/p\u003e\r\n\r\n# Expose Camera Stream Source\r\n\r\n_Home Assistant integration to expose an API to retrieve the camera stream source URL._\r\n\r\nFor example, it allows you to [import](#importing-cameras-from-home-assistant-to-go2rtc-and-frigate) Tuya, Nest and possibly other cameras to go2rtc and Frigate.\r\n\r\nNote, however, that **this integration will only work if you are already able to view your camera stream in Home Assistant using [HLS](https://www.home-assistant.io/integrations/stream/)**.\r\n\r\n**For cameras that exclusively only work via WebRTC** (through the [RTSPToWebRTC Home Assistant integration](https://www.home-assistant.io/integrations/rtsp_to_webrtc/)), this method will not help. It is the case for [some specific Nest and Tuya cameras](https://github.com/felipecrs/hass-expose-camera-stream-source/issues/5), for example.\r\n\r\nIf that is your case:\r\n\r\n- Nest WebRTC-native cameras are supported natively in go2rtc, see [here](https://github.com/AlexxIT/go2rtc?tab=readme-ov-file#source-hass) for more details.\r\n- Tuya WebRTC-native cameras are not supported either by Home Assistant or go2rtc. If you need it, you can express your need in:\r\n  - https://github.com/home-assistant/core/issues/68503\r\n  - https://github.com/AlexxIT/go2rtc/issues/315\r\n\r\n## Installation\r\n\r\nEasiest install is via [HACS](https://hacs.xyz/):\r\n\r\n[![Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.](https://my.home-assistant.io/badges/hacs_repository.svg)](https://my.home-assistant.io/redirect/hacs_repository/?owner=felipecrs\u0026repository=hass-expose-camera-stream-source\u0026category=integration)\r\n\r\n1. Click the button above, and install this integration via HACS. Do **not** try to configure it yet.\r\n2. Restart Home Assistant.\r\n3. Add the following to your `configuration.yaml` file:\r\n\r\n   ```yaml\r\n   expose_camera_stream_source:\r\n   ```\r\n\r\n4. Restart Home Assistant again.\r\n\r\nNow the integration should be active.\r\n\r\n## Importing cameras from Home Assistant to go2rtc and Frigate\r\n\r\nThis integration can be used to import cameras from Home Assistant to [go2rtc](https://github.com/alexxit/go2rtc) and [Frigate](https://github.com/blakeblackshear/frigate), **including cameras which does not expose a RTSP feed by default, like some Tuya and Nest cameras**.\r\n\r\n### When go2rtc is running within the Frigate add-on\r\n\r\n\u003cdetails\u003e\r\n  \u003csummary\u003eClick here to show\u003c/summary\u003e\r\n\r\nIf you are running go2rtc within the Frigate add-on, you can use the following configuration:\r\n\r\n```yaml\r\n# /config/frigate.yaml\r\n\r\ngo2rtc:\r\n  streams:\r\n    my_camera:\r\n      - echo:bash /config/custom_components/expose_camera_stream_source/get_stream.sh camera.my_camera\r\n\r\ncameras:\r\n  my_camera:\r\n    ffmpeg:\r\n      inputs:\r\n        - path: rtsp://127.0.0.1:8554/my_camera?video\r\n          input_args: preset-rtsp-restream-low-latency\r\n          roles:\r\n            - detect\r\n```\r\n\r\nWhere `camera.my_camera` is the Home Assistant entity ID for the camera that you want to import the stream from.\r\n\r\n\u003c/details\u003e\r\n\r\n### When go2rtc is running within Frigate via docker\r\n\r\n\u003cdetails\u003e\r\n  \u003csummary\u003eClick here to show\u003c/summary\u003e\r\n\r\nWhen go2rtc is running within Frigate via docker, you need to prepare a Bash script to mount it to the Frigate container. Here is how the script should look like:\r\n\r\n```bash\r\n#!/usr/bin/env bash\r\n\r\nset -eu\r\n\r\nHA_TOKEN=\"${HA_TOKEN:?\"HA_TOKEN is not set, make sure to have this environment variable set with your Home Assisant long-lived token.\"}\"\r\nentity_id=\"${1}\"\r\n\r\nexec curl -fsSL -H \"Authorization: Bearer ${HA_TOKEN}\" \"http://192.168.1.10:8123/api/camera_stream_source/${entity_id}\"\r\n```\r\n\r\nWhere `192.168.1.10` is your Home Assistant's IP address.\r\n\r\nPaste the content above in a file named `get_ha_stream.sh`, and place it in your Frigate's `config` directory, beside your `frigate.yaml`. Then, give it execution permission with the following command:\r\n\r\n```console\r\nchmod +x /path/to/your/config/get_ha_stream.sh\r\n```\r\n\r\nYou will also need a long-lived access token from Home Assistant. To generate one:\r\n\r\n1. Go to your Home Assistant profile page: [![Open your Home Assistant instance and show your Home Assistant user's profile.](https://my.home-assistant.io/badges/profile.svg)](https://my.home-assistant.io/redirect/profile/)\r\n2. Scroll down to _Long-Lived Access Token_, and click in _Create Token_.\r\n3. Give it a name, like `go2rtc` and press _Ok_.\r\n4. Copy your generated access token and save it. We will need it soon.\r\n\r\nNow, you need to make sure your token is added as the `HA_TOKEN` environment variable. If you use Docker Compose, you just need to add something like the below in your configuration:\r\n\r\n```diff\r\n# docker-compose.yaml\r\n\r\nservices:\r\n  frigate:\r\n    image: ghcr.io/blakeblackshear/frigate:stable\r\n    volumes:\r\n      - /path/to/your/config:/config\r\n+   environment:\r\n+     HA_TOKEN: paste-your-long-lived-access-token-here\r\n```\r\n\r\nAnd here is an example of the Frigate configuration:\r\n\r\n```yaml\r\n# frigate.yaml\r\n\r\ngo2rtc:\r\n  streams:\r\n    my_camera:\r\n      - echo:/config/get_ha_stream.sh camera.my_camera\r\n\r\ncameras:\r\n  my_camera:\r\n    ffmpeg:\r\n      inputs:\r\n        - path: rtsp://127.0.0.1:8554/my_camera?video\r\n          input_args: preset-rtsp-restream-low-latency\r\n          roles:\r\n            - detect\r\n```\r\n\r\nWhere `camera.my_camera` is the Home Assistant entity ID for the camera that you want to import the stream from.\r\n\r\n\u003c/details\u003e\r\n\r\n### When go2rtc is installed as an add-on\r\n\r\n\u003cdetails\u003e\r\n  \u003csummary\u003eClick here to show\u003c/summary\u003e\r\n\r\nIf you are running go2rtc as an add-on in Home Assistant, the process is a little simpler (if not, check [here](#when-go2rtc-is-running-via-docker)). Here's an example of the go2rtc configuration:\r\n\r\n```yaml\r\n# /config/go2rtc.yaml\r\n\r\nstreams:\r\n  my_camera:\r\n    - echo:bash /config/custom_components/expose_camera_stream_source/get_stream.sh camera.my_camera\r\n```\r\n\r\nWhere `camera.my_camera` is the Home Assistant entity ID for the camera that you want to import the stream from.\r\n\r\nThe `get_stream.sh` script is included by this integration. You can use it to get the stream source URL for any camera in Home Assistant from inside of any add-on.\r\n\r\nThen, you can consume your go2rtc's `my_camera` stream in other applications like Frigate or other NVRs:\r\n\r\n- `rtsp://192.168.1.10:8554/my_camera`\r\n\r\nWhere `192.168.1.10` is the IP which you can access the go2rtc interfaces (for add-on users it's the same IP as your Home Assistant).\r\n\r\n\u003e **Tip:** Try to first play the RTSP link above in VLC before adding to Frigate or other NVRs, to ensure everything is working up to this point.\r\n\r\n\u003c/details\u003e\r\n\r\n### When go2rtc is running via docker\r\n\r\n\u003cdetails\u003e\r\n  \u003csummary\u003eClick here to show\u003c/summary\u003e\r\n\r\nWhen go2rtc is not running as a Home Assistant add-on, you need to prepare a Bash script and mount it to the go2rtc container. Here is how the script should look like:\r\n\r\n```bash\r\n#!/usr/bin/env bash\r\n\r\nset -eu\r\n\r\nHA_TOKEN=\"${HA_TOKEN:?\"HA_TOKEN is not set, make sure to have this environment variable set with your Home Assisant long-lived token.\"}\"\r\nentity_id=\"${1}\"\r\n\r\nexec curl -fsSL -H \"Authorization: Bearer ${HA_TOKEN}\" \"http://192.168.1.10:8123/api/camera_stream_source/${entity_id}\"\r\n```\r\n\r\nWhere `192.168.1.10` is your Home Assistant's IP address.\r\n\r\nPaste the content above in a file named `get_ha_stream.sh`, and place it beside your `go2rtc.yaml`. Then, give it execution permission with the following command:\r\n\r\n```console\r\nchmod +x /path/to/your/get_ha_stream.sh\r\n```\r\n\r\nYou will also need a long-lived access token from Home Assistant. To generate one:\r\n\r\n1. Go to your Home Assistant profile page: [![Open your Home Assistant instance and show your Home Assistant user's profile.](https://my.home-assistant.io/badges/profile.svg)](https://my.home-assistant.io/redirect/profile/)\r\n2. Scroll down to _Long-Lived Access Token_, and click in _Create Token_.\r\n3. Give it a name, like `go2rtc` and press _Ok_.\r\n4. Copy your generated access token and save it. We will need it soon.\r\n\r\nNow, you need to make sure the script you created earlier is mounted in the go2rtc container, and your token is added as the `HA_TOKEN` environment variable. If you use Docker Compose, you just need to add something like the below in your configuration:\r\n\r\n```diff\r\n# docker-compose.yaml\r\n\r\nservices:\r\n  go2rtc:\r\n    image: alexxit/go2rtc\r\n    network_mode: host\r\n    restart: always\r\n    volumes:\r\n      - /path/to/your/go2rtc.yaml:/config/go2rtc.yaml\r\n+     - /path/to/your/get_ha_stream.sh:/config/get_ha_stream.sh\r\n+   environment:\r\n+     HA_TOKEN: paste-your-long-lived-access-token-here\r\n```\r\n\r\nAnd here is an example of the go2rtc configuration:\r\n\r\n```yaml\r\n# go2rtc.yaml\r\n\r\nstreams:\r\n  my_camera:\r\n    - echo:/config/get_ha_stream.sh camera.my_camera\r\n```\r\n\r\nWhere `camera.my_camera` is the Home Assistant entity ID for the camera that you want to import the stream from.\r\n\r\nThen, you can consume your go2rtc's `my_camera` stream in other applications like Frigate or other NVRs:\r\n\r\n- `rtsp://192.168.1.10:8554/my_camera`\r\n\r\nWhere `192.168.1.10` is the IP which you can access the go2rtc interfaces (for add-on users it's the same IP as your Home Assistant).\r\n\r\n\u003e **Tip:** Try to first play the RTSP link above in VLC before adding to Frigate or other NVRs, to ensure everything is working up to this point.\r\n\r\n\u003c/details\u003e\r\n\r\n### When go2rtc is running via the WebRTC integration\r\n\r\n\u003cdetails\u003e\r\n  \u003csummary\u003eClick here to show\u003c/summary\u003e\r\n\r\nWhen go2rtc is not running as a Home Assistant add-on neither via an add-on, but as part of the WebRTC integration, you need to prepare a Bash script in your `/config` directory.\r\n\r\nFirst, you will need a long-lived access token from Home Assistant. To generate one:\r\n\r\n1. Go to your Home Assistant profile page: [![Open your Home Assistant instance and show your Home Assistant user's profile.](https://my.home-assistant.io/badges/profile.svg)](https://my.home-assistant.io/redirect/profile/)\r\n2. Scroll down to _Long-Lived Access Token_, and click in _Create Token_.\r\n3. Give it a name, like `go2rtc` and press _Ok_.\r\n4. Copy your generated access token and save it. We will need it soon.\r\n\r\nThen, you can create the script. Here is how the script should look like:\r\n\r\n```bash\r\n#!/usr/bin/env bash\r\n\r\nset -eu\r\n\r\nHA_TOKEN=\"\u003cput your long-lived access token here\u003e\"\r\nentity_id=\"${1}\"\r\n\r\nexec curl -fsSL -H \"Authorization: Bearer ${HA_TOKEN}\" \"http://127.0.0.1:8123/api/camera_stream_source/${entity_id}\"\r\n```\r\n\r\nPaste the content above in a file named `get_ha_stream.sh`, and place it in Home Assistant's `/config` directory. Do not forget to put your long-lived access token in the script's placeholder.\r\n\r\nThen, give it execution permission with the following command:\r\n\r\n```console\r\nchmod +x /config/get_ha_stream.sh\r\n```\r\n\r\nAnd here is an example of the go2rtc configuration:\r\n\r\n```yaml\r\n# go2rtc.yaml\r\n\r\nstreams:\r\n  my_camera:\r\n    - echo:/config/get_ha_stream.sh camera.my_camera\r\n```\r\n\r\nWhere `camera.my_camera` is the Home Assistant entity ID for the camera that you want to import the stream from.\r\n\r\nThen, you can consume your go2rtc's `my_camera` stream in other applications like Frigate or other NVRs:\r\n\r\n- `rtsp://192.168.1.10:8554/my_camera`\r\n\r\nWhere `192.168.1.10` is the IP which you can access the go2rtc interfaces (for add-on users it's the same IP as your Home Assistant).\r\n\r\n\u003e **Tip:** Try to first play the RTSP link above in VLC before adding to Frigate or other NVRs, to ensure everything is working up to this point.\r\n\r\n\u003c/details\u003e\r\n\r\n## Bonus: importing Tuya cameras to go2rtc without Home Assistant\r\n\r\nThis repository also provides a script that is able to operate without Home Assistant, allowing you to import Tuya cameras to go2rtc without the need of Home Assistant.\r\n\r\nIt also allows you to select between _RTSP_ and _HLS_ streams, which is not possible with the Home Assistant integration (which is always _RTSP_).\r\n\r\nScript: [get_tuya_stream_url.py](./custom_components/expose_camera_stream_source/scripts/get_tuya_stream_url.py)\r\n\r\nUsage: `Usage: python3 get_tuya_stream_url.py \u003cdevice id\u003e \u003cclient id\u003e \u003cclient secret\u003e \u003ctuya api base url\u003e [stream type]`\r\n\r\nExample:\r\n\r\n```console\r\n$ python3 get_tuya_stream_url.py \u003cdevice id\u003e \u003cclient id\u003e \u003cclient secret\u003e https://openapi.tuyaus.com RTSP\r\nrtsps://ebf0345643b3de54904xgqs:OIB97AMHY7LG8TW6@aws-tractor2.tuyaus.com:443/v1/proxy/echo_show/d91271489ccd46331be3e4f3fa65b5a8893c0799bef1485ba\r\n\r\n$ python3 get_tuya_stream_url.py \u003cdevice id\u003e \u003cclient id\u003e \u003cclient secret\u003e https://openapi.tuyaus.com HLS\r\nhttps://aws-tractor2.tuyaus.com:8033/hls/348ceb3cbe1c4429b849c546c924af9bb5f053cd858ae65e0e3bf.m3u8\r\n```\r\n\r\nAnd it can be integrated with go2rtc in the same way as the Home Assistant integration:\r\n\r\n```yaml\r\n# go2rtc.yaml\r\n\r\nstreams:\r\n  my_camera:\r\n    - echo:python3 /path/to/your/get_tuya_stream_url.py \u003cdevice id\u003e \u003cclient id\u003e \u003cclient secret\u003e https://openapi.tuyaus.com RTSP\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelipecrs%2Fhass-expose-camera-stream-source","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffelipecrs%2Fhass-expose-camera-stream-source","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelipecrs%2Fhass-expose-camera-stream-source/lists"}