Skip to content

Commit 3dad894

Browse files
committed
Greatly simplify the setup procedure by dropping the need for get_stream.sh
1 parent b7c27b3 commit 3dad894

File tree

1 file changed

+43
-236
lines changed

1 file changed

+43
-236
lines changed

README.md

Lines changed: 43 additions & 236 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66

77
_Home Assistant integration to expose an API to retrieve the camera stream source URL._
88

9-
For 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.
9+
For example, it allows you to [import](#importing-cameras-from-home-assistant-to-go2rtc-or-frigate) Tuya, Nest and possibly other cameras to [go2rtc](https://github.com/alexxit/go2rtc) or [Frigate](https://github.com/blakeblackshear/frigate).
1010

11-
Note, 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/)**.
11+
Note, however, that **this integration will only work if you are already able to view your camera stream in Home Assistant through [HLS](https://www.home-assistant.io/integrations/stream/)**.
1212

13-
**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.
13+
**For cameras that exclusively work through WebRTC** this integration will not help. It is the case for [certain Nest and Tuya cameras](https://github.com/felipecrs/hass-expose-camera-stream-source/issues/5), for example.
1414

15-
If that is your case:
15+
Here are some alternatives:
1616

17-
- Nest WebRTC-native cameras are supported natively in go2rtc, see [here](https://github.com/AlexxIT/go2rtc?tab=readme-ov-file#source-nest) for more details.
18-
- Tuya WebRTC-native cameras are not supported either by Home Assistant or go2rtc. If you need it, you can express your interest in:
19-
- https://github.com/AlexxIT/go2rtc/issues/315 (being worked on by @seydx, but you can [try it already](https://github.com/AlexxIT/go2rtc/issues/315#issuecomment-2905955963))
17+
- Nest WebRTC-only cameras are supported natively in go2rtc through the [Nest source](https://github.com/AlexxIT/go2rtc?tab=readme-ov-file#source-nest).
18+
- Tuya WebRTC-only cameras are not supported by Home Assistant, but native support in go2rtc is being worked on by @seydx, and you can [try it already](https://github.com/AlexxIT/go2rtc/issues/315#issuecomment-2905955963).
2019
- Cameras that only support still images can be added to go2rtc through [this method](https://github.com/felipecrs/hass-expose-camera-stream-source/issues/53).
2120

2221
## Installation
@@ -37,98 +36,50 @@ Easiest install is via [HACS](https://hacs.xyz/):
3736
3837
Now the integration should be active.
3938
40-
## Importing cameras from Home Assistant to go2rtc and Frigate
41-
42-
This 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**.
43-
44-
### When go2rtc is running within the Frigate add-on
45-
46-
<details>
47-
<summary>Click here to show</summary>
48-
49-
If you are running go2rtc within the Frigate add-on, you can use the following configuration:
50-
51-
> [!IMPORTANT]
52-
> If using Frigate 0.16 Beta or newer, change the paths below from `/config/` to `/homeassistant/`.
39+
## Importing cameras from Home Assistant to go2rtc or Frigate
40+
41+
This integration can be used to import cameras from Home Assistant to [go2rtc](https://github.com/alexxit/go2rtc) or [Frigate](https://github.com/blakeblackshear/frigate).
42+
43+
> [!IMPORTANT]
44+
> Before importing to go2rtc, let's make sure a stream source is available for your camera. Simply run this command in the [Terminal](https://github.com/hassio-addons/addon-ssh) or [VS Code add-on](https://github.com/hassio-addons/addon-vscode):
45+
>
46+
> ```console
47+
> curl -fsSL http://supervisor/core/api/camera_stream_source/camera.my_camera -H "Authorization: Bearer ${SUPERVISOR_TOKEN}"
48+
> ```
49+
>
50+
> **Replacing** `camera.my_camera` with your camera entity ID.
51+
>
52+
> If you have **no access to add-ons**, you will need to replace `${SUPERVISOR_TOKEN}` with your Home Assistant long-lived access token and `http://supervisor/core` with the IP address or URL of your Home Assistant. Read below for more details. If you are on Windows, you can run that command in PowerShell by changing `curl` to `curl.exe`.
53+
>
54+
> After running it, it should output an RTSP or HTTP URL.
55+
>
56+
> **If it did not**, sorry but stream source is not available for your camera.
57+
>
58+
> **If it did, copy this URL and try to play it in [VLC](https://www.videolan.org/vlc/)**.
59+
>
60+
> Be quick though, some URLs expire after a few seconds if no connection is made. You can generate a new one by running the command again.
61+
>
62+
> **If it does not play in VLC**, it will not play in go2rtc or Frigate either. Sorry.
63+
64+
Here is an example of how to do it in your go2rtc configuration file:
5365

5466
```yaml
55-
# /config/frigate.yaml
56-
57-
go2rtc:
58-
streams:
59-
my_camera:
60-
- echo:bash /config/custom_components/expose_camera_stream_source/get_stream.sh camera.my_camera
67+
# go2rtc.yaml
6168
62-
cameras:
69+
streams:
6370
my_camera:
64-
ffmpeg:
65-
inputs:
66-
- path: rtsp://127.0.0.1:8554/my_camera?video
67-
input_args: preset-rtsp-restream-low-latency
68-
roles:
69-
- detect
70-
```
71-
72-
Where `camera.my_camera` is the Home Assistant entity ID for the camera that you want to import the stream from.
73-
74-
</details>
75-
76-
### When go2rtc is running within Frigate via docker
77-
78-
<details>
79-
<summary>Click here to show</summary>
80-
81-
When 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:
82-
83-
```bash
84-
#!/usr/bin/env bash
85-
86-
set -eu
87-
88-
HA_TOKEN="${HA_TOKEN:?"HA_TOKEN is not set, make sure to have this environment variable set with your Home Assisant long-lived token."}"
89-
entity_id="${1}"
90-
91-
exec curl -fsSL -H "Authorization: Bearer ${HA_TOKEN}" "http://192.168.1.10:8123/api/camera_stream_source/${entity_id}"
71+
- 'echo:curl -fsSL http://supervisor/core/api/camera_stream_source/camera.my_camera -H "Authorization: Bearer ${SUPERVISOR_TOKEN}"'
9272
```
9373

94-
Where `192.168.1.10` is your Home Assistant's IP address.
95-
96-
Paste 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:
97-
98-
```console
99-
chmod +x /path/to/your/config/get_ha_stream.sh
100-
```
101-
102-
You will also need a long-lived access token from Home Assistant. To generate one:
103-
104-
1. 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/)
105-
2. Scroll down to _Long-Lived Access Token_, and click in _Create Token_.
106-
3. Give it a name, like `go2rtc` and press _Ok_.
107-
4. Copy your generated access token and save it. We will need it soon.
108-
109-
Now, 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:
110-
111-
```diff
112-
# docker-compose.yaml
113-
114-
services:
115-
frigate:
116-
image: ghcr.io/blakeblackshear/frigate:stable
117-
volumes:
118-
- /path/to/your/config:/config
119-
+ environment:
120-
+ HA_TOKEN: paste-your-long-lived-access-token-here
121-
```
122-
123-
And here is an example of the Frigate configuration:
74+
Or, **if you are using Frigate**, here is how you can do the same in your Frigate configuration file:
12475

12576
```yaml
126-
# frigate.yaml
77+
# config.yml
12778
12879
go2rtc:
12980
streams:
13081
my_camera:
131-
- echo:/config/get_ha_stream.sh camera.my_camera
82+
- 'echo:curl -fsSL http://supervisor/core/api/camera_stream_source/camera.my_camera -H "Authorization: Bearer ${SUPERVISOR_TOKEN}"'
13283
13384
cameras:
13485
my_camera:
@@ -140,168 +91,24 @@ cameras:
14091
- detect
14192
```
14293

143-
Where `camera.my_camera` is the Home Assistant entity ID for the camera that you want to import the stream from.
144-
145-
</details>
146-
147-
### When go2rtc is installed as an add-on
148-
149-
<details>
150-
<summary>Click here to show</summary>
151-
152-
If 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:
153-
154-
```yaml
155-
# /config/go2rtc.yaml
156-
157-
streams:
158-
my_camera:
159-
- echo:bash /config/custom_components/expose_camera_stream_source/get_stream.sh camera.my_camera
160-
```
161-
162-
Where `camera.my_camera` is the Home Assistant entity ID for the camera that you want to import the stream from.
163-
164-
The `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.
165-
166-
Then, you can consume your go2rtc's `my_camera` stream in other applications like Frigate or other NVRs:
167-
168-
- `rtsp://192.168.1.10:8554/my_camera`
169-
170-
Where `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).
94+
**Replacing** `camera.my_camera` with your Home Assistant camera entity ID.
17195

172-
> **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.
96+
Note that **you do not need to replace `${SUPERVISOR_TOKEN}` or make any further changes** if you are running go2rtc through the [WebRTC integration](https://github.com/AlexxIT/WebRTC), [go2rtc add-on](https://github.com/AlexxIT/go2rtc#go2rtc-home-assistant-add-on), or [Frigate add-on](https://docs.frigate.video/frigate/installation#home-assistant-addon).
17397

174-
</details>
175-
176-
### When go2rtc is running via docker
177-
178-
<details>
179-
<summary>Click here to show</summary>
180-
181-
When 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:
182-
183-
```bash
184-
#!/usr/bin/env bash
185-
186-
set -eu
187-
188-
HA_TOKEN="${HA_TOKEN:?"HA_TOKEN is not set, make sure to have this environment variable set with your Home Assisant long-lived token."}"
189-
entity_id="${1}"
190-
191-
exec curl -fsSL -H "Authorization: Bearer ${HA_TOKEN}" "http://192.168.1.10:8123/api/camera_stream_source/${entity_id}"
192-
```
193-
194-
Where `192.168.1.10` is your Home Assistant's IP address.
195-
196-
Paste 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:
197-
198-
```console
199-
chmod +x /path/to/your/get_ha_stream.sh
200-
```
201-
202-
You will also need a long-lived access token from Home Assistant. To generate one:
203-
204-
1. 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/)
205-
2. Scroll down to _Long-Lived Access Token_, and click in _Create Token_.
206-
3. Give it a name, like `go2rtc` and press _Ok_.
207-
4. Copy your generated access token and save it. We will need it soon.
208-
209-
Now, 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:
210-
211-
```diff
212-
# docker-compose.yaml
213-
214-
services:
215-
go2rtc:
216-
image: alexxit/go2rtc
217-
network_mode: host
218-
restart: always
219-
volumes:
220-
- /path/to/your/go2rtc.yaml:/config/go2rtc.yaml
221-
+ - /path/to/your/get_ha_stream.sh:/config/get_ha_stream.sh
222-
+ environment:
223-
+ HA_TOKEN: paste-your-long-lived-access-token-here
224-
```
225-
226-
And here is an example of the go2rtc configuration:
227-
228-
```yaml
229-
# go2rtc.yaml
230-
231-
streams:
232-
my_camera:
233-
- echo:/config/get_ha_stream.sh camera.my_camera
234-
```
235-
236-
Where `camera.my_camera` is the Home Assistant entity ID for the camera that you want to import the stream from.
237-
238-
Then, you can consume your go2rtc's `my_camera` stream in other applications like Frigate or other NVRs:
239-
240-
- `rtsp://192.168.1.10:8554/my_camera`
241-
242-
Where `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).
243-
244-
> **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.
245-
246-
</details>
247-
248-
### When go2rtc is running via the WebRTC integration
249-
250-
<details>
251-
<summary>Click here to show</summary>
252-
253-
When 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.
254-
255-
First, you will need a long-lived access token from Home Assistant. To generate one:
98+
**Otherwise**, you need to replace `${SUPERVISOR_TOKEN}` with your Home Assistant long-lived access token. To generate one:
25699

257100
1. 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/)
258101
2. Scroll down to _Long-Lived Access Token_, and click in _Create Token_.
259102
3. Give it a name, like `go2rtc` and press _Ok_.
260-
4. Copy your generated access token and save it. We will need it soon.
261-
262-
Then, you can create the script. Here is how the script should look like:
263-
264-
```bash
265-
#!/usr/bin/env bash
266-
267-
set -eu
268-
269-
HA_TOKEN="<put your long-lived access token here>"
270-
entity_id="${1}"
271-
272-
exec curl -fsSL -H "Authorization: Bearer ${HA_TOKEN}" "http://127.0.0.1:8123/api/camera_stream_source/${entity_id}"
273-
```
274-
275-
Paste 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.
276103

277-
Then, give it execution permission with the following command:
278-
279-
```console
280-
chmod +x /config/get_ha_stream.sh
281-
```
282-
283-
And here is an example of the go2rtc configuration:
104+
**Additionally**, you need to replace `http://supervisor/core` with the IP address or URL of your Home Assistant instance. Example:
284105

285106
```yaml
286-
# go2rtc.yaml
287-
288107
streams:
289108
my_camera:
290-
- echo:/config/get_ha_stream.sh camera.my_camera
109+
- 'echo:curl -fsSL http://192.168.1.10:8123/api/camera_stream_source/camera.my_camera -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI4ZDljNzU4NjM2OGQ0NzI0YmJhZjVlODBmZDdjODMwMiIsImlhdCI6MTc0ODA0OTc4OSwiZXhwIjoyMDYzNDA5Nzg5fQ.RmV0VN43byRA-azB8N7jUn2j7W9LRppJlzQ1aOQcnFc"'
291110
```
292111

293-
Where `camera.my_camera` is the Home Assistant entity ID for the camera that you want to import the stream from.
294-
295-
Then, you can consume your go2rtc's `my_camera` stream in other applications like Frigate or other NVRs:
296-
297-
- `rtsp://192.168.1.10:8554/my_camera`
298-
299-
Where `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).
300-
301-
> **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.
302-
303-
</details>
304-
305112
## Bonus: importing Tuya cameras to go2rtc without Home Assistant
306113

307114
This 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.

0 commit comments

Comments
 (0)