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

8 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!

Hey all! My wife and I recently found out we’re expecting child number 2 this next fall, so I will be re-incorporating this over the coming months. I will post updates here as I add them to Github. If you have come across an issue and found a fix, let me know in DM or feel free to submit a PR!

1 Like

Hi first off, congratulations on your second child! I just found this project and it’s perfect for what I was looking for. I have setup all the helpers, frontend lovelace yaml and the blueprint and they all seem to be working correctly. I am new to Node-RED, but I was able to update all of the nodes and I am getting notifications sent out with messages to both our phones. However, I am having an issue with updating values of the underlying entities you created for extra tracking in Node-RED. I’m sure it’s something to do with me not fully understanding something related to Node-RED, but I was hoping you might have some insight what I’m missing.

I’m getting this error TypeError: Cannot read properties of undefined (reading ‘reduce’) when I try to add a Feeding from the frontend lovelace yaml you have in your github. I can see inside the node that i’m getting a value for Feeding Amount and then it seems like the step from the Notify to the population of the entities that the amount is reset to undefined/unknown before it can populate the sensor we created. Thanks again!

I just enabled BabyBuddy today and am working through getting my frontend added again. I know there have been various updates to the underlying add-on and integration since I disabled it, so there may need to be some changes. Based on your Node-RED screenshot, it looks like the JSON isn’t being parsed properly, resulting in the TypeError. Are any of your API calls in that section working?

Your DM helped me get to the right place. When I added the debug node to the right step I found I actually was getting an Unauthorized request. I had originally made the mistake of getting a Long-term Token from Home Assistant instead of directly from the Baby Buddy Add-On API settings. I thought it was weird that my HA Long Term Token was so much longer than the one in your example config, but once I had that setup correctly the feeding statistics entities you created in Node-RED started to work.

I was then having an issue with the Pumping config not working and my fix was to make a separate helper for input_number.bb_pumping_amount and use that entity in Node-RED. I was trying to just use the one entity, input_number.bb_amount, but without further digging something was causing that to 0 out / become undefined when entering the Pumping info. I figured maybe something leftover from the Feeding or something I had changed inadvertently when trying to fix the original issue. Otherwise I think I have everything working. Thanks again for all your hard work on this because it’s going to make life easier tracking this for us!

EDIT: Also, I found the LP Time wasn’t working because Last Pumping Attributes are Start and End, not Time like I’m assuming they were originally from the BB Add-on. I changed ‘time’ to ‘end’ for all the Last Pumping template sensors and that showed up correctly on the front-end.