Dahua camera presets how to?

Dahua PTZ is not so popular I guess :frowning:

How are you sending the URL presets from HomeAssistant?

I switch my Dahua cams between day and night mode using HomeAssistant. To do it, I set up command line switches that are triggered by sunset/sunrise. Below is one of my switches:

platform: command_line
  switches:
    garage_cam_mode:
      command_on: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=0"'
      command_off: 'curl --digest -u "USERNAME:PASSWORD" -g "http://IP_ADDRESS/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1"'

If you’re able to use the preset URLs via browser after confirming username/password, my guess is that your cameras require digest authorization and not just simple authorization. Try using the curl command above with your settings, and it should work.

1 Like

Thanks Johnnyletrois, I just found your other post with the digest included in the curl command.
If I run those from my Windows command prompt they work, so thats another step closer :slight_smile:

I really have no idea where i should put the curl command and how to trigger them.

Is it possible to make an selection from a input_select and start an automation based on the input?

My preset curl command:
curl --digest -u “admin:password” “http://ipaddress/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0

My input select:
input_select.dahua_ptz
options: Oprit,Voordeur,Tuin,Laagveen,Schoolsticht,Uitzicht
icon: mdi:cctv
friendly_name: Dahua SD6C225U-HNI Preset

Going to use the day and night mode commands for sunset/sunrise as well, thanks for sharing.

Got the presets working with a script activate button within HASS, no rocket since but took me some time.
Could not find the complete step to do it, so here is my config:

configuration.yaml
shell_command: !include includes/shell_command.yaml
script: !include_dir_merge_named includes/scripts

shell_command.yaml
dahua_preset_tuin: curl --digest -u “admin:password” “http://192.168.4.11/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=3&arg3=0

Scripts Folder
dahua_preset_oprit.yaml
dahua_preset_tuin.yaml
dahua_preset_voordeur.yaml

dahua_preset_oprit.yaml
dahua_preset_oprit:
sequence:
- service: shell_command.dahua_preset_oprit

Next is the Input Select, any tips are welcome :smiley:

1 Like

Camera Preset automation based on input select

automation_dahua_preset_input_select.yaml
alias: “Dahua Preset Input Select”
trigger:

  • platform: state
    entity_id: input_select.dahua_ptz
    action:
  • service: script.turn_on
    data_template:
    entity_id: >
    {% if is_state(‘input_select.dahua_ptz’, ‘Oprit’) %}script.dahua_preset_oprit
    {% elif is_state(‘input_select.dahua_ptz’, ‘Voordeur’) %}script.dahua_preset_voordeur
    {% elif is_state(‘input_select.dahua_ptz’, ‘Tuin’) %}script.dahua_preset_tuin
    {% endif %}
2 Likes

Done for today :smiley:

1 Like

Can you show image what you are add here?

Sorry for the late response, had home assistant running without changes for months.

The curl commands stopped working after updating HASS, I now got an error code 1 (Protocol Unknown) when the curl command is executed :frowning:

Removed all the subfolders from “C:\Users\username\AppData\Local\Programs\Python” and reinstalled HomeAssistant.

Everything is working again :sweat_smile:

1 Like

I do not understand what are you do here with the camera?

I can use the selection list to change the camera preset

@Sitnalta Thanks for your tips. Trying to implement this today but not having any luck with the command line stuff.

I have a command_line.yaml with the following:

preset_1_park: curl --digest -u “admin:password” “http://10.0.1.13/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=1&arg3=0
preset_2_pool_gate: curl --digest -u “admin:password” “http://10.0.1.13/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0
preset_3_beach_gate: curl --digest -u “admin:password” “http://10.0.1.13/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=3&arg3=0
preset_4_pool: curl --digest -u “admin:password” “http://10.0.1.13/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=4&arg3=0
preset_5_spa: curl --digest -u “admin:password” “http://10.0.1.13/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=5&arg3=0

However, when I go the the dev panel and run that service (without any additional json), the camera does not move. If I pop this in a URL though, the camera responds.

http://admin:[email protected]:80/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=5&arg3=0

image

Can you call your command line items straight from the dev panel? Of course, they aren’t working from the scripts either.

FYI, I’ve sent the commands using curl for Windows and they work so something up with Hassio?

