Hikvision IP Camera Integration

I struggled quite a bit to make a subset of my security cameras work with Home Assistant so I figured I’d share my findings as the posts I read were either incomplete or inaccurate for my use case.

All my cameras and my NVR (7732) are Hikvision so what I am writing may not apply to you if you have different hardware.

Below is the configuration that finally worked.

One might believe that stating username and password both separately and in the RTSP URL is redundant, however I have found that listing them separately is needed for the still image, while the RTSP URL needs the username and password as part of the URL.

    username: "username"
    password: "password"

In the configuration I pasted below, replace the NVR-IP with the IP of your NVR. This will be the same for all the cameras on your NVR.

still_image_url: http://NVR-IP...

The port used for the still picture is sequential starting from 65000. You will notice that each camera has a different port… 65001, 65002, 65003, etc. This is what determines the camera the still image is from. The 102 should be equivalent to Channel 1, Substream 2. It might be possible to change the substream to the main stream by using 1 (thus 101) but it is unnecessary as the image is just for the card so a larger image (8MP in my case) would just use more resources unnecessarily. Do not try to change the Channel number as done for the streams as it will not work (at least on a Hikvision 7732 NVR)

still_image_url: http://NVR-IP:65001/ISAPI/Streaming/channels/102/picture

For the stream RTSP URL, the format for the Hikvision NVR is as shown below. The port here stays the same. The default RTSP port is 554 so unless you changed it, leave it at 554. The channel number determines the Channel and the stream for each camera. In the example below, it is Channel 1, Stream 1. If you want a lower resolution stream to help with resources, you can use 102. The next camera is 201, and so on.

stream_source: rtsp://username:password@NVR-IP:554/Streaming/Channels/101

Even with all of this in the configuration, I was having issues with the still image showing up for some cameras and others not. Taking a step back, the username and password I used for this is an “Operator” level login, not an Administrator one. I have these logins set both in the NVR and the IP Cameras - all the same. For some reason, I had to go to the Security tab of all the IP Cameras that were refusing to give me a still image and re-save (writing the password in again) the Operator login password. Instantly the still image appeared on the dashboard. The confusing bit is that I am interfacing with the NVR and the password there is clearly correct as I use it in other applications and some of the cameras were working… Anyhow, pulling the still image per IP Camera appears to need the same credentials to be stored on the IP Camera itself… and even if they are (like my case), I had to refresh them (no idea why… maybe the password was not what I thought it was and never noticed given I switched to using an NVR).

I hope to save some people the grief and research I had to go through to get it working by detailing my observations. I’m not an expert in IP Cameras so take this with grain of salt.

#IP Camera Configuration
camera:
  - platform: generic
    name: Entrance Camera
    username: "username"
    password: "password"
    authentication: digest
    still_image_url: http://NVR-IP:65001/ISAPI/Streaming/channels/102/picture
    stream_source: rtsp://username:password@NVR-IP:554/Streaming/Channels/101

  - platform: generic
    name: Driveway West Camera
    username: "username"
    password: "password"
    authentication: digest
    still_image_url: http://NVR-IP:65002/ISAPI/Streaming/channels/102/picture
    stream_source: rtsp://username:password@NVR-IP:554/Streaming/Channels/201

  - platform: generic
    name: Driveway East Camera
    username: "username"
    password: "password"
    authentication: digest
    still_image_url: http://NVR-IP:65003/ISAPI/Streaming/channels/102/picture
    stream_source: rtsp://username:password@NVR-IP:554/Streaming/Channels/301
    
  - platform: generic
    name: Backyard Camera
    username: "username"
    password: "password"
    authentication: digest
    still_image_url: http://NVR-IP:65004/ISAPI/Streaming/channels/102/picture
    stream_source: rtsp://username:password@NVR-IP:554/Streaming/Channels/401
    
  - platform: generic
    name: Garage Camera
    username: "username"
    password: "password"
    authentication: digest
    still_image_url: http://NVR-IP:65005/ISAPI/Streaming/channels/102/picture
    stream_source: rtsp://username:password@NVR-IP:554/Streaming/Channels/501
3 Likes

I have found a similar problem with my DVR which is a Swann. I was receiving a

401 Unauthorised

Took me a long time to realise I had to put the username and pass in the URL for RTSP but for the still it accepted this:

username: user
password: pass

