How to add a go2rtc stream into HomeKit
Spent hours trying to understand the process, to no avail.
I want to add a H264 camera, which I stream through go2rtc, into my HomeKit home. If I understand correctly, it's possible. However what I don't understand is how the pairing process works.
- Apple Home app expects a QR code (which I don't have?),
- or I can see locally discovered devices (which lists other devices but NOT my go2rtc camera),
- or I can enter a setup pin manually (which does nothing).
So how is the process supposed to work? Documentation (the readme file) doesn't mention that at all...
I guess it works via announcing the camera via mDNS? If so, I couldn't quite understand how the announcement process works exactly.
Is an mDNS daemon needed? If so, what configuration is expected from it? (I use Avahi, so in /etc/avahi/avahi-daemon.conf I set publish-workstation=yes, tried also with no.) But most likely it's not needed (since there's no dbus mentioned anywhere), so I also tried running with Avahi disabled.
I did monitored new mDNS announcements on another device in the same LAN (macOS's dns-sd -B) and saw no new devices appear, so the announcements didn't seem to work.
I did disable firewall, but that changed nothing.
Here's my config:
streams:
car:
- rtsp://login:[email protected]/live
- ffmpeg:car#audio=opus
homekit:
car:
name: Car camera
webrtc:
candidates:
- 192.168.1.15:8555
rtsp:
listen: ":8554" # RTSP Server TCP port, default - 8554
username: "admin" # optional, default - disabled
password: "pass" # optional, default - disabled
default_query: "video&audio"
Here's the output log (that's all I get):
[test@tyan-epyc go2rtc]$ ./go2rtc_linux_amd64
00:41:02.620 INF go2rtc version 1.8.5 linux/amd64
00:41:02.621 INF [api] listen addr=:1984
00:41:02.621 INF [rtsp] listen addr=:8554
00:41:02.621 INF [webrtc] listen addr=:8555
Also tried with 1.8.2.
I see that I'm probably supposed to see a lot of [homekit] yada yada in the log, but I see none. So some prerequisite seems not been met, so no mDNS announcements are being created. But (remote) debugging it will take me days. Maybe there's an earier explanation I'm missing?
In web GUI in Add tab, under Apple HomeKit (or via curl'ing /api/homekit), I can see my own camera as Car-camera go2rtc/1.8.5 homekit://192.168.1.15:1984?device_id=39:DB:AB:1A:2B:C8&feature=0&status=1, so something seems working.
I'm extremely confused what I'm wrong.
A another good GUI-based tool for seeing mDNS info on MacOS is the app "Discovery", it helped me find some issues in my network setup: https://tildesoft.com/
I hope you figure this out, I'd like to simplify my setup down to just using go2rtc to provide my cameras in HomeKit!
I have a similar issue, and I have idea what might be causing it. It's mDNS-related. When you open http://go2rtc:1984/add.html page and click on "Apple HomeKit", for a brief moment the camera appears in Home app and you can add it. It then works for some time and then stops working. If you open that add.html page again and click on "Apple HomeKit", the camera starts working again the Home App.
When you click on "Apple HomeKit", it queries the go2rtc homekit API, which starts mDNS discovery. I think the discovery must be running all the time for the cameras to be discoverable and functional in the Home App.
- go2rtc uses mDNS proto for announcing cameras to network
- you don't needs QR, you can enter PIN code manually
- you don't needs any additional software on your server (Avahi, etc)
- theoretically, having additional software (Avahi, etc) should not be a problem, but who knows...
- go2rtc and iOS should be in the same subnet
- go2rtc should have access to network (port forwarding via Docker or VM - may not be enough)
- the go2rtc API module should not have a password (RTSP module - OK), this will be fixed in the future
- bad routers, network cards or network drivers can be cause of problems
OK, I think I figured it out.
The problem was my setup. I was running HomeAssistant in docker using network_mode: host (so that network discovery works), and at the same time I was running go2rtc on the same host, in docker with network_mode: host.
Apparently, there was a conflict between HomeAssistant and go2rtc, both trying to listen to UDP port 5353, but only one receiving packets at a time.
Solved by creating a separate ipvlan/macvlan network for go2rtc (which is a bit tricky to configure properly). Now cameras are discovered immediately and work in Home app no problem (but only from 1 device at a time).
- go2rtc should have access to network (port forwarding via Docker or VM - may not be enough)
If I'm running Frigate with HomeAssistant the container is setup with port forwarding, is there anyway for go2rtc to utilize the host IP for the HomeKit URI instead of the container IP?
Was troubleshooting this for hours last night thinking I was configuring Frigate wrong before I finally exposed go2rtc 1984 and saw they HomeKit URI referencing a 172 container address instead of the host.
It's recommended to use go2rtc only in network host mode for nice protocols like WebRTC, HomeKit, RTSP UDP and other https://hub.docker.com/r/alexxit/go2rtc