One of the hardest part of being a parent is keeping a constant eye on the baby to make sure that the baby is doing well. Thus, it is not surprising that baby monitors are one of the fastest growing baby product category. However, many of the baby monitors available on the market are rather dumb and expect the parents to keep looking at the video stream or listen to the audio. This how-to will help you create a smart baby monitor on a budget and integrate it with Home Assitant. Instead of relying on the poor quality baby monitor speakers, we use our existing speakers (eg. Sonos). We can also send notifications (with pictures) to avoid constant monitoring of the feed.
Obviously, you can use the setup as a general purpose surveillance system to monitor noise in the whole house.
We need an IP camera that can capture sound in the baby’s room. It is also possible to use a Raspberry Pi with a microphone and send the audio to Home Assistant with
ffmpeg -f alsa -i hw:1,0 -vn -f rtp rtp://18.104.22.168:2000 over multicast. We can set the
input option on the Home Assistant side to
rtp://22.214.171.124:2000 in the same network.
Next, we attach a
ffmpeg_noise binary sensor to our IP camera. The sensor has an output
option that allows us to send the output to an icecast2 server for playing over speakers integrated with Home Assistant. We can use the binary sensor in our automation. You can ignore the icecast2 setup if you don’t want to play the audio after the noise sensor trigger.
We change the platform name for binary sensor in 0.38 from
ffmpeg_noise. Also all service going to component and was rename from
$ sudo echo "deb http://ftp.debian.org/debian jessie-backports main" >> /etc/apt/sources.list $ sudo apt-get update $ sudo apt-get -t jessie-backports install ffmpeg $ sudo apt-get install icecast2
We setup a icecast mount point for our babyphone and update
<mount> <mount-name>/babyphone.mp3</mount-name> <stream-name>Babyphone</stream-name> <username>stream_user</username> <password>stream_pw</password> </mount>
Now we can add the noise sensor to Home Assistant. We lower the sensitivity of the sensor (so that you are not inundated with notifications for every cough of the baby) to 2 seconds using the
duration option. The sensor should wait 60 seconds before restoring and it prevent us that a wine break will triggering a new alarm.
We can optimize the audio stream for human voice by using a highpass filter with 300 Hz and a lowpass filter with 2500 Hz. This filters out all non-human sounds such as background noise. We can even add a volume amplifier if the microphone volume is too low (you can remove it from
extra_arguments). For icecast2 we convert the audio stream to mp3 with samplerate of 16000 (which is the minimum for Sonos speakers). We use
peak to set the threshold for noise detection, where 0 dB is very loud and -100 dB is low.
binary_sensor: - platform: ffmpeg_noise input: rtsp://user:[email protected]_input/video extra_arguments: -filter:a highpass=f=300,lowpass=f=2500,volume=volume=2 -codec:a libmp3lame -ar 16000 output: -f mp3 icecast://stream_user:[email protected]:8000/babyphone.mp3 initial_state: false duration: 2 reset: 60 peak: -32
We use the option
initial_state to prevent the FFmpeg process from starting with Home Assistant and only start it when needed. We use an
input_boolean to control the state of FFmpeg services using the following automation.
input_boolean: babyphone: name: babyphone initial: off automation: - alias: 'Babyphone on' trigger: platform: state entity_id: input_boolean.babyphone from: 'off' to: 'on' action: service: ffmpeg.start entity_id: binary_sensor.ffmpeg_noise - alias: 'Babyphone off' trigger: platform: state entity_id: input_boolean.babyphone from: 'on' to: 'off' action: service: ffmpeg.stop entity_id: binary_sensor.ffmpeg_noise
Now we can make a lot stuff. Here is a simple example of an automation what should be possible with Sonos speakers.
automation: - alias: 'Babyphone alarm on' trigger: platform: state entity_id: binary_sensor.ffmpeg_noise from: 'off' to: 'on' action: - service: media_player.sonos_snapshot entity_id: media_player.bedroom - service: media_player.sonos_unjoin entity_id: media_player.bedroom - service: media_player.volume_set entity_id: media_player.bedroom data: volume_level: 0.4 - service: media_player.play_media entity_id: media_player.bedroom data: media_content_type: 'music' media_content_id: http://my_ip_icecast:8000/babyphone.mp3 - service: light.turn_on: entity_id: - light.floor - light.bedroom data: brightness: 150 - alias: 'Babyphone alarm off' trigger: platform: state entity_id: binary_sensor.ffmpeg_noise from: 'on' to: 'off' action: - service: media_player.sonos_restore entity_id: media_player.bedroom - service: light.turn_off: entity_id: - light.floor - light.bedroom
Special thanks to arsaboo for assistance in writing this blogpost.