6 min read

Setting up a live mast cam in Home Assistant using RTSP & WebRTC

There are lots of advantages to catamarans when it comes to close quarters manoeuvring, but visibility is not one of them. From the helm of our Leopard 45, I really can't see a single part of the bow.

Most of the time this isn't a big problem. We like to stay far away from things you might otherwise hit. When it comes time to pick up a mooring ball or pull into a marina, though, visibility becomes a pretty big issue.

So, after a year of struggling, I finally decided to do something about it.

Leopard sells Raymarine IP cameras as upgrade options when you buy an L45, and they are perhaps one of the most efficient ways to squander money on an utterly redundant setup. The factory installs 2x Raymarine Cam220 units. One forward, under the coach roof - a vantage point from which you can see almost nothing. One aft, deep inside the aft cockpit, from which you can see absolutely nothing.

Both cameras are only 1080p, not particularly wide angle, and only work with the Raymarine chart plotter.

Fortunately, I met someone else with the same boat who had installed a top-down Unifi G4 Bullet right under the radar — and the angle and perspective both looked really good! Down the rabbithole we go.

After looking through the latest Unifi IP camera range, supply chain shortages aside, I decided to go for a G4 Dome camera. This is a newer model than the G4 Bullet, with a slighter wider field of view and moderately better specs.

Ubiquiti UniFi Protect G4 Dome Camera

Compact 4MP Vandal-Resistant Weatherproof Dome Camera with Integrated IR LEDs

$264 on Amazon

The next challenge was figuring out how to power it. Unifi cameras have a passive draw of just 5W, but only work over POE, which is a 48V DC Power standard delivered Over Ethernet. You can achieve POE by using a POE-supported network switch, or a POE injector, but either way you have to get to 48V. On our boat we have 12V DC power direct from the batteries, or 220V AC power from the inverter. Either one requires a converter to step-up or step-down to 48V.

Initially I was planning (and ordered) a full POE switch setup, with a plan to power the switch with a 12-48V DC/DC converter. After a lot of testing, this just felt like overkill to run a single POE device. So in the end, I bought a simple AC POE injector on Amazon that will simply run over AC.

BV-Tech Gigabit PoE+ Injector

Oh my god look at this ugly brick. It works great, no complaints, but I'm deducting a star for how hideous it is.

$18 on Amazon

The camera install up the mast was done by professionals, and went smoothly. We had the G4 Dome attached to the base of the radar mount, with Cat5e run down the mast cable bundle to my fortress of solitude network hub, where it connects to the POE injector, and then a basic (non-POE) TP-Link gigabit switch.

If you use Unifi cameras with a Ubiquiti router, there are all sorts of fancy managed features that integrate together and play nicely. I don't; so the setup experience is a little more basic. The camera lets you adjust some picture settings,  some network settings, and that's about it.

The main setting I'm interested in is the RTSP feed, which can be adjusted in bitrate, frames per second, and quality, allowing you to fine-tune things to suit your usecase best. If all you care about is recording, then you probably want the maximum quality. But if you care about using the camera for a live feed (say, while docking a boat) - then the most important factor is latency.

I don't need the sharpest image, I need an image that shows me as-close-to-realtime as possible as I can get. Which is where the problems began.

Initially, I set up the camera in Home Assistant using the same RTSP method I've written about before.

Adding a Wyze Cam Pan to Home Assistant with RTSP
How to configure the Wyze Cam Pan for Home Assistant using RTSP and a little bit of 3D printing to complete the look.

It worked, as in.. the feed loaded, but right away I noticed there was a solid 2-3s delay in the footage. I'd noticed this when setting up the Cam Pan, too, but I sort of assumed it was a side effect of cheap consumer hardware running over Wifi. I'd expected the more expensive Unifi camera to be latency free, running over ethernet. This lag in the context of docking would render the camera completely pointless, because there's no way you can make quick manoeuvring decisions 2-3s after something has already happened.

Many hours of Googling ensued — "Unifi camera / RTSP video lag" — "Ubiquiti G4 camera latency" — I tried every variation, and I almost gave up hope. Most of my search results contained people talking about a ~2s lag being unavoidable and pretty standard for RTSP in general. I was also able to replicate the same lag by loading the RTSP stream direcly in VLC - to rule out any issue with Home Assistant.

Finally, when I was right on the brink of returning the camera to the seller, I followed a random Home Assistant community link on page 1,592 of Google, and discovered the most wonderful 3rd party component for Home Assistant.

GitHub - AlexxIT/WebRTC: Home Assistant custom component for viewing IP cameras RTSP stream in real time using WebRTC and MSE technology
Home Assistant custom component for viewing IP cameras RTSP stream in real time using WebRTC and MSE technology - GitHub - AlexxIT/WebRTC: Home Assistant custom component for viewing IP cameras RTS...

This little library converts RTSP video streams into WebRTC (the web standard behind most video conferencing products) - and the second I installed it, the lag all but disappeared. It's maybe 0.2s now, which is entirely manageable.

Now, when we go anywhere near a dock or a mooring ball, I have near-perfect visibility of the front of the boat and its surroundings.

I know a few people who have FLIR cameras up their masts that are infinitely superior to this setup, but for under $300 and less than 1% of the price of a FLIR install — I'm pretty thrilled with how this turned out.

It's only been a few weeks, but the camera has come in handy so many times already, including spotting shallow areas while navigating through the Bahamas.

Something I'd like to test out next is whether I can also get the video feed connected to our Raymarine chart plotter - just to save me needing to bring an iPad up to the helm. From what I've read so far, it sounds straightforward? (I'm sure it won't be) — but that will have to wait until I can get my hands on the stupid proprietary cable required to connect an IP camera to SeaTalk/NMEA2k.

Broad IP camera support, a Raymarine advantage
When I outfitted Have Another Day to begin cruising I wanted better visibility of several areas of the boat. IP cameras are the natural way to tackle this but once I realized I wanted five or more cams the cost of MFD manufacturer branded models quickly became prohibitive. Fortunately I’d already de…