Running Custom Audio through a Dahua POE IP Doorbell Camera Using Home Assistant

Introduction

I have a Dahua VTO2111D-P-S2 IP doorbell camera which in general is a good video intercom/doorbell for remote communication. However, I have a fenced in house and since I can see through the camera and have an ability to unlock the gate with it. My premise is that sometimes guests would ring the doorbell, I will see them on the video feed and just press the unlock gate automation to unlock the gate. Many time the guests would not hear the gate lock click and would not understand that they are able to enter. So I wanted to find a way to play a custom audio files to this doorbell to enhance its functionality and be able to inform the guests. By utilizing the Dahua Web Service 2.0 interface and integrating it with Home Assistant, it is possible to push custom audio files to your VTO device.

This blog post will guide you through the process of configuring the Dahua VTO doorbell to play custom audio files, using a shell command in Home Assistant. I will also provide the necessary details to help you test this configuration.

Method 1: Adding Custom Audio Files to the Dahua VTO Doorbell

Dahua’s Web Service 2.0 allows you to interact with their devices via a web interface. This includes the capability to upload and play custom audio files. You can access the Dahua VTO2111D-P-S2’s web interface and upload an audio file directly.

Limitations to Note:

  • Only .mp3 files are supported.
  • Files limited to 20kb size.
  • There is some stutter when playing the audio file. This could be due to network connection or that the doorbell is actively ringing at the time of playing.

Dahua Web Interface Documentation:

For detailed steps on how to navigate and upload files through the web interface, refer to the Dahua Web Service 2.0 documentation: Dahua Web 2.0 Documentation. In general you just have to have the initial setup done for your doorbell and have access to the web interface. Then you can navigate to the settings and have the ability to upload custom .mp3 files. You select the function as in Audio types. To what function you want the doorbell to play the audio file. The file size limit is rather small 20kb. So only short messages can be played. You can record your own or find a suitable pre-recorded message online to use. If the file exceeds the limit you can use any free tools available on the web to compress it. For example FreeConvert

You can then navigate to the Security tab and make sure the specified sound prompt is enabled. In thhis case Unlock should be set to Enable in the Audio Control tab.

That should be it. You can for example use the DMSS app to trigger the unlock function and it should play the sound that was uploaded. This does not require any additional software/hardware but is limited in some ways.

Method 2: Setting Up Home Assistant for Audio Control

To automate the process of playing custom audio through the VTO, we’ll configure Home Assistant to send an audio file to the doorbell using the shell_command feature. This involves creating a pre-recorded audio file stored in Home Assistant, and writing a shell script that sends the audio to the Dahua VTO via a curl command. What I would suggest if using this method would be to set up the doorbell via the custom component for Dahua here. The integration also has a list of supported devices which you can check out and figure out the best choice.
The found method for this was through the mentioned integrations issue discussion found here. This uses a curl command to send the audio file to the doorbell, this has more finer control as you can configure this to be anything and not tied to a specific event. Since you are using home assistant you could have different voice message based on the time of day, action performed etc. You could even leverage AI TTS generation for on the fly audio files. But this is beyond the scope of this guide.

Convert your sound file

The curl commands used to transfer and play audio works with the .al sound files. So this uses the G.711A codec to have appropriate format files that the doorbell can play. This is discussed in more detail which I found through the GitHub discussions here. As described you can format your sound files locally using tools like SoX or FFmpeg. Or use an online file converter service like this one.

Home Assistant Configuration (configuration.yaml)

In your Home Assistant configuration.yaml file, add the following configuration for the shell command:

shell_command:
  varteliai: /bin/bash /config/www/script.sh

As per usual any changes to the configuration.yaml file require a restart of home assistant to take effect.

This command will trigger the script located in the /config/www/ folder, which contains the curl command that uploads and plays the audio file. Usually the /confg/www folder is easily accessible for home assistant to pull files from. So for this reason I suggest for initial testing to store them here, once you have everything working you can move them to a more preferable/secure location.

Shell Script (script.sh)

Here’s a basic example of the shell script (script.sh) that will be triggered:

#!/bin/bash
TEXT="$1"
curl -vvv --user 'user:password' --limit-rate 8K --expect100-timeout 3 --connect-timeout 5 --no-keepalive --max-time 7 -F "file=varteliai.al;type=Audio/G.711A" -H "Content-Type: Audio/G.711A" -H "content-length: 9999999" "http://your-dahua-ip/cgi-bin/audio.cgi?action=postAudio&httptype=singlepart&channel=1"

Explanation of the Curl Command:

  • --user 'username:password': This sets the basic authentication with the Dahua VTO. Be sure to replace username and password with your actual credentials.
  • --limit-rate 8K: Limits the upload speed to prevent overloading the VTO.
  • file=@/config/www/varteliai.al;type=Audio/G.711A: This points to the location of the audio file (replace with your file’s location), ensuring the audio format is set to G.711A.
  • "http://your-dahua-ip/cgi-bin/audio.cgi?action=postAudio&httptype=singlepart&channel=1": Replace your-dahua-ip with the actual IP address of your Dahua VTO device.

Testing and Integrating the Shell Command in Home Assistant

Once the shell command and script are configured, you can test the setup:

  • Developer Tools – Services: You can manually execute the shell command via Home Assistant’s Developer Tools by selecting the shell_command.varteliai service. This is a great way to ensure your command is working as expected.
  • Testing Outside Home Assistant: Before setting up the full automation, test the curl command in a terminal or compatible environment (e.g., on a Raspberry Pi or other Linux environments).

If everything is configured and functioning correctly you should hear the sound being played from the doorbell.

Relevant Documentation:

Automating the Process

Once you’ve confirmed that the audio file plays successfully via the shell command, you can create an automation in Home Assistant to trigger the shell command based on specific conditions, such as when someone rings the doorbell or a motion sensor is activated. In this case if you have the Dahua integration configured you can monitor the doorbell state when the button is pressed to do some form of action.

For example:

automation:
  - alias: Play Custom Audio on Doorbell Ring
    trigger:
      platform: state
      entity_id: binary_sensor.doorbell
      to: 'on'
    action:
      service: shell_command.varteliai
      data:
        message: "Your custom audio file"

This automation ensures that the shell command is triggered, sending the audio file to the Dahua VTO when the doorbell rings.

Alternative via AppDaemon

Home Assistant has a community add-on called AppDaemon which allows to run a sand-boxed python based instance. If you for example prefer to run scripts via the python environment and not shell scripts. AppDaemon could have the functionality you need if you prefer that. But this will perhaps be detailed in a separate post for leveraging it.

Conclusion

Integrating custom audio into your Dahua POE IP doorbell using Home Assistant can elevate your home automation setup, making it more personalized and functional. With the help of Dahua’s Web Service 2.0 and Home Assistant’s shell command feature, you can seamlessly trigger audio files to play under certain conditions.

By following the steps in this guide, you’ll have a fully functional system to play custom audio on your Dahua doorbell. Make sure to customize the scripts and configurations as per your environment and requirements.

Summary

  • You can upload custom audio files to your Dahue via its web interface.
  • Using Home Assistant and a shell command, you can automate the process of playing custom audio on the doorbell.
  • A combination of curl command and shell scripting allows you to easily send audio files to the Dahua VTO.
  • You can test and automate the shell command in Home Assistant’s developer tools and through automations.

Helpful Documentation:

This integration opens up more possibilities for creative automations and enhances your home automation setup.

As always I hope this has helped you out.

Share

Antanaitis

I always wanted to somehow document my work and ideas. I'm finally writing something.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *