Hikvision setup

This works for my 4 cameras using virtual host with the NVR

- platform: generic
  still_image_url: http://192.168.1.100:65002/ISAPI/Streaming/channels/1/picture  
  name: Driveway One
  username: hass
  password: !secret camera_nvr_password
  authentication: digest
- platform: generic
  still_image_url: http://192.168.1.100:65003/ISAPI/Streaming/channels/1/picture  
  name: Driveway Two
  username: hass
  password: !secret camera_nvr_password
  authentication: digest
- platform: generic
  still_image_url: http://192.168.1.100:65004/ISAPI/Streaming/channels/1/picture  
  name: Back Gate
  username: hass
  password: !secret camera_nvr_password
  authentication: digest
- platform: generic
  still_image_url: http://192.168.1.100:65005/ISAPI/Streaming/channels/1/picture  
  name: Side Yard
  username: hass
  password: !secret camera_nvr_password
  authentication: digest
3 Likes

perfect!! that did the trick, thanks.

Thnx ptdalen. do you use this in a push notification script with screenshot?

I use these cameras in a group that is visible in the front end. Pictures update every 5-10 seconds which works great for me. I also do send screen shots to push bullet using a pythons script, I use the line crossing sensor as a trigger.

So I have this in my binary_sensors.yaml file

 - platform: hikvision
   host: 192.168.1.100
   port: 65002
   ssl: False
   username: USERNAME
   password: !secret camera_nvr_password
 - platform: hikvision
   host: 192.168.1.100
   port: 65003
   ssl: False
   username: USERNAME
   password: !secret camera_nvr_password
 - platform: hikvision
   host: 192.168.1.100
   port: 65004
   ssl: False
   username: USERNAME
   password: !secret camera_nvr_password
 - platform: hikvision
   host: 192.168.1.100
   port: 65005
   ssl: False
   username: USERNAME
password: !secret camera_nvr_password

I have this in my configuration.yaml

switch:
  - platform: command_line
    switches:
      save_driveway1:
        command_on: "python /home/homeassistant/.homeassistant/scripts/driveway1.py"
        command_off: ""  
  - platform: command_line
    switches:
      save_driveway2:
        command_on: "python /home/homeassistant/.homeassistant/scripts/driveway2.py"
        command_off: ""
  - platform: command_line
    switches:
      save_backgate:
        command_on: "python /home/homeassistant/.homeassistant/scripts/backgate.py"
        command_off: ""
  - platform: command_line
    switches:
      save_sideyard:
        command_on: "python /home/homeassistant/.homeassistant/scripts/sideyard.py"
command_off: ""

Then these are the scripts

capture_driveway1_camera:
  alias: Capture Still Image from Driveway 1 Camera
  sequence:
    - service: switch.turn_on
      entity_id: switch.save_driveway1
    - service: switch.turn_off
      entity_id: switch.save_driveway1

capture_driveway2_camera:
  alias: Capture Still Image from Driveway 2 Camera
  sequence:
    - service: switch.turn_on
      entity_id: switch.save_driveway2
    - service: switch.turn_off
      entity_id: switch.save_driveway2

capture_backgate_camera:
  alias: Capture Still Image from Backgate Camera
  sequence:
    - service: switch.turn_on
      entity_id: switch.save_backgate
    - service: switch.turn_off
      entity_id: switch.save_backgate

capture_sideyard_camera:
  alias: Capture Still Image from Sideyard Camera
  sequence:
    - service: switch.turn_on
      entity_id: switch.save_sideyard
    - service: switch.turn_off
entity_id: switch.save_sideyard

Here is my automations, I have some conditions to reduce the alerts, these may need to be adjusted dependeding on your camera setup.

##########################################
## Camera Picture Alerts                ##
##########################################    
- alias: 'Cameras Drive Way 1 Picture'
  trigger:
  - platform: state
    entity_id: binary_sensor.driveway_1_line_crossing
    to: 'on'
  condition:
  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.cameras_drive_way_1_picture.attributes.last_triggered) | int > 60 }}'
  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.cameras_drive_way_2_picture.attributes.last_triggered) | int > 60 }}'
  action:
  - service: script.turn_on
    entity_id: script.capture_driveway1_camera
  - delay: '00:00:05'
  - service: notify.pushbullet_notifications
    data:
      message: Drive Way Line Crossing from 24th Street
      target:
      - !secret pauls_secret_email
      - !secret tracys_secret_email
      title: DRIVEWAY 1 NOTIFICATION
      data:
        file: "/tmp/driveway1.jpg"

- alias: 'Cameras Drive Way 2 Picture'
  trigger:
  - platform: state
    entity_id: binary_sensor.driveway_2_line_crossing
    to: 'on'
  condition:
  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.cameras_drive_way_2_picture.attributes.last_triggered) | int > 60 }}'
  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.cameras_drive_way_1_picture.attributes.last_triggered) | int > 60 }}'
  action:
  - service: script.turn_on
    entity_id: script.capture_driveway2_camera
  - delay: '00:00:02'
  - service: notify.pushbullet_notifications
    data:
      message: Drive Way Line Crossing from the Half Street
      target:
      - !secret pauls_secret_email
      - !secret tracys_secret_email
      title: DRIVEWAY 2 NOTIFICATION
      data:
        file: "/tmp/driveway2.jpg"

- alias: 'Cameras Back Gate Picture'
  trigger:
  - platform: state
    entity_id: binary_sensor.backyard_line_crossing
    to: 'on'    
  condition:
  - condition: state
# Back Door Open Close Sensor
    entity_id: binary_sensor.open_close_sensor_back_door
    state: 'off'
    for:
      minutes: 2
  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.cameras_back_gate_picture.attributes.last_triggered) | int > 60 }}'      
  action:
  - service: script.turn_on
    entity_id: script.capture_backgate_camera
  - delay: '00:00:02'
  - service: notify.pushbullet_notifications
    data:
      message: Backgate Line Crossing
      target:
      - !secret pauls_secret_email
      - !secret tracys_secret_email      
      title: BACKGATE NOTIFICATION
      data:
        file: "/tmp/backgate.jpg"

- alias: 'Camera Side Yard Picture'
  trigger:
  - platform: state
    entity_id: binary_sensor.sideyard_line_crossing
    to: 'on'
  condition:
  - condition: template
    value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.cameras_side_yard_picture.attributes.last_triggered) | int > 60 }}'
  action:
  - service: script.turn_on
    entity_id: script.capture_sideyard_camera
  - delay: '00:00:02'
  - service: notify.pushbullet_notifications
    data:
      message: Sideyard Line Crossing
      target:
      - !secret pauls_secret_email
      - !secret tracys_secret_email      
      title: SIDEYARD NOTIFICATION
      data:
        file: "/tmp/sideyard.jpg"

I dont have access to the python script at the moment, but its in one of the posts in the community. Also i set this up when I first got started with HA, its possible (even likely), this could be simplified.

Hope this helps

4 Likes

Here is an example of my python script. I have 4 one for each camera

import urllib
urllib.urlretrieve("http://username:[email protected]:65004/ISAPI/Streaming/channels/103/picture", "/tmp/backgate.jpg")

I did have them all in one script but found that it took a couple seconds to capture the images, and only needed a new image if there was a reason, so I broke it up

this is great thanks! this is a great start. now i just need to get my denon heos working and i can migrate off of domoticz.

ptdalen, did you by chance have any dome cameras that were 720p? My 4MP turrets show up fine but the older domes donā€™t work. wonder if it requires 16:9 aspect ratio?

Mine are all bullet cameras. I think 2mp. 1920x1080

Sorry for resurrecting this threadā€¦ Iā€™m trying to get the Motion switch (components/switch/hikvisioncam.py) going.

However, I seem on getting a 401 error, even when Iā€™m using the same admin username and password that I log in (and configured for the binary sensor). When I tested the same URL (http:///MotionDetection/1// in Postman with basic authentication, it fails as well (also a 401 error).

But if I do it from a browser where Iā€™ve already logged in, I get the XML config for motion control back fine without an error.

1 Like

Anyone notice these sensors not accurately reporting? Like I have multiple motion events recorded locally but HA motion sensor reports last motion event over 12 hours ago??

I am getting motion events on my motion sensor, just not as frequently as I am getting actual motion recordings?

Thanks in advance

Iā€™ve had issues from time to time where the sensors seem to stop reporting. If I restart HA everything seems to start working again. I have not troubleshot much further, but the other day when it happened i was able to trace it back to a power outage I had in my house earlier. I believe that my HA instance came back up before my Cameras.

Iā€™ve got the same issue :sleepy:
Sometimes itā€™s also stuck in ā€œDetectedā€ until I restart HAss

My icons donā€™t appear to change color during state changes either.

I have this issue, rarely reports any detection at all in HA

I am still testing, and not 100% positive, but it appears as if the Home Assistant threshold for motion is higher than the Hikvision threshold to record. I played with one of my motion zones today. I raised the sensitivity and lowered the percentage until the home assistant sensor tripped consistently. I then went back and noticed that there were recordings the entire time I was testing.

I understand this doesnā€™t make sense with the way the sensor is designed though.

I will say, I found motion alerts just way to finickey (even on the camera). I mostly use line crossing alerts, or a combination of line crossing and motion (via automation). Line crossing seems very accurate. I still get false positives, but much less often. One automation I do, is I only trigger on motion, if there was a line crossing, I then out the line crossing a bit away from the motion area. That works pretty well for me.

1 Like

How are you using line crossing and motion in your automations?

Is it possible to see the data stream from the Hikvision camera to Hass, in order to troubleshoot this ?

Hi
I add to my home assistant config this:

Then i add to lovelace card:

type: picture-glance
title: Camera 01
entities: []
camera_image: camera.camera_01

But i still not see image video from camera. STill see gray image:

What i done wrongā€¦ ?

When open in web browser this link (login and pass) http://192.168.xx.xx/ISAPI/Streaming/channels/1/picture
i see image from camera ok.

EDIT
I found a bug. Change value in secret to other and works.

Also add binary sensor like this:

  • platform: hikvision
    host: 192.168.xx.xx
    port: 80
    username: !secret user_hikvision
    password: !secret pass_hikvision

This works but in Home assistant still show as detect motion. But camera no detect motion:

Why ? After restart HA show OFF and when before camera i run motion again still ONā€¦ and not change to OFF.
I use camera Hikvision DS-2CD2063G0-I with latest firmware 5.5.82

I can not get my Hikvision DS-2CD2355FWD-I camera to show up in HA.

This URL works in a web browser:

http://10.1.1.22/ISAPI/Streaming/channels/101/picture

But the generic camera config using this URL it never shows anything:

- platform: generic
  name: Downstairs
  username: !secret camera_user2
  password: !secret camera_password
  still_image_url: http://10.1.1.22/ISAPI/Streaming/channels/101/picture

I also tried:

- platform: generic
  name: Rumpus Room GENERIC
  still_image_url: http://USER:[email protected]/ISAPI/Streaming/channels/101/picture"

Iā€™ve tried with and without user & password as the web browser does not require authentication (bad!).

I also tried an rstp stream:

- platform: ffmpeg
  name: Downstairs
  input: rtsp://USER:PASSWORD%[email protected]/Streaming/Channels/101

I can open this stream in VLC fine but HA does not show anything (yes I did set up the ffmpeg component).

Any ideas?