Carpe Diem:28 May, 2020

Affordable & Awesome Smart Baby Monitor

This post may contain affiliate links. Please see our disclaimer for more info.

UPDATE: The Wansview K3 camera that I use is no longer available on Amazon at the time of this writing AND I’ve learned that newer firmwares do not support local RTSP – blah! I instead am providing links to the Wansview K2 – the 720p version of the camera. Any camera will work as long as it has RTSP (local access) support. Many newer brands (such as the K5) only offer cloud only support meaning it will not work just locally with Home Assistant.

I’ve recently become a parent, and it’s pretty epic. I highly recommend. It does come with its challenges however. Logistics and priorities were completely flipped up in the air. One of the challenges was finding an effective and secure baby monitor so that we could keep an eye on the little guy without busting the bank. Baby stuff can get expensive quick – I was looking to avoid spending $200 for a proprietary limited device. Plus many of those devices use RF so you only have a limited range and depending on interference, even more limited.

With this setup, you’ll be notified and be able to keep an eye on the kid wherever you have internet access. Your neighbor parents will look at your setup in awe.

Using Home Assistant as the base, I was able to research the details I needed to get started. This post proved to be extremely helpful – I’m using much of this in my setup.

Good parenting disclaimer: If you’ve used Home Assistant long enough, you’ll know that it can fail – most likely due to user error (in my experience!). It’s not just HA, any device/system can fail. With any automation that has critical consequences if not operating right, make sure your conscious of how its running. Do I trust this setup to tell me if my kid is crying after waking up from a nap? Yes! But if I notice he’s napping longer than normal, I do a quick check on the live feed every now and then. We all have different levels of parent paranoia!

Project goals

  • Accurate sensor when the baby is crying (making noise). However we don’t want false alarms when regular background noise is picked up (these camera mics can pick up a lot of noise!)
  • Video feed of the baby
  • Notifications on my phone and wife’s phone that we’re able to turn off/on independently (if one of us is not home for example)

Ingredients

Equipment

Setting up WiFi Cameras these days is pretty simple. It’s just a matter of informing the device of your WiFi name and password. I recommend using a static IP for your cameras – it will save you a bunch of time and makes keeping things organized much easier. I make all my devices static from within my router by assigning IPs to MAC addresses. If you’re having trouble getting your specific camera working with HA, do some googling of your model and HA. Chances are someone has already figured it out.

You don’t need a fancy camera for this setup by any means – I’m rocking a Wansview K3 that I paid $30 bucks for. I can’t find it anymore on Amazon – another option is the K2 Camera 720p. Do not buy the K5 – it’s not compatible with RTSP. As long as you can find a camera with the standard IP camera protocol, RTSP, you’ll likely be able to integrate with HA.

Integration

This part is a little more complicated – there are a lot of components involved here. Luckily it’s not anything too complicated – just a lot of parts to fit together. I’ll walk through each part and provide the necessary config code. I highly recommend doing some trial an error as you get each component setup to confirm it’s working as intended before moving onto the next piece. This way, if there is an issue, you can limit your potential problem scope areas.

Camera

Follow the steps on HA Camera integration . You might need to do some trial and error to figure out what config options work best for you. At a minimum, you’ll need to add the still image parameter and the stream source parameter. Additionally, I found that in order to get the streaming to work correctly, I needed to put in the user and password twice – once as arguments and again within the RTSP stream source link – see my config below. The below works for my Wansview K3 Camera which also has the same protocols as the K2 camera.

camera:
  - platform: generic
    name: Nursery
    stream_source: rtsp://[username]:[password]@192.168.1.199/live/ch0
    still_image_url: http://192.168.1.199/mjpeg/snap.cgi?chn=0
    username: [username]
    password: [password]
    authentication: digest

FFMEPG

This is the brains of this whole operation. FFmpeg is a light yet powerful video processing tool. This tool does the actual scanning of the camera’s audio source and triggers when the audio meets a certain pattern (specified by us – details in the FFmpeg Binary Sensor section below). You can even use FFmpeg to process the video stream too to check for motion and other things, however any type of video processing is a heavy lift on the processor. A raspberry pi isn’t the best option for this. Luckily, audio processing only takes up about 5% CPU load on average based on my findings with my raspberry pi 3.

Don’t let this powerful tool put you at unease; getting this working with HA is a breeze.