It’s strange because VLC player doesn’t need that to work.

Working Config:

- platform: generic
  still_image_url: http://cctv.lan:85/action/snapshot?channel=03
  stream_source: rtsp://myusername:[email protected]:554/ch03/0
  name: patio
  framerate: 3
  verify_ssl: false
  username: myusername
  password: mypass

@hotswapster - My latest configuration iteration is having the user and password in the RTSP URL of all my cameras (even though some did not work with a viewer login I created for this purpose and I had to use the admin login) and no user and password in the newer cameras for the still image URL. The only way I can explain this is that something changed in the newer cameras but what I don’t get is why that would matter since all the URLs point to the NVR and not the cameras directly.

Do your camera feeds choke (long lag to start, and then short amount of live feed, then frozen video for a bit, then back to live and so on)? I assume the RPI4 does not have the resources necessary to process 8MP camera feeds but before I start upgrading to a NUC I wanted to be sure that was the issue. Most of my devices have 4k screens so the 8MP feed is actually of benefit and the secondary streams are a pretty big step down.

I don’t have that issue. Also think about the network throughout. There are calculators for IP cameras and how much bandwidth you need.

My guess it is your RPI. I moved from that to a VM a long time ago and haven’t looked back. Although HASS runs on a Pi, if you have more than a simple setup, more processing power helps.

You’d don’t have to use a NUC. You can always use an old laptop or something lying around.

80 Zwave, 90 Zigbee, 20 LIFX, a variety of Wifi devices, and 10 8MP IP cameras integrated. Zwave tends to be slow and video streaming has hiccups, but for the rest the performance seems quite good. I guess I will only find out trying.

Zwave is slow anyway.

Do you have a normal computer you use? Just install in on there for a trail before spending money!

1 Like

I am guessing that anything with a CPU that has native decoding support for HEVC / H265 will likely work better. I don’t think the RPI4 cpu has it.

I’ve had my hikvision cameras working on for a while basically the same way as you but the only way I could add them is by using the sub streams URL and setting that to MJPEG.
Are you able to add the main stream as a camera entity ?

Just to chime in here…
even though I created an operator user on my NVR it did not propagate to the cameras and I had to go create that user for each camera…

@Symbiot78 Creating a user on the NVR will not, and should not, propagate to the individual cameras. What you should be doing is get the camera feeds from the NVR itself. Anyhow, if you want more granular control over the cameras such as rebooting them (i forget what is possible via HA) then you probably need to create the user on each camera and point to it directly. I opted for the safer approach of getting the feeds from the NVR so all my RTSP addresses point to the NVR. While I can’t recall the details, some Hikvision cameras behave differently from others (same brand, different models) which made it annoying to get them all to work. Part of the issue was substream and RTSP formatting differences and how the login/pwd needed to be specified for each camera. If I recall correctly, only the more recent cameras worked as I expected them to. I had to fiddle around with the YAML to get the older ones to work.

Edit: look into the new webrtc addon. I installed it but haven’t fully implemented it yet but it is supposedly much better than the traditional RTSP stream (all mine struggle to stream).

Good evening. Thanks a lot for your article.

I have a couple of questions could you answer?

  1. Tell me please, why do you need a non-moving image in the card, what does it do?
  2. Please tell me, have you decided to record video with sound from your Hikvision cameras?
  3. Please tell me how you solved the issue of sending video with sound to telegrams?
    Thank you.

Добрый вечер. Спасибо большое за вашу статью.

У меня есть пару вопросов вы могли бы ответить?

  1. Скажите пожалуйста, зачем вам не подвижное изображение в карточке, что оно делает?
  2. Скажите пожалуйста, вы решили для себя запись видео со звуком с ваших камер Hikvision?
  3. Скажите пожалуйста, как вы решили вопрос с отправкой видео со звуком в телеграмм?
    Спасибо.

@SergTokarev - Given the IP cameras are now configured via GUI and we now also have webRTC integration, I would say what I wrote above is obsolete. I would recommend exploring webRTC if you are looking at importing camera feeds into HA:

I do not record the cameras using HA. I have a dedicated NVR for that, but you could look into FRIGATE which I believe allows you to record video along with doing object detection.

Regarding Telegram… I don’t know as I do not use it.

Thanks a lot!
Your post did the trick to get my Hikvision NVR in HA :slight_smile:

1 Like