Frigate NVR Binding

I started working on a binding for the Frigate NVR software. I created a bridge for the server connection but events are send through MQTT. Is it possible to have the frigate bridge rely on another MQTT bridge. Right now I am created a separate MQTT client connection and I think it is causing issues. It throws exception when events are called and I think its related to MQTT and threading. Any advise would be appreciated.

Thanks,
Scott

Source Code:

1 Like

If you need a working example on how to connect to MQTT, and also how to do auto discovery from mqtt messages, then check out the ‘espmilighthub’ binding. To get a binding merged you will need to use the framework to connect to MQTT and not use paho or another external library to make the connection.

openhab-addons/bundles/org.openhab.binding.mqtt.espmilighthub at main · openhab/openhab-addons (github.com)

I looked at the ‘espmilighthub’ binding as an example. The problem I have is the MQTT messages do not specify the IP address of the Frigate Server. This is the reason I created a bridge for the user to setup the IP and port of the server.

Is your target device running an on-board MQTT broker? I recall some robot lawnmower or vacuum doing something like that.

Frigate can be configured to use any MQTT server. I personally use one MQTT server for all my stuff so it seems redundant to have multiple connections from different bindings. I did copy the the iRobot code that uses an onboard MQTT server, but I am having some threading issues I think and I was hoping there is a better way.

Alright, so the expected use would be -
User sets up an MQTT broker, if they haven’t already.
User connects NVR to broker as client.
User installs OH MQTT binding, connects it to broker as client with standard bridge Thing, if they haven’t already.

Your OH add-on is told (by configuring a Thing) or finds out (by subscribing to magic topic) about the NVR, and auto-creates suitable channels.

Sounds like you might look at MQTT Homie extension for an example.

Yes I understand more now why your asking this. You can normally have binding level config options, but your binding will show up as part of the MQTT binding, so you will need to create a new broker to have the options available for users to use. This will mean a second connection to the mqtt broker if you have one of each bridge type setup so the broker needs to allow multiple connections.

You can create extra mqtt bridges and 1 did exist until it was recently removed. You can see the source code that was removed here (click on the ‘files changed’ link):
[mqtt] Remove MQTT System Broker by jimtng · Pull Request #12157 · openhab/openhab-addons (github.com)

Your xml file would look something like this. NOTE that the bindingId is just mqtt and that when your jar is in the addons folder, you will click on the mqtt binding to add things to the inbox and your binding will not show up as a separate binding


<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="mqtt"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
	xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">

	<thing-type id="camera">
		<supported-bridge-type-refs>
			<bridge-type-ref id="frigateBroker"/>
		</supported-bridge-type-refs>

Also note that I list the supported-bridge-type-refs so the only one that the camera thing can use is the frigateBroker which you will need to define and create your own handler for, PLUS you will need to handle it in your handler factory. I have not created a MQTT bridge before but it should be the same, just you do it as if your mqtt and not your own binding.

  1. FrigateHandlerFactory needs to return TRUE when the framework asks via supportsThingType(ThingTypeUID thingTypeUID). All the handlerFactories get asked if they support the ‘frigateBroker’, you need to say TRUE.

  2. Once the framework gets a true on your handlerFactory, you need to implement createHandler(Thing thing) in your FrigateHandlerFactory to then create a handler for ‘frigateBroker’.

  3. Your XML file needs to define the frigateBroker.

  4. Another way is to scan all your site local internal IP’s and make a http request that only frigate would reply to. This code shows an example of this method but if someone does not use the default port for frigate this would not be useful


openhab-addons/IpObserverDiscoveryService.java at main · openhab/openhab-addons (github.com)