Doorbell with media player function

I’m looking for a doorbell that allows me to send media/TTS to the built in speaker so, for example, I can send a canned to the doorbell response asking them to leave the package from a push notification if I see a delivery driver at the door.

So far I’ve only seen the UniFi doorbells/cameras support this. Are there any others?

I’ve made a shell script that can do this on the AD410 Amcrest that I can call from HA. Works okay.

#!/bin/bash
TEXT="$1"
LOG=ttslog
LOG=/config/ttslog
echo "TEXT: $TEXT" > $LOG

FILE=`curl -v -X POST \
 -H "Authorization: Bearer xxxxxxx" \
 -H "Content-Type: application/json" \
 -d "{\"message\": \"$TEXT\", \"platform\": \"google_cloud\"}" \
 https://ha.xxxx.xxxx:18123/api/tts_get_url | awk -F/ '{print $6}' |awk -F\" '{print $1}'` >> $LOG 2>&1
echo CURLRC=$? >> $LOG

echo
echo FILE:$FILE >> $LOG
echo
ffmpeg -y -i "/config/tts/$FILE" -c:a pcm_alaw -ac 1 -ar 8000 -sample_fmt s16 /config/audio_test.al >> $LOG 2>&1
echo FFMPEGRC=$? >> $LOG
echo

#  --digest 
curl -vvv --user 'admin:xxxxxxV' \
  --limit-rate 8K \
  --expect100-timeout 3 \
  --connect-timeout 5 \
  --no-keepalive \
  --max-time 7 \
  -F "file=@/config/audio_test.al;type=Audio/G.711A" \
  -H "Content-Type: Audio/G.711A" \
  -H "content-length: 9999999" \
  "http://10.100.1.143/cgi-bin/audio.cgi?action=postAudio&httptype=singlepart&channel=1" >> $LOG 2>&1
echo DOORRC=$? >> $LOG
exit 0
shell_command:
  doorbelltts: >-
    /config/ttsplay "{{ states('input_text.tts_door_text') }}"

It would be easier if the gstreamer integration was available in HA.

2 Likes

That plays audio on the doorbell?

Yes. I set the content of an input text and it will play it. It’s hacky but it works. If HA ever fixes gstreamer, it would work easier than doing it like this.

In theory, you can play any mp3 audio if you modify the script to convert it using ffmpeg to the right input codec like above. I will say that I don’t believe the length of the audio can be very long… YMMV

1 Like

I finally got the script to run with no errors on my setup, but the doorbell keeps returning the following:

  • We are completely uploaded and fine

100 9695 0 0 100 9695 0 8183 0:00:01 0:00:01 --:–:-- 8188* Empty reply from server

100 9695 0 0 100 9695 0 8180 0:00:01 0:00:01 --:–:-- 8188

  • Closing connection 0
    curl: (52) Empty reply from server

Any idea why I keep getting an empty reply from the server?

It must have been something to do with the vlan settings, but it is working now. I still get curl: (28) Operation timed out, but the sound does play on the doorbell.

Can you run through where to set this script up in HA?
I’ve set the script config for my own situation

I had to chmod 777 the bash script, change the platform to “google_translate” and use my local http://local-ip:8123 to get it to work.

Appreciate it, this was a life saver!

Put it in the config folder.

Yes it needs to be executable

chmod +x script

But both platforms should work fine. I use this linear16 encoding where the default is mp3. Don’t know if this matters

tts:
  - platform: google_cloud
    key_file: google-cloud.json
    language: en-US
    gender: male
    voice: en-US-Wavenet-F
    encoding: linear16
    speed: 1.1
    gain: -1.0
    text_type: ssml
    profiles:
      - telephony-class-application
      - wearable-class-device
    time_memory: 57600

You only need to use the local url if your network doesn’t do nat loopback (nat hairpin).

I have managed to get it working on an Amcrest AD110. However, I have some problems.

If the message is very short, everything works fine. But if the message is longer, only the last few seconds (2-3s) are played.

Did you have the same issue? Perhaps its AD110 related…

I think these messages need to be shorter… You could try to adjust the timeouts. You’ll see that I have the expect100 timeout pretty low and the maxtime at 7. Try increasing them a bit and see how you fair.

This is a bit beyond my league. Could you help me out with the following: I want to play a Halloween sound instead of the normal chime from the doorbell. How would I do that? And how do I use such a bash script?

I guess a bash script (.sh?) with the digest part of your script (and hardcoded mp3 location) which runs through a shell command? And what codec/filetype should I use then?