BabyBuddy for HomeAssistant

BabyBuddy in HomeAssistant

This project, which revolves around the BabyBuddy Project, is meant to highlight my own way of getting and posting data between the BabyBuddy Add-on and HomeAssistant. This project is ongoing, and I apologize for the lack of polish or random comments I left in Node-RED. Our first-born came 4 weeks early, so my timeframe on the project became hours instead of weeks. Tummy Time is not used much throughout my project just yet, but will be in the future. Please note that since this is my first child, I did not reference child_id at this time.

The lovelace is heavily inspired by @Noblewolf’s post, with modifications made to it: Baby Buddy Dashboard & Blueprint
The automation side of things was initially inspired by both Noblewolf’s blueprint, as well as @OCT0PUSCRIME’s input helpers: [WIP] Baby Buddy Integration Frontend

:vertical_traffic_light: All Code is available on my GitHub repository due to character length limitations.:vertical_traffic_light:

What’s Required:

List of Input Helpers
Additional Sensors (with attributes) created by the Node-RED API calls

Additional Sensors (with attributes) created by the Node-RED API calls

- **Total Daily Feeding *(since midnight)*** - Daily bottles counts - Average per bottle - **Total Daily Pumping Amount *(since midnight)*** - Times pumped - Average pumping amount - **Total Daily Diaper Changes *(since midnight)*** - **Bottle Counts Day *(8am-8pm)*** - Total - Average per bottle - **Bottle Counts Night *(8pm-8am)*** - Total - Average per bottle - **Daily Wet Diapers *(since midnight)*** - **Daily Solid Diapers *(since midnight)*** - **Rolling 24hr Feeding Avg** - Bottle count - Total amount in last 24hr - **Rolling 24hr Diaper Avg** - **Rolling 24hr Wet Diaper Avg** - **Rolling 24hr Solid Diaper Avg**

Our newborn was a late preterm, so the additional information was useful to us. Recent studies have shown that daytime breastmilk has more cortisol and nighttime breastmilk has more melatonin. So my wife tries to split her breastmilk based on when it was pumped. This meant tracking bottles/averages of day and night separately to help us prevent waste when we fortify it.

Lovelace

My frontend changes include formatting changes, inclusion of graphs for each section, and the addition of the above data. Markdown headers now separate sections of data making it easier to read. The biggest change was modifying the `Start Timer` button, which now animates when the timer is active, and it also displays an elapsed time to gauge duration of the activity. The End Feeding/Sleep/TummyTime buttons are now hidden behind a conditional card that only shows when the timer is active. I retained the subviews for each activity, but I duplicated relevant information into their respective subviews as well. The only downside of the subviews is they don't navigate back to the previous lovelace page since only one action is allowed, which is needed for the helper.

Node-RED Automations

I’m a very visual person, so I use Node-RED for 98% of my automations. The automations used in this project use a variety of inputs, including input helpers and Noblewolf’s blueprint.

One of the things I set out to do with this project was to get more information from BabyBuddy into my frontend. I noticed that by strictly using input helpers to calculate things, my data would sometimes be mismatched. For example, if I added a feeding to BabyBuddy directly, my feeding counter helper wouldn’t include it. To solve this, I decided to go directly to the source itself via the API. Using Node-RED, I paired the input helpers together with API calls to POST and GET all the data I wanted, including accurate counts for things.

Since these projects are intended for the sleep-deprived parents of newborns, mistakes are almost guaranteed. Failure to input all required information meant no data would POST to the add-on, resulting in missed entries. The Node-RED flows now check for what data is present vs what is required to prevent API errors. When required data is found to be missing, the API call is bypassed, the current time is stored as an endTime variable, and a mobile notification is sent to complete it at our earliest convenience. Using the endTime var allows us to finish whatever we are doing without worrying about times getting messed up. We also get confirmation notifications after the integration POSTs the information successfully. I added a persistent notification that can quickly tell us when our child ate last and how much, without having to open up the dashboard.

I’ve also incorporated Google Assistant via the use of Routines. I exposed certain input.buttons to Google Home, then used those in Node-RED to trigger certain flows.

Known issues:

  • API calls on the first day of the month that reference the previous day (ex. overnight bottle counts) do not work properly based on how the function node builds the url variable.
  • If the previous feeding/pumping amount is the same as the new amount, the State for the BabyBuddy HA Integration’s last_feeding and last_pumping sensors don’t update, only the attributes update. The fix is to use the template sensors. The template sensors extract a variety of these attributes which can then be used as triggers in Node-RED.

Image Examples

Lovelace Dashboard - Home

Lovelace Dashboard - Diaper Change Subview

6 Likes

Wow this is phenomenal! I have been using Baby Buddy for the past few months and really like it, I was thinking of doing something similar to this since I have to add all the stuff from daycare that happens or the stats won’t be accurate, I was hoping to build a quick entry form similar to what you have for logging the diaper. I will have to take a look at this in more detail when I get some sleep!

This looks amazing but the instructions are very overwhelming. I have the BB add-on working. But the graphs you have are significantly more superior to the reports BB has.

If your daycare tracks when your child was fed and you aren’t too worried about feeding duration during those times, you can easily modify the Node-RED sequence to just use an input timestamp as the start/end time.

Alternatively, you could modify some of the function nodes to exclude data (or in your case, missing data) between the daycare hours. For the rolling 24hr average, you would essentially get 2 averages (time before daycare and time after daycare) within that 24hr window, then average those two values.

I’m planning to add some filter code to remove the outliers. If my child decides he wants a 30mL snack between feedings, I want to track that I fed him that much at that time, but I don’t want it to affect my averages (which should be between 90mL and 120mL for his age).

There are a lot of pieces to the puzzle in my setup, but you can modify things for what you need. For example, you may not need any of the Node-RED stuff if the data the BB integration provides is enough for your case. Integrations are beyond my scope still, so Node-RED was my way of getting the data I needed.

Not sure what I’ve done with my installation here, but the timeline is completely off by almost two years, any ideas?

Were you still planning on building/maintaining this? Looks like it hasn’t been updated in a while.

Hey guys, Im trying out this but having trouble to add feeding, tummy, diaper from HA to BB, dont know of I have to change anything on node red API, I changed to point to my HA instance , node is working , I received the notifications , but never being posted, anyone can help me?

Hello I was able to add information from diapers, and pumping, but not for feeding, all nodes seems ok, all info in the lovelace as well, how can I test to see why isn´t populating?

Hey, I was able to get this work but in the process I wanted to inform you you left some personal information in the code.

In two instances, you didn’t default the baby name to baby doe, and in the NodeRed.json, IP address and Token is out there (which is what I had to change to get it to work for me.

Just wanted to inform so you could update this.

1 Like

Hey all,

My wife and I stopped tracking everything when our firstborn was around 10 months of age, so I haven’t had a chance to update anything since. I do know there have been updates to the BabyBuddy add-on and integration since I posted this, which may be causing some issues since a few of the Node-RED sequences were workarounds for missing features. I do plan on using this again for future children and will post necessary updates as I find them, but I do not have a timeline for that.

In the meantime, if you run into issues with the code and find a fix, please submit a PR on Github so I can keep the repository up to date for others. Thanks!