Links on the site may earn us an affiliate commission. Learn more.

In this post, we’ll go over how to integrate Ubiquiti’s UniFi Protect with Home Assistant. So you can easily control different settings in your security cameras directly from your Home Assistant instance. On top of that, we’ll also go over a few useful automations that you can set up with this integration.

To manage the UniFi Protect cameras with Home Assistant, there is a custom integration available in HACS that you would need to install. If you haven’t installed HACS yet, you can find a tutorial on how to set it up here.

Set up a local account in UniFi

Before installing the integration, you need to set up a local account via the UniFi web interface. The local account will allow the custom integration to access and manage the settings for your UniFi security cameras.

Open the UniFi web interface and go to Manage Users and on the top right corner, click on Add User. On the pop-up that comes up, set the Role to Limited Admin and change the account type to Local user only. You can set the Name for this local account to Home Assistant and also add the Home Assistant logo as the profile image. Then set up a Username and Password. Under Application Permissions. Set the UniFi Protect option to Administrator. For all other options, you can change it from View only to None. After that, click on Save to create the new local account.

Enable RTSP in the UniFi cameras

You need to enable RTSP on the cameras you would like to access via Home Assistant. So on the top right corner of the web interface, click on the menu icon and click on Protect. In the UniFi Protect web interface, go to UniFi Devices. Click the camera you would like to access via Home Assistant, and then click on Settings. Under Real time streaming protocol, enable the streaming quality option that you would like to use.

Install the UniFi Protect integration

In Home Assistant, open HACS, go to Integrations, and click on Explore & add repositories. Search for UniFi Protect, open it, and then click on Install this repository in HACS. A pop-up comes up where you can choose the version you would like to install. Leave it set to the latest and then click on Install. After installing, you need to restart Home Assistant, but first, you need to check that the stream: option in Home Assistant is enabled. So, using the VS Code add-on, open the configuration.yaml file and check that the stream: option is there. If not, just add it and restart Home Assistant.

Configure the UniFi Protect integration

After installing the UniFi Protect integration via HACS, you need to configure the integration. So, return to the Configuration page and click on Integrations. Click on Add Integration, search for UniFi Protect, and click on it. A new pop-up comes up where you need to enter the UniFi Protect IP address and the username and password for the local account you created. Leave the other options set to default and then click on Submit. If the connection is successful, another pop-up comes up where you can assign your security cameras to specific areas. After that, click on Finish to complete the configuration.

If you click on Devices under the UniFi Protect integration, you can view the entities you can manage from Home Assistant. Then you can add the camera stream to the dashboard using the Picture entity card.

Automations

There are several automations that you can set up with the UniFi Protect integration. Below, we’ll go over a few simple but useful automations that are a must-have.

Send notification with an image when the doorbell is pressed

When using the UniFi Protect app, if someone rings the doorbell or motion is detected, you get a notification letting you know of the event. However, that notification doesn’t include an image of who is at the door. You have to actually click on the notification for the app to open and then see the camera feed. Now, with Home Assistant, we can create an automation that will send a notification with the alert and also include a snapshot of the camera feed.

In Home Assistant, go to ConfigurationAutomations, and then click on Add automation. On the pop-up that comes up, click on Start with an empty automation and set the automation as follow:

Name: Notify when doorbell is pressed

Triggers:
  Trigger type: Event
  Event type: unifiprotect_doorbell

Actions
  Action 1
    Action type: Call service
    Service: camera.snapshot
      Target:
        Pick entity: Doorbell entity
      Filename: /config/www/doorbell_image.jpg

  Action 2
    Action type: Call service
    Service: notify.mobile_app_[device_name] #Replace [device_name] with your device’s name
      Message: There is someone at the door
      Title: Doorbell pressed
      Data:
        image: /local/doorbell_image.jpg
        clickAction: app://com.ubnt.unifi.protect #Android only
        url: shortcuts://run-shortcut?name=[shortcut-name] #iOS Only. Replace [shortcut-name] with the shortcut name you create
        ttl: 0
        priority: high
        group: doorbell-pressed

The Filename under Action 1 saves the image with the name doorbell_image.jpg in the www folder, located in the Home Assistant config folder. Anytime the automation is triggered, it will save a snapshot from the doorbell camera in that folder. And it will overwrite any existing image with that same name.

Under Action 2 the clickAction is available for Android to open a specific app. In this case, the UniFi Protect app. However, for iOS, you need to use the iOS Shortcuts app and create a shortcut to open the Unifi Protect app and then at the url option instead.

The group option in Action 2 will keep several notifications with that same name together instead of showing several notifications separately.

Save the automation, and when you test it, you should get a notification from Home Assistant letting you know that someone is at the door, and it will also include an image from the doorbell.

Send notification alert when motion is detected

For this example, I’m going to do it for the doorbell. However, you can set up this same automation for any other UniFi camera. Add a new automation and set it as follow:

Name: Notify when motion detected by the door

Triggers:
  Trigger type: State
  Entity: Select camera entity
  From: off
  To: on

