Dahua IP Cam screenshot

Hi,

I’m trying to pull a screenshot from my Dahua (IPC-HDW4431C-A-V2) but it seems not to work. I have another Hikvision cam and have no problem with screenshot

My automation.yaml with Dahua url looks like:

- alias: This is a test
  initial_state: 'on'
  hide_entity: True
  trigger:
    platform: state
    entity_id: binary_sensor.door_window_sensor_158d00014df82f
    to: 'on'
  action:
    - service: notify.Telegram
      data:
        title: 'Home Assistant'
        message: 'Test!'
        data:
          photo:
           -  url: http://user:[email protected]:8033/cgi-bin/snapshot.cgi
            caption: 'This is a test'

Port 8033 is not a default port for a Dahua camera.
I tried your link with my username password ip and port 80 and it works.

Did you also have to open port 80 on your router?
Could you share your working automation script? Thnx

alias: Notify IOS App
initial_state: true
hide_entity: false
trigger:

  • platform: state
    entity_id: switch.button_nr
    to: ‘on’
    action:
    service: notify.ios_iphone
    data:
    message: “message”
    data:
    attachment:
    url: http://username:password@ip:port/cgi-bin/snapshot.cgi
    content-type: jpg
    hide-thumbnail: false
1 Like

Unfortunately I still can’t pull a screenshot. I also opened port 80 but still nothing.

This does not look like a public ip but the ip from your local network. This will. To be able to see the image remotely, you need to be able to access that through an ip address or a dns name ( look at duckdns ).

You need to forward port X from the router to port 80 on the camera. Then set the url as

http://user:pass@<public_ip>:<port_x>/…

For example, I can externally access my camera port 80 through my public ip, port 64113 (random port chosen by me).

Depinding on the router / internet connection you might have to use port 80 or you can use any other port (one external port for every camera).

Hope this points you in the right direction.

I haven’t used this feature yet, so I’m not 100% sure if a public address is needed, the configuration says “url or file (Required): For local or remote path to an image.” so both might work.

I do use external port for Dahua and the camera can be reached outside my network. But I can’t pull a jpg. What notification platform do you guys use? And could you share a working script?

did you find how?

Add the camera as a generic IP cam:

- platform: generic
  name: Garage
  authentication: digest
  username: !secret ip_cam_user
  password: !secret ip_cam_pass
  still_image_url: !secret ip_cam_garage_snapshot_url

Then use the snapshot service in your automation to create a screenshot and then send that screenshot:

action:
  - service: camera.snapshot
    data_template:
      entity_id: camera.nwhouse
      filename: "/config/www/snapshots/nwhouse_cam_{{ trigger.to_state.last_changed }}.jpg"

  - service: notify.ios_my_iphone_app
    data_template:
      message: "NWHouse tripwire activated at {{now().strftime('%H:%M %d-%m-%y')}}"
      data:
        attachment:
          url: "http://IP_ADDRESS_OF_HOMEASSISTANT:8123/local/snapshots/nwhouse_cam_{{ trigger.to_state.last_changed|urlencode }}.jpg"
          content-type: jpeg
        entity_id: camera.nwhouse

I used your script but get an 404 error. Is there any other way to get a screenshot of Dahua?
Or is it becauseI use duckdns that cause the problem to get a local snapshot?

I don’t use DuckDNS, so I can’t help you there.

Ok, I managed to save the local snapshot but can’t attached it to (facebook) notification. Any help appreciated! This is how my automation script look like:

- alias: Test Automation
  initial_state: 'on'
  hide_entity: True
  trigger:
  - platform: state
    entity_id: binary_sensor.door_window_sensor_158d00014db7b2
    from: 'off'
    to: 'on'
  action:
    - service: camera.snapshot
      data_template:
        entity_id: camera.dahua_ipc
        filename: "/config/www/snapshots/camera.dahua_ipc{{ trigger.to_state.last_changed }}.jpg"
    - service: notify.facebook
      data:
        message: 'This is a test'
        data:
          attachment:
          type: 'image'
          payload: "https://ip:8123/config/www/snapshots/camera.dahua_ipc{{ trigger.to_state.last_changed|urlencode }}.jpg"
        target:
          - '+31xxxxxxxxxx'

what are you did here?
save the snapshots on your local and then send it via HA?

I don’t know if I understand your question but the screenshots are saved in /config/www/snapshots/ (you need to create a folder named snapshots or something).

But I still cannot get the screenshot with push notification. Maybe someone here has the solution?

Solved almost, it sent snapshot but did not send text message:

- alias: binary_sensor_garden_camera_photo
  initial_state: true
  hide_entity: false
  trigger:
    platform: state
    entity_id: binary_sensor.garden_camera
    to: 'on'
  condition:
    - condition: state
      entity_id: alarm_control_panel.home_alarm
      state: armed_home
  action:
    - service: camera.snapshot
      data:
        entity_id: camera.garden_camera
        filename: "/config/www/cam_captures/garden_{{ now ().year }}_{{ now ().month }}_{{ now ().day }}_{{ now ().hour }}_{{ now ().minute }}.jpg"
    - service: notify.telegram
      data:
        title: "Presence Detected at garden"
        message: "Motion in the garden!"
        data:
          photo: 
              file: "/config/www/cam_captures/garden_{{ now ().year }}_{{ now ().month }}_{{ now ().day }}_{{ now ().hour }}_{{ now ().minute }}.jpg"
              capture: snapshoot