If you are using HASSIO, FFmpeg is actually already installed. Enable it by just including ffmpeg: in your config. To integrate with other installations of HA, see the HA docs here.

ffmpeg:

FFMPEG Noise Binary Sensor

I’ve written a lot about binary sensors – I use them for many of my projects. They are simple and effective. We are lucky enough to have a FFmpeg noise binary sensor already built into HA. This means that once FFmpeg is triggered via a camera audio feed, it’ll flip this binary sensor which we can then use to trigger the rest of our automations. This saves us a TON of trouble so that we don’t have to create our own sensor from scratch.

Enable this by adding the below to your configuration.yaml. This includes the audio frequency specifications for what FFmpeg should focus in on (baby crying vs car going by). I grabbed this from this post, and found that I didn’t need to tweak the settings at all.

binary_sensor:
  - platform: ffmpeg_noise
    input: rtsp://[username]:[password]@192.168.1.199/live/ch0
    extra_arguments: -filter:a highpass=f=300,lowpass=f=2500,volume=volume=2 -codec:a libmp3lame -ar 16000
    initial_state: false
    duration: 2
    reset: 60
    peak: -32

Input Boolean (Switch)

Input_boolean sounds fancy, but these are all just digital switches in the HA interface. These allow us to turn automations off and on from the front end. For this use case, we use these to 1) enable the baby monitoring and 2) tell the automation which devices to send the notifications to.

input_boolean:
  baby_monitor_mom:
    name: Baby Monitor Mom
    initial: off

  baby_monitor_dad:
    name: Baby Monitor Dad
    initial: off

Notifications

This is the essential part to make this all worthwhile: getting notified when the little one needs some love.

The beauty of this setup is that you can be anywhere with internet connectivity and get notifications that the baby is screaming.

No need to worry about RF range and be pinned to a 30 foot radius around the baby’s room. My wife and I are able to enjoy a late evening in the backyard while still keeping an eye on the little one.

I’m using iOS notifications provided by the HA iOS companion. I’m able to get a fast notification that includes a picture of the room from the camera on my phone and watch. This way I’m able to quickly see if the baby is actually crying or just made a mid-sleep noise – it happens a lot!

There is no additional code needed for this if you are using the mobile_app platform. See HA for details on how to set up. Otherwise set your own platform up. Once complete, you’ll have a notify service that you’ll use to send messages to devices.

Notification Groups

While not 100% necessary for this project, using notification groups will make your automations much easier. They essentially just let you create aliases (or groups) and all the entities in that group will get notified. I use this for 2 purposes:

  1. Create a parents group that notifies myself and my wife
  2. Create wrapper groups for devices so I don’t need to change all my automations/setup if my device name changes. For example, the new HA iPhone companion (in beta as of this writing) uses whatever I named my iPhone as the device ID. Right now my iPhone is named iPhoneX. But someday it’ll be iPhone12 or 30 (who knows!). I created a group that takes my device ID as an entity and named the group ad_iphone, which I use in all my automations. Then when my device name changes, I just need to update the group and not all the automations.
notify:
  - name: parents
    platform: group
    services:
      - service: adiphone
      - service: ios_lbiphone
  - name: adiphone
    platform: group
    services:
      - service: mobile_app_ad_iphonex

Stream

This is a somewhat new component that allows you to stream video through Home Assistant to HA itself or other devices. I use this to stream my camera’s feed to HA’s front end. This can be extremely handy as you can setup your automations to check if you’re watching ChromeCast for example and if so, stream the video to the TV. While this component isn’t required to receive notifications – it’s nice to see a live feed of the kid.

Setup for this was a little trial and error for my cameras. I needed to update the camera’s RTSP URL (See the camera section above) to include my username and password.

stream:

Automation

Getting things automated right took a bit of thought Let’s revisit our goals and come up with the following automation specific goals:

  • Accurate trigger to start the notification process (FFmpeg noise binary sensor does this for us) when the camera picks up audio
  • Provide an image (or video) in my notification
  • Ability to turn the notifications off and on independently for multiple devices

The below code (automations.yaml) and Node Red setup will accomplish the above. I use Node Red for all my automations but I had my old YAML lying around to share. Download my Node Red flow here.

