curl --request POST --url 'http://<user>:<password>@<doorbell_ip_address>/cgi-bin/audio.cgi?action=postAudio&httptype=singlepart&channel=1' --header 'content-length: 9999999' --header 'content-type: Audio/G.711A' --max-time 3 --data-binary @<output_name.al>
For anyone who is interested, here is my workflow. It's through Home Assistant so YMMV depending on your setup (I pieced a lot of this together from different posts on the forums).
- Disable the chime completely using the command: http://<doorbell_ip_address>/cgi-bin/configManager.cgi?action=setConfig&VideoTalkPhoneGeneral.RingFile=0
- Prep the audio file. I used Sox with the following command: sox -v 0.8 <input_name.ext> -r 8k -c1 <output_name.al>
- On Home Assistant, set up the Dahua Home Assistant integration and add the doorbell.
- When the doorbell button is pressed, an event is fired on the Home Assistant event bus. I have an automation looking for this event as a trigger:
- platform: event
event_type: dahua_event_received
event_data:
Action: Start
Code: CallNoAnswered - The Action of the automation is a "Call service" action type for a "Shell Command: doorbell_chime" service I created. Something like this would need to be added to the configuration.yaml file in HA first:
shell_command:
doorbell_chime: bash /config/shell/doorbell_chime.sh - To send the sound to the doorbell a curl POST request is needed, so the doorbell_chime.sh file contains the following code:
#!/bin/bash
curl --request POST --url 'http://<user>:<password>@<doorbell_ip_address>/cgi-bin/audio.cgi?action=postAudio&httptype=singlepart&channel=1' --header 'content-length: 9999999' --header 'content-type: Audio/G.711A' --max-time 3 --data-binary @<output_name.al>
I found that if you don't add --max-time #, the POST request never actually exits so you can't send another request; the --max-time exits it.