Home Assistant integration to expose an API to retrieve the camera stream source URL.
For example, it allows you to import Tuya, Nest and possibly other cameras to go2rtc and Frigate.
Easiest install is via HACS:
-
Click the button above, and install this integration via HACS. Do not try to configure it yet.
-
Restart Home Assistant.
-
Add the following to your
configuration.yaml
file:expose_camera_stream_source:
-
Restart Home Assistant again.
Now the integration should be active.
This integration can be used to import cameras from Home Assistant to go2rtc and Frigate, including cameras which does not expose an RTSP feed by default, like some Tuya and Nest cameras.
If you are running go2rtc as an add-on in Home Assistant, the process is a little simpler (if not, check here). Here's an example of the go2rtc configuration:
# go2rtc.yaml
streams:
my_camera:
- echo:bash /config/custom_components/expose_camera_stream_source/get_stream.sh camera.my_camera
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.
You can then use the my_camera
go2rtc stream in Frigate for things like object detection and recording:
# frigate.yml
my_camera:
ffmpeg:
inputs:
- path: rtsp://192.168.1.10:8554/my_camera
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).
Tip: Try to first play the RTSP link above in VLC before adding to Frigate, to ensure everything is working up to this point.
When go2rtc is not running as a Home Assistant add-on, you need to prepare a script and mount it to the go2rtc container. Here is how the script should look like:
#!/usr/bin/env bash
set -eu
HA_TOKEN="${HA_TOKEN:?"HA_TOKEN is not set, make sure to have this environment variable set with your Home Assisant long-lived token."}"
entity_id="${1}"
exec curl -fsSL -H "Authorization: Bearer ${HA_TOKEN}" "http://192.168.1.10:8123/api/camera_stream_source/${entity_id}"
Paste the content above in a file named get_ha_stream.sh
. For this example, we will store the file at your home folder (~/get_ha_stream.sh
). Then give it execution permission with the following command:
chmod +x ~/get_ha_stream.sh
You will also need a long-lived access token from Home Assistant. To generate one:
- Go to your Home Assistant profile page:
- Scroll down to Long-Lived Access Token, and click in Create Token.
- Give it a name, like
go2rtc
and press Ok. - Copy your generated access token and save it. We will need it soon.
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:
# docker-compose.yaml
services:
go2rtc:
image: alexxit/go2rtc
network_mode: host
restart: always
volumes:
- "~/go2rtc.yaml:/config/go2rtc.yaml"
+ - "~/get_ha_stream.sh:/config/get_ha_stream.sh"
+ environment:
+ HA_TOKEN: paste-your-token-here
And here is an example of the go2rtc configuration:
# go2rtc.yaml
streams:
my_camera:
- echo:/config/get_ha_stream.sh camera.my_camera
The rest is just like the guide for the add-on.