Hikvision Camera Auto Privacy

My family has gotten on board with the idea of indoor cameras in common areas for checking in on the dogs, the kids in other parts of the house, or exception situations (alarms, etc…), but none of us really care for the cameras recording us 24/7.

We considered a few different options:

  • Just live with them on all the time
  • Pan/Tilt cameras that would point away from the main part of the room when “disabled” (2 of the Amcrest ones we used ended up dying after a year and a half or so of this usage)
  • Automate the camera’s power via API calls to their switches to turn PoE on/off (requires waiting for camera to boot up when we want to view something)

We found a decent compromise in the end - automate the application and removal of a full screen privacy mask.

I added a helper toggle that causes an automation to either enable/disable privacy on the cameras via a
rest_command service call. This lets us view the state of the camera privacy on our phones and trigger a notification to go off to everyone that is home if the privacy state changes manually.

To create and enable the mask, this API call to the Hikvision cameras has seemed to work universally. I’m not sure I fully understand the coordinates that get used (x=700 seemed to cause a thing visible line on the video), but this creates a full-screen blacked out image (this also disables motion recording since it senses no motion through the privacy mask)

rest_command:
  hik_privacy_enable_kitchen:
    url: http://192.168.xx.yy/ISAPI/System/Video/inputs/channels/1/privacyMask/
    method: PUT
    headers:
      authorization: "Basic AUTH STRING"
    payload: >
      <PrivacyMask><enabled>true</enabled>
      <normalizedScreenSize><normalizedScreenWidth>700</normalizedScreenWidth>
      <normalizedScreenHeight>480</normalizedScreenHeight></normalizedScreenSize>
      <PrivacyMaskRegionList>
      <PrivacyMaskRegion xmlns="">
      <id>1</id>
      <enabled>true</enabled>
      <RegionCoordinatesList>
        <RegionCoordinates><positionX>0</positionX><positionY>0</positionY></RegionCoordinates>
        <RegionCoordinates><positionX>704</positionX><positionY>0</positionY></RegionCoordinates>
        <RegionCoordinates><positionX>704</positionX><positionY>480</positionY></RegionCoordinates>
        <RegionCoordinates><positionX>0</positionX><positionY>480</positionY></RegionCoordinates>
      </RegionCoordinatesList>
      </PrivacyMaskRegion>
      </PrivacyMaskRegionList>
      </PrivacyMask>

And similarly, to disable, this API call:

rest_command:
  hik_privacy_disable_kitchen:
    url: http://192.168.xx.yy/ISAPI/System/Video/inputs/channels/1/privacyMask/
    method: PUT
    headers:
      authorization: "Basic <AUTH STRING>"
    payload: "<PrivacyMask><enabled>false</enabled></PrivacyMask>"

I created these for each interior camera and then made a script for globally enabling/disabling the privacy masks. The scripts just call the RESTful commands.

Next, I added an automation to map the toggle helper to the scripts and provide notifications if applicable. The automation is triggered anytime the camera privacy toggle changes.

alias: Camera Privacy Control
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.camera_privacy
    id: trigger
condition: []
action:
  - if:
      - condition: state
        entity_id: input_boolean.camera_privacy
        state: "on"
    then:
      - service: script.home_indoor_cameras_privacy_on
        continue_on_error: true
        metadata: {}
        data: {}
    else:
      - service: script.home_indoor_cameras_privacy_off
        continue_on_error: true
        data: {}
      - if:
          - condition: template
            value_template: "{{ trigger.to_state.context.user_id != none }}"
        then:
          - service: script.notify_users_at_home
            metadata: {}
            data:
              message: Indoor camera privacy has been disabled.
mode: single

The value template that controls whether a notification is sent (trigger.to_state.context.user_id != none }}" checks if the toggle helper was triggered by an automation or by someone in the UI and only notifies if it was from the UI, this way we don’t get notifications when the cameras come on upon triggering our away automations, etc…

The script referenced script.notify_users_at_home just handles checking to see who is listed as home and sends the notificationt to them.

image

I’ve had this set up for a couple of weeks now and it’s worked out really well for us. I hadn’t seen this solution posted before, so wanted to share in case it was helpful to anyone else.

2 Likes

Clever solution! I just pan the cameras to the ceiling or a wall behind them when certain conditions occur that require privacy (i.e., guest mode pans all cameras that might be invasive).

Get cheap dedicated poe switch for indoor cams and Just add smart switch to AC input if poe switch.

That’s exactly what I do, I have a smart switch connected to my camera PoE hub and restart it daily in case there are PoE issues, which about 10% of the time there are and a reboot clears it up.