Hikvision IP Camera Integration

Edit: This thread is old and no longer accurate. While I cannot provide details, there is an integration for Hikvision cameras that may make things easier, however I simply used “Generic Camera” integration for all my HK cameras at first, then I adopted Scrypted to pull from the NVR and feed HA.

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

Hey Aruffell, I have a NVR with 4 IP cameras from hikvision… Can’t find exactly how to get the camera to display on HA. Any tips as of today? Thanks!

I read your article about camera and NVR integration. Question: if you put username and password into configuration.yaml, they are no longer well protected. How to avoid this?

If I include all these entries into the configuration file, do I need anything else?

@frjung - I would ignore the information on this thread as in HA terms it is ancient by now :). I added a note at the top to say so in order not to waste other people’s time. Your observation is correct, and I still see the password in clear in logs and/or other places I can’t recall at this time. I would create a local user account (one that cannot be used to log into the system from outside your network) for only HA and difficult password (random characters, and not shared with anything else) to minimize the risk, but I agree… HA should improve its handling of credentials. I am sure it is just a matter of time as some instances have already been improved.

Hi,
In my dashboard I have the following code to display the RTSP stream from a HIKVISION camera:

type: custom:webrtc-camera
rtsp://login:[email protected]:554/streaming/channels/101
ui: true
media: video

The image is not displayed (but it works with VLC)

@Stives25 The RTSP URL will vary if you are pointing to the camera directly or to an NVR. Also, there are multiple streams so changing 101 to 102, for example, should display a lower resolution stream that may work better if you have a 4K camera and running this on a RPI or similar low end hw.

I am no longer well versed on this as I moved to an i7 based PC running my HA a few years ago, and have also stopped using web2rtc. I am also in the process of converting from Hikvision to Unifi for my IP cameras and NVR. I surely overtaxed the system as I had all sorts of slowness and issues related to (9x 4K) camera feeds.

I am now using Scrypted (running in a VM) as it exposes all my Hikvision and Unifi cameras to Amazon so I can view them on any of my Echo Shows. I also automatically get the doorbell video when someone rings the bell without having to use a Ring doorbell (I use the Unifi G4 Doorbell).

Scrypted also rebroadcasts the video from the cameras so that all my devices can stream it from Scrypted instead of the NVR or IP Cameras to prevent all the streaming devices from exceeding the maximum throughput which I believe was quite low on my NVR (160Mbits or so?). Scrypted can do a ton more and I am still exploring it. Check it out…

1 Like

@Stives25 - Yes, I never understood why the secondary streams are SOOO bad compared to the main one unless they are trying to stay compatible with ancient systems, or something. I would love for the cameras to have 4K main stream and 1080 secondary stream at the very least.

As for your issue, are you saying that the video shows in VLC and HA, but the static image does not? Or that you can only view the feed/image in VLC and nothing in HA?

I don’t use static images.
With 101, the stream displays fine in VLC but not in HA. However, I have 4 other cameras (Mobotix and Axis) for which the RSTP stream is displayed correctly with the same type of code.

|Edit]
After updating the camera firmware, everything works normally. Thank you @aruffel for your help.