Node Red Flow
# turn on bb monitor if either mom or dad switch is on
- id: babyMonitorOn
  alias: bb Monitor On
  trigger:
    - platform: state
      entity_id: input_boolean.baby_monitor_mom
      from: "off"
      to: "on"
    - platform: state
      entity_id: input_boolean.baby_monitor_dad
      from: "off"
      to: "on"
  action:
    service: ffmpeg.start
    entity_id: binary_sensor.ffmpeg_noise
  condition:
    - condition: state
      entity_id: binary_sensor.ffmpeg_noise
      state: unavailable

# mom's switch turned off, check if dad's is still on
# if so, leave it on. If not, turn it off
- id: babyMonitorOffMom
  alias: bb Monitor Off Mom
  trigger:
    - platform: state
      entity_id: input_boolean.baby_monitor_mom
      from: "on"
      to: "off"
  action:
    service: ffmpeg.stop
    entity_id: binary_sensor.ffmpeg_noise
  condition:
    - condition: state
      entity_id: input_boolean.baby_monitor_dad
      state: "off"

# dad's switch turned off, check if mom's is still on
# if so, leave it on. If not, turn it off
- id: babyMonitorOffDad
  alias: bb Monitor Off Dad
  trigger:
    - platform: state
      entity_id: input_boolean.baby_monitor_dad
      from: "on"
      to: "off"
  action:
    service: ffmpeg.stop
    entity_id: binary_sensor.ffmpeg_noise
  condition:
    - condition: state
      entity_id: input_boolean.baby_monitor_mom
      state: "off"

# baby triggered alarm! Notify Mom
- id: babyMonitorMom
  alias: Baby monitor notify mom
  trigger:
    platform: state
    entity_id: binary_sensor.ffmpeg_noise
    from: "off"
    to: "on"
  action:
    service: notify.ios_lbiphone
    data:
      title: Baby Alert!
      message: bb be noisy...
  condition:
    - condition: state
      entity_id: input_boolean.baby_monitor_mom
      state: "on"

# baby triggered alarm! Notify Dad
- id: babyMonitorDad
  alias: Baby monitor notify dad
  trigger:
    platform: state
    entity_id: binary_sensor.ffmpeg_noise
    from: "off"
    to: "on"
  action:
    service: notify.ios_adiphone
    data:
      title: Baby Alert!
      message: bb be noisy...
  condition:
    - condition: state
      entity_id: input_boolean.baby_monitor_dad
      state: "on"

And there you have it! After setting this up you’ll officially be parent 2.0 and impress all your neighbors!

