Smart Baby Monitor

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 Assistant. 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.

Setup

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://236.0.0.1:2000 over multicast. We can set the input option on the Home Assistant side to rtp://236.0.0.1: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 to ffmpeg_noise. Also all service going to component and was rename from binary_sensor.ffmpeg_xy to ffmpeg.xy.

On Raspbian Jessie, you can setup FFmpeg and install an icecast2 server using:

$ 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 an icecast mount point for our babyphone and update /etc/icecast2/icecast.xml:

<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

Trigger an alarm

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

Thanks

Special thanks to arsaboo for assistance in writing this blogpost.


This is a companion discussion topic for the original entry at https://home-assistant.io/blog/2017/02/03/babyphone/
14 Likes

By the second child you stop caring so much… :grinning:

12 Likes

Even more by the third. :stuck_out_tongue:

4 Likes

Great post! Been thinking about implementing something like this in Home-Assistant, inspired by the following.
Cheers

Tried this one on XIaomi Fang camera but the white noise keeps triggering the sensor, without the fang hack, it looks like the camera is still giving white noise.

EDIT: turns out I need to tweak the peak and duration option on the binary sensors.

1 Like

@accelle
I’m having the samme camera. Care to share your peak and duration options?

I didn’t change much of the configuration:

extra_arguments: -filter:a highpass=f=300,lowpass=f=2500,volume=volume=2 -codec:a libmp3lame -ar 16000
#output:  -f mp3 /home/homeassistant/.homeassistant/www/babymonitor.mp3
initial_state: false
duration: 2
reset: 60
peak: -20

I was experiencing hang ups on the xiaomi fang so I still need to look on the camera and see if the timestamp is up to date. rtsp is still hanging and takes some time to restart even with the monitor script.

1 Like

Would it be possible to extend this to stream the video from the IP camera to a device? I would potentially like it to send the stream to my TV (after pausing what I am watching).

Could I send the video stream ip to a chromecast? Would that work?

Oh sh*t !! until you posted this, I’d forgotten about the second child.

Now where did I leave them…

2 Likes

Setting up presence detection - Home Assistant :stuck_out_tongue:

3 Likes

@accelle Did you manage to sort this out?

no, i gave up on fang. I just used echo’s drop in feature for baby monitor.

Oh right I see

@arsaboo do you mind sharing your icecast.xml please? as I am struggruling to find what changes I need to make for the stream to work after doing a fresh install of icecast on my raspberry pi.

thanks.

I am not using icecast…

Can anyone recommend a camera for this setup.

Was looking at

Dahua c35 (English FW) $76USD delivered to NZ
Dahua a46 (English FW) $112USD delivered to NZ

Amcrest 1080p pro $70 USD delivered to NZ
Amcrest 2MP Ultra HD $90USD delivered to NZ
Amcrest 4MP Ultra HD $100USD delivered to NZ

I don’t actually need PTZ but would like audio support.

I really want to set this up but have no idea how to setup the camera to stream to home assistant and also the audio via USB microphone. I tried to follow the guide but I feel it misses some steps under the assumption I know what I’m doing :slight_smile:

Just thought I’d say, me and my wife use a wyze cam, theyer cheap $25ish and work great.

Is it also possible to install Icecast on Hassio docker? Can someone tell me how to set this up within Hassio? Or is there maybe an Node Red alternative to create a babyphone / babymonitor

If icecast is available on docker, then you can install it. Install the portainer addon and proceed from there.