UniFi Protect expanded support for PTZ cameras

With the addition of the G5 PTZ camera, the UniFi Protect lineup now has two PTZ cameras including a much more affordable option. More Home Assistant users will need advanced PTZ functionality from this integration to fully integrate and automate these cameras.

This feature request is intended to collect input and hopefully upvotes to expand UniFi Protect integration support for PTZ cameras. Here is a list of functions that I’m requesting for consideration:

  • Action calls to pan, tilt, zoom to a preset
  • Buttons and actions for discrete pan, tilt, zoom commands which could be mapped to a UI if desired (e.g. pan 1 deg, zoom 1.1x, etc.)

Feel free to add anything else you want below and please remember to vote.

Would like to add:

  • toggle tracking on/off

Right now, if you move the camera manually, you have to re-enable tracking from the original viewer. Looking to automate it after a certain timeout.

1 Like

Here’s more:

  • toggle the integrated spotlight on/off (G5)

Hmm, there is a switch for that already (switch.<cameraname>_tracking_person) and it works as intended. If it is set to on, it moves the camera to “home” position and starts automatic tracking again.

Hi, i have posted in another thread (Unifiptotect G4 PTZ - #9 by ofer8). i am trying to work on adding goto preset select entity to ptz cameras and wonder if anyone trying to do the same. my code:
add ptz preset select to unifi camera · home-assistant/core@10e17c0 · GitHub.
the code is working but i have hard time to add tests on it since the dataclass is frozen and i can’t mock the functions.
Also I had to use nest_asyncio since get_ptz_presets, get_ptz_home and get_ptz_current are all async function that needs to be called from within a loop.
the code is working on my dev env and i can see all my presets and its updated when i move the camera to a preset inside and out homeassistant.
If someone have a better way to do this or any suggestions let me know.

2 Likes

On the G5 PTZ, toggling this doesn’t reset home position

Go to home for the G5 round be nice. Full PTZ and saved preset support could come too, but most important for me would be going home, and possibly knowing if you’re currently at home position

There is a GO home work-around, or at least what I’ve noticed. If you manually move the camera the person tracking disables, and this is exposed in HA. When person tracking is enabled, after a timeout the camera resets to the home position. I have an automation that if person tracking is disabled for 5 minute re-enable and it resets the camera

1 Like

Preset buttons in Home assistant would be great. I just set two g5 ptz up with camera cards in HA and I’d love to add some buttons to pan to presets and enable/disable person tracking.

I’d like to see the ability to switch the camera to a different preset location so the PTZ will move to that preset when activated. These PTZ cameras are far from amazing but if I can have HA see a change of status for another sensor and tell the PTZ to look where that sensor is then its better than what its doing currently.

3 Likes

For anyone that wants to setup a rest command to navigate to a ptz preset, here is a workaround until this is integrated natively.

rest_command:
  pan_camera_to_home:
    url: https://{CONSOLEIP}/proxy/protect/integration/v1/cameras/{cameraid}/ptz/goto/-1
    method: POST
    verify_ssl: false
    headers:
      X-API-KEY: "{APIKEY}"
      accept: "application/json"
  pan_camera_to_preset1:
    url: https://{CONSOLEIP}/proxy/protect/integration/v1/cameras/{cameraid}/ptz/goto/0
    method: POST
    verify_ssl: false
    headers:
      X-API-KEY: "{APIKEY}"
      accept: "application/json"

To get the id of your camera, just open the device in protect and look at the url.

To get the api key https://{CONSOLEIP}/protect/settings/control-plane/integrations

Found this out thanks to this post in the issue that is currently being worked on by several people here in this thread.

2 Likes

As I understand, you can only get the API key if using the cloud?

I was wrong - you can get the key even without using the cloud.

Thanks for this, saved me a bit of time. I now have home and side gate presets for my G5 PTZ that sit nicely alongside buttons for my security and patio lights. I also set up an automation so that if a PIR at the side gate detects motion it pans to it and then goes back to home after motion is cleared for 1 minute.

1 Like

This would be so good. I think in lieu of a patrol feature something basic like on alarm for glass break go to saved position, pause for x seconds if no human tracking go back to home position. Would be awesome.

That’s a beauty of a card. Nice layout at the bottom AND a tidy yard to boot! :slight_smile:

Thanks, it’s a picture elements card with button card and bubble card elements. The action buttons are bubble card sub-buttons.

type: picture-elements
camera_image: camera.back_door_low_resolution_channel
camera_view: live
elements:
  - type: custom:button-card
    style:
      top: 10%
      left: 92%
      width: 15%
    show_name: true
    show_state: false
    name: Live
    layout: icon_name
    icon: mdi:record
    styles:
      card:
        - border-radius: 24px
        - width: 100%
        - opacity: 0.6
      img_cell:
        - width: 40px
        - height: 20px
        - background: none
        - border-radius: 100%
      icon:
        - width: 20px
        - color: red
        - top: "-2px"
      name:
        - color: var(--primary--font-color)
        - font-size: 10px
        - justify-self: start
  - type: custom:mod-card
    style:
      top: 85%
      left: 50%
      width: 96%
    card_mod:
      style: |
        ha-card {
          border-radius: 36px;
          -webkit-backdrop-filter: blur(2px) !important;
          backdrop-filter: blur(2px) !important;
        }
    card:
      type: custom:bubble-card
      name: Back Door
      card_type: button
      button_type: state
      show_state: false
      entity: camera.back_door_high_resolution_channel
      force_icon: true
      show_attribute: true
      button_action:
        tap_action:
          action: none
      card_layout: normal
      sub_button:
        - icon: mdi:home
          action: perform-action
          perform_action: rest_command.pan_camera_to_home
          target: {}
          tap_action:
            action: perform-action
            perform_action: rest_command.pan_camera_to_home
            target: {}
        - icon: mdi:gate
          action: perform-action
          perform_action: rest_command.pan_camera_to_preset1
          target: {}
          tap_action:
            action: perform-action
            perform_action: rest_command.pan_camera_to_preset1
            target: {}
        - entity: light.big_security_light_switch_0
          icon: mdi:light-flood-down
          state_background: true
          light_background: true
          tap_action:
            action: toggle
            target:
              entity_id: light.big_security_light_switch_0
        - entity: light.back_door_floodlight_light_2
          icon: mdi:wall-sconce-flat
          state_background: true
          light_background: true
          tap_action:
            action: more-info
            target:
              entity_id: light.back_door_floodlight_light_2
        - entity: binary_sensor.back_garden_motion
          show_name: false
          show_state: false
          show_background: true
          state_background: true
          show_icon: true
      styles: |-
        .bubble-button-card {
          opacity: 1 !important;
          background: rgba(0,0,0,0) !important;
          -webkit-backdrop-filter: blur(2px) !important;
          backdrop-filter: blur(2px) !important;
        }
        .bubble-button-card-container {
          background-color: rgba(0,0,0,0) !important;
          -webkit-backdrop-filter: blur(2px) !important;
          backdrop-filter: blur(2px) !important;
          filter: blur(50%) !important;
        }

        .bubble-button-background {
          background-color: var(--card-background-color) !important;
          filter: blur(50%) !important;
        }

        .bubble-icon {
          color: black !important;
          opacity: 1 !important;
        }
        .bubble-icon-container {
          background-color: white !important;
        }
        .bubble-name {
          font-size: auto !important;
        }

        .bubble-sub-button-container {
          background: none !important;
        }
3 Likes

Home Assistant changed how they collect feature requests. Go here to vote on the updated version of this same request.

1 Like

What kind of card is that? I would love to have similar setting / overlay with buttons for lights and actions.