28 Comments

  1. Roelof Schuiling Reply

    Awesome what you did with HA, hats off to you!

    For the time challenged new parents I might also recommend the Android app Baby Monitor 3G. Put it on an old phone or tablet, and you get similar functionality as described in the article.

  2. Erdan Kinmer Reply

    I didnt get how this solution is better than just using wyzecam? I just use wyzecam for baby monitoring. Just put low sensitivity on the sound alert option and disable the motion alerts option fully. It just works fine. Never got a false sound alert. Plus each time an alert is triggered it saves 12 sec video. If you build a code that can alayse and look for patterns among those alerts then it can more interesting for me.

    1. Alex Post author Reply

      Wyzecam may be getting better, but in my experience with IP Cameras, the mic sensitivity never worked for my house. Walking around the house, the kid moving around in the crib, or a car truck driving by would trigger the sound notification. When using the HA setup, you are actually filtering out sound frequencies and focusing in on the frequency range in which a baby’s cry is heard. Another benefit is the ability for my wife and I to turn on or off the notifications easily in HA. It’s two presses on a phone or we can ask Alexa. This is also independent of one another – If I’m out of town, my wife can easily just enable it for her. Another benefit is the ability to queue up different automations. For example instead of just getting a notification on your phone, it can turn on a hallway light in the middle of the night to guide your path to the kid. Or you can even stream the audio to a speaker to make sure you hear it! Integrating with HA means you can easily add this into your ecosystem. Lastly, with HA. You’re not sending your data outside your home – Wyzecams are uploading all this footage to their servers. Folks feel differently about this but some don’t want to have to send data to other companies; I don’t mind as much.

      If your setup works for you, that’s great! No need to change it. For me, I did a handful of trial and error before I found one that worked.

  3. Glenn Chapman Reply

    This is great and has proved useful to me as an old baby monitor (mother in law with alzheimer’s). One thing I’m struggling with – how can you get more than one camera sound working. Ffmeg_noise seems to just call the first platform in configuration.yaml. I’ve tried putting the second cameras credentials in the node red data field for call service “ffmpeg start monitoring”, but this didn’t work either. Any ideas?

    1. Alex Post author Reply

      I haven’t tried two separate entities for just ffmpeg.noise but in theory it should work. Let me try playing around with my config to see what I can do – stay tuned!

  4. painy Reply

    Are you using this during the night?
    Im not a parent yet but i hear a lot of parents sleep in shifts. Like mom does first half of the night, dad does second.
    How about a second input boolean with a longer duration. During the first part of the night it sends a notification to mom if triggerd, and to dad the second part.
    Preferably silenty as not to wake the other parent (fully). Like via a fitbit silent alarm? No idea how to push this with HA though.
    You could then listen to the feed with wired earbuds on your smartphone.
    Or is this scenario to optimistic?

    1. Alex Post author Reply

      I did initially use it at night, but found it wasn’t necessary. Our kid’s rooms are all close enough to the master bedroom that I could easily hear an upset kid without the monitor. But when I did use it, I had it turn on my bedside light to have a little less aggressive of a wake up.

      The scenario you proposed sounds feasible. That’s the beauty of this setup; once you get the noise sensors into HA, you can create automations for anything that has connectivity to HA. I don’t know about fitbit, but I have an apple watch that receives notifications (via the iphone HA Companion app). You could set the automation up to repeatedly notify your phone/watch (to wake you from a deeper slumber) until you trigger it off.

      Best thing I’ve found is trying out a few different set ups and see what works best. Don’t try to perfect it the first time!

  5. Francois Reply

    Hello,
    Thanks for sharing this project ! I managed to get it working with a Wansview Q5 (which is at first a cloud only camera, but managed to get the rtsp url anyway). Do you use the stream component in Hassio ? I can’t figure out how to hear things in live stream.

    1. Alex Post author Reply

      Great to hear you got the Q5 working! I’m disappointed that Wansview is making it more difficult not to cloud…
      Regarding the stream component, yes I do use it. I have not figured out how to get audio in though with this camera. When I initially set it up, I learned that the stream component is still relatively new and not fully compatible with all audio/video sources. I imagine it’ll be further supported in a later release. For the time being, I’ve found that the video has been enough to see an upset child, or if I want audio, I use an IP Camera app on my phone. Right now I’m using Wansview’s app, but I’m going to transition to a different setup at some point – Blue Iris I think.

      1. Francois Reply

        Thanks, i will keep you posted if i find anything regarding audio in stream. One more question : the ffmpeg binary sensor keeps going randomly “unavailable”. Did you have the same problem ?

        1. Alex Post author Reply

          I’ve had issues where ffmpeg binary sensor would go unavailable, but it wasn’t random. Happened almost immediately after I enabled it. Unavailable indicated theirs a problem with ffmpeg, likely the config. I’ve found that ffmpeg is VERY picky with the config setup and it varies based on how you have HA installed (hassbian vs hassio for example). And this changes from one version of HA to another. The config I posted above works for me running in hassio. However on hassbian, I needed to include the below additional line to get it to work. What type of install and version of HA are you running?

          binary_sensor:
          – platform: ffmpeg_noise
          input: !secret wansview_stream_19
          ffmpeg_bin: /usr/bin/ffmpeg # <<<<< extra line needed for hassbian extra_arguments: -filter:a highpass=f=300,lowpass=f=2500,volume=volume=2 -codec:a libmp3lame -ar 16000 initial_state: false duration: 2 reset: 60 peak: -32 You could also try adding 'ffmpeg:' to your config as well (anywhere). It should be enabled by default for hassio, however.

          1. Francois

            Thanks a lot for your answer again. I use hassio, latest version. No change with or without “ffmpeg_bin: /usr/bin/ffmpeg “, (even if it’s not needed for hassio, i tried). The binary sensor becomes unavailable after a random time between 2 and 3 hours. I will keep looking for a solution.

          2. Alex Post author

            Hmm – yeah I’m not sure then; it seems to be very finicky. In the meantime, you could add a simple automation to call ‘ffmpeg.restart’ to restart the service every time it returns an unavailable state.

    2. José Pedro Reply

      Hi! I have a Q5 also and I already found there is a RTSP stream on port 554… Unfortunately I can’t access it (seems to give me authorization failed). Can you describe how did you find the RTSP stream for it? It would help others as well 🙂

      Thanks!

  6. John Reply

    Good work!

    I have a question, did you manage to get your sound working in the stream component? or you just rely in the noise sensor?

    1. Alex Post author Reply

      Thanks! Regarding the stream component, I have not figured out how to get audio in though with this camera. When I initially set it up, I learned that the stream component is still relatively new and not fully compatible with all audio/video sources. I imagine it’ll be further supported in a later release. For the time being, I’ve found that the noise sensor and video has been enough to know when I have an upset child. Or if I want audio, I use an IP Camera app on my phone. Right now I’m using Wansview’s app, but I’m going to transition to a different setup at some point – Blue Iris as a one stop shop for all my cameras I think.

  7. raj Reply

    I am soon to be a parent and want to setup this monitoring using Wyze cam 2. I have a few questions:
    1. How do I know if the stream is getting to HA correctly? how to test I don’t have a card to see and struggling setting up.
    2. You show 4-5 sets of the score above, are these all going in the configuration.yaml in any sequence?
    3. Can you make a video tutorial for this, please?

    1. Alex Post author Reply

      Congratulations! that’s exciting news! It’s a load of fun being a parent. For your questions:
      1) What do yo mean by card? By steam are you talking about the audio stream that is being used for the detection or the entire video stream? If you are using hassio (now called just home assistant), there isn’t an easy way to see what ffmpeg is processing unforch. If you have access to the console, you can run the ‘top’ command which is much like windows task manager to see what tasks are running. But generally, start trying it out to see if you can get it working is the best. If you follow the steps, HA will give you notifications when things are working well. Trial and error 🙂

      2) By scores do you mean blocks of code? Most of the blocks do go in the configuration.yaml. The lastmost code block can go into automations.yaml though.

      3) Unfortunately I lack the equipment, time, and knowledge to make quality content videos. These kids take up too much time – sorry!

  8. Raj Reply

    I am sorry for the typos and wrong choice of words.
    1. The card is the front end of the Lovelace UI object where I am getting my live stream as a test. I understood not that we won’t have any front end from this project.
    2. Yes, I meant code blocks above for notification, stream and then Node-red. OK, so I will try with automation.yaml
    3. Lol – I will soon understand your pain. And that’s why want to finish the project before the arrival.

    Thanks

  9. Raj Reply

    Alex, in your notification group, notify: second part is where you assign your device service to the group. I am guessing that you need to add similar lines for your wife device as well in case that changes in future? This means I will add one more set of these lines with 2nd mobile_app service.

    – name: adiphone (or ios_lbiphone)
    platform: group
    services:
    – service: mobile_app_ad_iphonex (or mobile_app_lbiphone)

    1. Alex Post author Reply

      Hey – yep! You could make another group for another device. Can’t hurt.

      And one clarification on the previous comment – you’ll either want to use the automation.yaml or Node-Red. Not both.

  10. Raj Reply

    Thanks, Alex,
    I imported your Node-Red Flow and my 3 initial nodes are all Disconnected (DAd Monitor On, Mom Monitor On, and Baby Alert. What configuration is required to connect them with HA or device entities? Also, how do I test where I am going wrong as I haven’t got any notification (assuming I don’t have sound in that range of baby cry yet). If you can add test steps in your article for checking if each item is working as they are support to – stream, notify, group and lastly Node-red. Thanks in advance.

  11. Raj Reply

    Alex, I am just one step from making this work. On the node-red Notify Dad node, I am getting an API error – Call-service API error. Error Message: Service not found..

    Here the settings I changed – https://imgur.com/a/9ehE1kr
    Definitely some of my settings are not working or the noise itself is not coming. What could be wrong?

  12. Raj Reply

    Finally, it working. Although it’s picking every sound as a crying baby – keyboard click, mouse click, etc. Need to week the range I guess. Any suggestion where can I find information on that?
    Thanks a ton. I will be testing this in the coming days before my wife gives OK for the default monitor. lol

    1. Alex Post author Reply

      Awesome!! I’m no expert with sound and understanding the filters unforch. To tweak the sensitivity, you’ll need to play with the extra argument within the ffmpeg section in your HA config. extra_arguments: -filter:a highpass=f=300,lowpass=f=2500,volume=volume=2 -codec:a libmp3lame -ar 16000. Try removing the volume=volume=2. Or reduce the 2 to 1.5 or lower. See https://trac.ffmpeg.org/wiki/AudioVolume for more info.

Leave a Reply

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