Actions
  Action 1
    Action type: Call service
    Service: camera.snapshot
      Target:
        Pick Entity: Camera entity
      Filename: /config/www/doorbell_motion_image.jpg

  Action 2
    Action type: Call service
    Service: notify.mobile_app_[device_name] #Replace [device_name] with your device’s name
      Message: There is motion detected by the front door
      Title: Motion detected
      Data:
        image: /local/doorbell_motion_image.jpg
        clickAction: app://com.ubnt.unifi.protect #Android only
        url: shortcuts://run-shortcut?name=[shortcut-name] #iOS Only. Replace [shortcut-name] with the shortcut name you create
        ttl: 0
        priority: high
        group: doorbell-motion

Save the automation, and when there is motion detected on the camera, you will receive a Home Assistant notification with the camera image.

Set up privacy mode toggle

The next automation that I want to show you is useful when you have cameras inside your home. If you want to have some privacy when you are home at any time, you can have a toggle to enable and disable the camera easily. The automation would set up a privacy zone blacking out the whole camera view and stop recording as well. Let me show you how to set it up.

Create Toggle (Input Boolean)

The first thing you want to do is create a toggle that will trigger the automation. So, in Home Assistant, go to ConfigurationHelpers, click on Add helper, and select the Toggle option to create an input boolean. Set up a name and an icon for this toggle, and then click on Create.

Add automation

In the Automation page, add a new automation and set it up as follow:

Name: [Camera-Location] Camera Privacy Mode #Change [Camera-Location] with the rooms name

Triggers
  Trigger 1
    Trigger type: State
    Entity: #Select the toggle (Input boolean) you created
    To: on

  Trigger 2
    Trigger type: State
    Entity: #Select the toggle (Input boolean) you created
    To: off

Actions
  Action type: Choose
    Option 1
    Conditions:
      Condition type: State
      Entity: #Select the toggle (Input boolean) you created
      State: on
    Actions:
      Action type: Call service
      Service: unifiprotect.set_privacy_mode
        Entity ID: #Select the camera entity
        Privacy mode: #Toggle on
        Recording mode: Never
    Option 2
    Conditions:
      Condition type: State
      Entity: #Select the toggle (Input boolean) you created
      State: off
    Actions:
      Action type: Call service
      Service: unifiprotect.set_privacy_mode
        Entity ID: #Select the camera entity
        Privacy mode: #Toggle off
        Recording mode: #Set to always or motion

Save the automation, and if you run a test, you can see that switching the toggle on sets the privacy zone to black out the whole camera view and turns off the recording as well. Then, when switching it off, it disables the privacy zone, and the camera starts recording again.

Disable doorbell chime

The last thing that I want to show you is to set up a switch to disable the doorbell chime at any time. This switch is super useful when you don’t want to be disturbed by someone ringing the doorbell. And it is definitely a must-have if you have a newborn. Let me show you how to set it up.

First of all, go to Developer ToolsStates, and search for the doorbell entity. In the Attributes section, there are two options, chime_enabled and chime_duration. By default, the chime_duration is set to 300 when the chime is enabled on the doorbell. Remember that number because when you set up the switch, the option to turn on the chime, you would need to set it to that specific number.

Next, to create a custom switch, access the Home Assistant config folder using the VS Code add-on. By default, you should have a file name switch.yaml. Then, inside the configuration file, you would have the option switch: !include switch.yaml, linking the switch.yaml file to the configuration file. I personally don’t like to have all my switched in one file. I rather have each switch in its own file to make things a little more organized. If you would like to do it this way as well, replace switch: !include switch.yaml with switch: !include_dir_list switches. Then, create a new folder named switches, and inside that folder, create a file name doorbell_chime.yaml. Inside that file, enter the following template:

# Doorbell Chime
platform: template
switches:
  doorbell_chime:
    friendly_name: Doorbell Chime
    icon_template: hass:bell-ring
    unique_id: “7cb02cef-fdae-4069-aaaf-0e3b8604aac9”
    value_template: "{{ is_state_attr('camera.doorbell', 'chime_enabled', true) }}"
    turn_on:
      service: unifiprotect.set_doorbell_chime_duration
      data:
        entity_id: camera.doorbell
        chime_duration: 300
    turn_off:
      service: unifiprotect.set_doorbell_chime_duration
      data:
        entity_id: camera.doorbell
        chime_duration: 0

To explain this template a little bit. The custom switch is set up with the name, Doorbell chime. It’s going to update the status of the chime by checking on the chime_enabled attribute on the doorbell entity. Then when the switch is turn on, it will run the service unifiprotect.set_doorbell_chime_duration and set it to 300. Then when the switch is turned off, it will run the same service, and it will set the chime duration to 0.

Save the new switch and then restart Home Assistant to apply the changes. When you test the new switch and turn it off, you’ll notice that the chime_enabled attribute changes to false and the chime_duration to 0. Then when you turn it back on, it will change the chime_enabled attribute to true and the chime_duration to 300.

Alright, so we integrated UniFi Protect with Home Assistant, and we went over a few useful automations. This integration definitely makes the experience with the UniFi Protect cameras a lot better than just using the UniFi Protect app.

Want to support my work?