Solved it. Was copying code above pasted without code blocks. Argh! That resulted in smart quotes. The correct code is below.

preset_3_beach_gate: 'curl --digest -u "admin:password" "http://10.0.1.13/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=3&arg3=0"'

That you can copy! Just change your username, password and IP address.

Sorry xbmcnut, I’m not to active on the HASS forum at the moment so I didn’t see your previous post.
I’m a beginner and I don’t know how to paste code the correct way on the forum.
And I don’t see the option to edit my previous posts.

But 3 days to find a solution isn’t that bad, It really cost me months to get it working like above.

Still don’t understand why Dahua isn’t supported like some other brands, they really make great products.

@Sitnalta Thanks for the reply, appreciate that. Agree, 3 days is quite good. Didn’t mean to have a dig, I should know better but to be honest, I never knew what smart quotes were before yesterday! I jumped on Discord, and someone much cleverer than me spotted it instantly. Working great now and all dropped inside one package so a little tidying to do and I’ll drop it on my gist.

Hello dude, are you still there ?
I try to do the same thing than you, is the switch supposed to be in the configuration file ?

Here is what I have :

switch:
  - platform: wake_on_lan
    mac: "04:11:76:da7:15:ab"
    name: PC-Bureau
    host: 192.168.1.69

  - platform: command_line
    switches:
      imou_cam_preset:
        hide_command: 'curl --digest -u "admin:password" -g "http://192.168.1.70/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0"'

but that doesn’t work, when I check the conf file I get this :

Testing configuration at /config
Failed config
  switch.command_line: 
    - Invalid config for [switch.command_line]: [hide_command] is an invalid option for [switch.command_line]. Check: switch.command_line->switches->imou_cam_preset->hide_command. (See ?, line ?). 
    - platform: command_line
      switches: [source /config/configuration.yaml:58]
        imou_cam_preset: [source /config/configuration.yaml:59]
          hide_command: curl --digest -u "admin:password" -g "http://192.168.1.70/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0"

Successful config (partial)

Thank you very much !

Look at post 3, 4 and 5, the complete config is there.
I don’t use the input select as in my previous image anymore but use a Picture Glance Card.

Knipsel

Picture Glance Card Configuration

aspect_ratio: 0%
camera_image: camera.dahua_sd6c225u_hni
camera_view: live
title: Dahua SD6C225U
type: picture-glance
hold_action:
  action: more-info
entities:
  - entity: switch.dahua_sd6c225u_night_mode
    icon: 'mdi:theme-light-dark'
  - entity: script.dahua_preset_oprit
    icon: 'mdi:car'
    tap_action:
      action: toggle
  - entity: script.dahua_preset_voordeur
    icon: 'mdi:door'
    tap_action:
      action: toggle
  - entity: script.dahua_preset_tuin
    icon: 'mdi:tree'
    tap_action:
      action: toggle

1 Like

I do not have Dahua camera but the information here was very helpful to create camera (simple IP camera “no-name”) movement controls. I have used browser to “spy” what commands are sent to camera when I press moment buttons and then put those in command line switches, example below:

command_on: 'curl -G "http://camera_ip/decoder_control.cgi?command=6&user=*******&pwd=********"'
command_off: 'curl -G "http://camera_ip/decoder_control.cgi?command=1&user=*******&pwd=*******"'

And it is working very well!

However I have one challenge. My switches are integrated into Picture Glance Card which looks like this, where I can see the switches
obraz
When I click on the image the picture gets bigger and the switches disappear:

.
Is there any way to keep switches available when clicking the camera picture?
Below is Picture Card Configuration:

camera_image: camera.kamera2o
entities:
  - entity: switch.kamera20_pan_h
    icon: 'mdi:arrow-left-right-bold-outline'
  - entity: switch.kamera20_left
    icon: 'mdi:menu-left-outline'
  - entity: switch.kamera20_right
    icon: 'mdi:menu-right-outline'
  - entity: switch.kamera20_up
    icon: 'mdi:menu-up-outline'
  - entity: switch.kamera20_down
    icon: 'mdi:menu-down-outline'
title: null
type: picture-glance
camera_view: live
tap_action:
  action: more-info
double_tap_action:
  action: url
  url_path: 'http://camera_ip/'

I have replaced real camera IP with the “camera_ip” and user & password with “*******” in my examples above.