[WIP] Baby Buddy Integration Frontend

Good day, I have recently built a front end for the Baby Buddy add-on and integration to assist in submitting data to Baby Buddy.

As you will probably be able to tell, I am somewhat of a novice and am open to suggestions on improving this solution, but I thought I would share as I haven’t seen any other examples of Baby Buddy integration frontends.

For this project, I used the Baby Buddy add-on and the Custom HACS Component. The Add-On is not required and the Baby Buddy software can be hosted elsewhere if desired.

Add-On: https://github.com/OttPeterR/addon-babybuddy
HACS Integration: https://github.com/jcgoette/baby_buddy_homeassistant

To get started, I used this helpful guide: https://martinnoah.com/babybuddy-and-home-assistant.html#.YyyY7HbMKUk

I wanted to take this further and build a frontend to be able to change parameters and submit them as I see fit. This allows me to retroactively make entries, and have more accurate data in BabyBuddy.

Main interface with input buttons and data

Change Button pulls up an interface to be able to set the time, type, color, and notes. Color is hidden when Solid is not checked.

The feeding button allows us to set the method, food type, amount, time, and notes. Amount is hidden when anything but Bottle is selected.

Other custom components needed to accomplish this can be found in HACS:

Custom Button Card: https://github.com/custom-cards/button-card
Browser Mod: https://github.com/thomasloven/hass-browser_mod
Time Picker Card: https://github.com/GeorgeSG/lovelace-time-picker-card

I am also heavily utilizing helper entities:

  • input_boolean.bb_diaper_wet
  • input_boolean.bb_diaper_solid
  • input_select.bb_diaper_color (Yellow, Brown, etc)
  • input_datetime.bb_diaper_time
  • input_text.bb_diaper_notes
  • input_text.bb_diaper_data
  • counter.bb_diaper_count
  • input_select.bb_feeding_method (Bottle, Breats, etc)
  • input_select.bb_feeding_type
  • input_number.bb_feeding_amount
  • input_datetime.bb_feeding_start
  • input_datetime.bb_feeding_end
  • input_text.bb_feeding_notes
  • counter.bb_feeding_count
  • input_button.bb_feeding_helper
  • input_datetime.bb_feed_time

YAML For the Change and Feed Buttons:

square: false
columns: 2
type: grid
cards:
  - type: custom:button-card
    icon: mdi:emoticon-poop
    color_type: icon
    color: rgb(68, 115, 158)
    show_name: false
    tap_action:
      action: fire-dom-event
      browser_mod:
        service: browser_mod.popup
        data:
          title: Wet Diaper
          timeout: 30000
          right_button: Submit
          right_button_action:
            service: automation.trigger
            data:
              entity_id: automation.baby_buddy_diaper_automation
          content:
            type: vertical-stack
            cards:
              - square: false
                columns: 2
                type: grid
                cards:
                  - type: entities
                    entities:
                      - entity: input_boolean.bb_diaper_wet
                        name: Wet
                      - entity: input_boolean.bb_diaper_solid
                        name: Solid
                  - type: custom:time-picker-card
                    entity: input_datetime.bb_diaper_time
                    hour_mode: 12
                    hour_step: 1
                    minute_step: 5
                    second_step: 5
                    name: ''
                    hide:
                      name: true
                    link_values: true
                    layout:
                      embedded: false
              - type: conditional
                conditions:
                  - entity: input_boolean.bb_diaper_solid
                    state: 'on'
                card:
                  type: entities
                  entities:
                    - entity: input_select.bb_diaper_color
                      name: []
                  show_header_toggle: false
                  title: Diaper Color
              - type: entities
                entities:
                  - entity: input_text.bb_diaper_notes
                    name: []
                title: Notes
                show_header_toggle: false
  - type: custom:button-card
    icon: mdi:baby-bottle
    color_type: icon
    color: rgb(68, 115, 158)
    show_name: false
    tap_action:
      action: fire-dom-event
      browser_mod:
        service: browser_mod.popup
        data:
          title: Feeding
          timeout: 60000
          size: wide
          right_button: Submit
          right_button_action:
            service: automation.trigger
            data:
              entity_id: automation.baby_buddy_feeding_automation
          content:
            type: vertical-stack
            cards:
              - type: entities
                entities:
                  - entity: input_select.bb_feeding_type
                    name: Feeding Type
                  - entity: input_select.bb_feeding_method
                    name: Feeding Method
              - type: conditional
                conditions:
                  - entity: input_select.bb_feeding_method
                    state: Bottle
                card:
                  type: entities
                  entities:
                    - entity: input_number.bb_feeding_amount
                      name: []
                  show_header_toggle: false
                  title: Feeding Amount
              - type: entities
                entities:
                  - entity: input_text.bb_feeding_notes
                    name: []
                title: Notes
                show_header_toggle: false
              - square: false
                columns: 2
                type: grid
                cards:
                  - type: custom:time-picker-card
                    entity: input_datetime.bb_feeding_start
                    hour_mode: 12
                    hour_step: 1
                    minute_step: 5
                    second_step: 5
                    name: Start Time
                    hide:
                      name: false
                    link_values: true
                    layout:
                      embedded: false
                  - type: custom:time-picker-card
                    entity: input_datetime.bb_feeding_end
                    hour_mode: 12
                    hour_step: 1
                    minute_step: 5
                    second_step: 5
                    name: End Time
                    hide:
                      name: false
                    link_values: true
                    layout:
                      embedded: false

YAML For Counts:

type: entities
entities:
  - entity: sensor.[BABY_NAME]_last_change
    name: Last Change
    format: time
  - entity: counter.bb_diaper_count
    name: Changes Today
    icon: []
  - type: attribute
    entity: sensor.[BABY_NAME]_last_feeding
    attribute: start
    name: Last Feeding
    format: time
  - entity: counter.bb_feeding_count
    name: Feedings Today
    icon: []

In the guide mentioned above, REST commands are used. I decided to go with the Service Calls that are already integrated with the HACS integration and automations:

The changing automation is triggered by the submit button on the Browser Mod popup card. It first determines if Wet and/or Solid is selected. Depending on which one, it sets Diaper Data to Wet, Solid, or Wet and Solid and then chooses which data to pass up.

At the end of the automation, all of the helpers are reset to the most used ones. So Wet on, Solid Off, No Color and No Notes.
Changing YAML:

alias: Baby Buddy Diaper Automation
description: ""
trigger: []
condition: []
action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: input_boolean.bb_diaper_wet
                state: "on"
              - condition: state
                entity_id: input_boolean.bb_diaper_solid
                state: "off"
        sequence:
          - service: input_text.set_value
            data:
              value: Wet
            target:
              entity_id: input_text.bb_diaper_data
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: input_boolean.bb_diaper_wet
                state: "off"
              - condition: state
                entity_id: input_boolean.bb_diaper_solid
                state: "on"
        sequence:
          - service: input_text.set_value
            data:
              value: Solid
            target:
              entity_id: input_text.bb_diaper_data
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: input_boolean.bb_diaper_wet
                state: "on"
              - condition: state
                entity_id: input_boolean.bb_diaper_solid
                state: "on"
        sequence:
          - service: input_text.set_value
            data:
              value: Wet and Solid
            target:
              entity_id: input_text.bb_diaper_data
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: input_boolean.bb_diaper_solid
                state: "on"
        sequence:
          - service: babybuddy.add_diaper_change
            data:
              time: "{{ states('input_datetime.bb_diaper_time') }}"
              type: "{{ states('input_text.bb_diaper_data') }}"
              color: "{{ states('input_select.bb_diaper_color') }}"
              notes: "{{ states('input_text.bb_diaper_notes') }}"
            target:
              entity_id: sensor.baby_[BABY_NAME]
      - conditions:
          - condition: state
            entity_id: input_boolean.bb_diaper_solid
            state: "off"
        sequence:
          - service: babybuddy.add_diaper_change
            data:
              time: "{{ states('input_datetime.bb_diaper_time') }}"
              type: "{{ states('input_text.bb_diaper_data') }}"
              notes: "{{ states('input_text.bb_diaper_notes') }}"
            target:
              entity_id: sensor.baby_[BABY_NAME]
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.bb_diaper_wet
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.bb_diaper_solid
  - service: input_select.select_option
    data:
      option: "''"
    target:
      entity_id: input_select.bb_diaper_color
  - service: input_text.set_value
    data:
      value: ""
    target:
      entity_id: input_text.bb_diaper_notes
mode: single

The feeding automation is triggered by the submit button on the Browser Mod popup card. It first determines if Bottle fed is selected or not. Depending on which one, it passes up the data including “amount” if bottle and not including “amount” if any other method is selected.

At the end of the automation, all of the helpers are reset to the most used ones. So Type Breats, Method Both, and No Notes.

Feeding YAML:

alias: Baby Buddy Feeding Automation
description: ""
trigger: []
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: input_select.bb_feeding_method
            state: Bottle
        sequence:
          - service: babybuddy.add_feeding
            data:
              end: "{{ states('input_datetime.bb_feeding_end') }}"
              type: "{{ states('input_select.bb_feeding_type') }}"
              method: "{{ states('input_select.bb_feeding_method') }}"
              start: "{{ states('input_datetime.bb_feeding_start') }}"
              amount: "{{ states('input_number.bb_feeding_amount') }}"
              notes: "{{ states('input_text.bb_feeding_notes') }}"
            target:
              entity_id: switch.[BABY_NAME]_timer
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: input_select.bb_feeding_method
                state: Both breasts
              - condition: state
                entity_id: input_select.bb_feeding_method
                state: Left breast
              - condition: state
                entity_id: input_select.bb_feeding_method
                state: Right breast
              - condition: state
                entity_id: input_select.bb_feeding_method
                state: Self fed
              - condition: state
                entity_id: input_select.bb_feeding_method
                state: Parent fed
        sequence:
          - service: babybuddy.add_feeding
            data:
              end: "{{ states('input_datetime.bb_feeding_end') }}"
              start: "{{ states('input_datetime.bb_feeding_start') }}"
              type: "{{ states('input_select.bb_feeding_type') }}"
              method: "{{ states('input_select.bb_feeding_method') }}"
              notes: "{{ states('input_text.bb_feeding_notes') }}"
            target:
              entity_id: switch.[BABY_NAME]_timer
  - service: input_select.select_option
    data:
      option: Breast milk
    target:
      entity_id: input_select.bb_feeding_type
  - service: input_select.select_option
    data:
      option: Both breasts
    target:
      entity_id: input_select.bb_feeding_method
  - service: input_text.set_value
    data:
      value: ""
    target:
      entity_id: input_text.bb_feeding_notes
mode: single

I also have an automation here to keep the various helpers updated. When changing start time for feeding it changes end time, so I can perform less clicks to set times, incrementing the total counts, and resetting the counts at the end of the day.

Helper YAML:

alias: Baby Buddy Update Helper Times
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.[BABY_NAME]_last_change
    id: last-change
  - platform: state
    entity_id:
      - sensor.[BABY_NAME]_last_feeding
    id: last-feed
    attribute: start
  - platform: state
    entity_id:
      - input_datetime.bb_feeding_start
    id: feeding-start
  - platform: state
    entity_id:
      - input_datetime.bb_feeding_end
    id: feeding-end
  - platform: time
    at: "00:00:00"
    id: new-day
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: feeding-start
          - condition: template
            value_template: >-
              {{ states('input_datetime.bb_feeding_end') <=
              states('input_datetime.bb_feeding_start') }}
        sequence:
          - service: input_datetime.set_datetime
            data:
              time: "{{ states('input_datetime.bb_feeding_start') }}"
            target:
              entity_id: input_datetime.bb_feeding_end
      - conditions:
          - condition: trigger
            id: feeding-end
          - condition: template
            value_template: >-
              {{ states('input_datetime.bb_feeding_end') <=
              states('input_datetime.bb_feeding_start') }}
        sequence:
          - service: input_datetime.set_datetime
            data:
              time: "{{ states('input_datetime.bb_feeding_end') }}"
            target:
              entity_id: input_datetime.bb_feeding_start
      - conditions:
          - condition: trigger
            id: last-change
        sequence:
          - service: counter.increment
            data: {}
            target:
              entity_id: counter.bb_diaper_count
      - conditions:
          - condition: trigger
            id: last-feed
        sequence:
          - service: counter.increment
            data: {}
            target:
              entity_id: counter.bb_feeding_count
      - conditions:
          - condition: trigger
            id: new-day
        sequence:
          - service: counter.reset
            data: {}
            target:
              entity_id:
                - counter.bb_diaper_count
                - counter.bb_feeding_count
    enabled: true
mode: single

I labelled this as a WIP because I am not totally happy with where it’s at:

  • There are other services I would like to include, like the Delete Last Entry service
  • A better way to handle total counts. The guide reference got total counts via templates, but they were not working for me. I may end up scraping the values from the BabyBuddy admin page, because I think it will be too complicated to account for deleting entries and updating the proper counter
  • I would like the time cards to update with the current time when opening the popup card, but have not gotten around to implementing that yet.
  • Rely less on helper entities
  • The helper automation to keep the end time for feeding up to date with the start time works until rolling past midnight, at which point I have to roll the end time up past midnight so it once again equals to before the start time. Should be simple to fix > when start time = midnight change end time to midnight.

Apologies if this is a bit confusing to follow, I am somewhat sleep deprived for obvious reasons :slight_smile:

5 Likes

I just searched “baby” in the forums here and this was the third result. We’re due next month (Dec 2022) and I’ve been wandering how Home Assistant can help with this. Thank you for this!

Sorry to crash the party, but anyone know why @cdubz on Github removed the “Deploy on Heroku” button? Remove Heroku-specific config and documentation · babybuddy/babybuddy@65a7e87 · GitHub

Is there another simple way to deploy Baby Buddy somewhere?

I know that @OttPeterR is working hard on a HA Addon, but it’s currently experiencing an issue docker build error related to dependencies? · Issue #21 · OttPeterR/addon-babybuddy · GitHub

BTW, @OttPeterR if you need help testing I’d be happy to lend a hand.

The Heroku option disappearing seems to have happened around the same time the free tier on Heroku going away, so maybe thats it.

And for my docket build issues, if there’s a Docker dependency experts out there your help would be greatly appreciated! I think some upstream dependency is having a conflict and thats causing the issue.

Tangentially, I think there’s a way to pre build the baby buddy HA container and save it on ghcr but I haven’t set that up yet. So ill add that to my eventual todo list :crossed_fingers:

1 Like

You’ve probably already read this a bunch but here’s HA’s developer documentation for Add-on’s Developing an add-on | Home Assistant Developer Docs

I’m not sure who here in the community would be of help but I know @123 has been around quite a while. @blakeblackshear has been doing some amazing work with Frigate. @blakeblackshear or @123 you know of any docker dependency experts that could guide @OttPeterR ?

hi @NobleWolf - this is my first try to install the add-on. I am not hosting it anywhere, I am trying to get it running on a container on HA on RPI 4 (arch armv7). I also tried running it on my laptop (arch x86_64) in case the architecture would be problematic, and that seems to work. I am no expert either, but hoping someone can help getting this to work on armv7/rpi4

1 Like

issues I have been able to find:
-base-build cannot be retrieved because of musl package version difference
-postgresql-dev cannot be retrieved because of libcrypto1 package version difference.

no idea how to solve this though.

I’m working on building off of your setup here but using the Home Assistant UI Subviews 2022.10: All over the place - Home Assistant

I’ll share when I’m done!

There was an update to the base addon docker image, that update was just pushed out so you should see it soon, let me know if it helps!

:frowning: Thank you, I tested it and posted the error message on the GitHub issue docker build error related to dependencies? · Issue #21 · OttPeterR/addon-babybuddy · GitHub

Thank you for your hard work here, you inspired me to make my own too!

I’ve created something similar and documented it here as a blueprint and screenshot of my dashboard:

@OCT0PUSCRIME let me know what you think!

1 Like

This looks great! Glad to see you took it further than I did and implemented more options like pumping, sleep and tummy time timers! I have slowed down my use of Baby Buddy in the last few weeks, but it was integral during the first couple of months. I will definitely reference back to this once I am on baby #2 lol.

1 Like

Okay, glad to meet someone who has used Baby Buddy… What features did you find useful? And separately, what features did your significant other find useful?

Do you happen to have a sensor for HA to display total feedings today? I think it should be a rest sensor but not sure how to make it.

You’d need to get the sensor from the Integration, but it currently doesn’t have that. @OCT0PUSCRIME has only documented his way to display the information provided by the integration. See the “HACS Integration” linked in the original post. I checked the “Issues” log for the integration and someone has already suggested that total feedings sensor be added: Feedings total amount · Issue #58 · jcgoette/baby_buddy_homeassistant · GitHub

You can also create your own counter like I did.
I documented it in a Blueprint and Dashboard in my previous comment above here: Baby Buddy Dashboard & Blueprint

The Home Assistant community is amazing. If you’re trying to do something it’s probably already been done and documented. :smiley:

The features I find useful seem to change as the baby changes. At first, both my partner and I heavily used the feeding and changes time and total counters.

Our guy came home under weight so it was crucial that we ensure we are giving him at least so mamy feedings a day and he is still having so many changes.

As that worry died down we really just started using the feedings. We split night shifts so it is helpful to be able to glance and see how long it has been. We never really did make use of the notes, diaper colors, feeding amount in oz, etc.

Now that we are onto a new phase, we are really only tracking solid diapers because he will go several days, which isn’t a problem, but it’s easy to forget just how many days.

Separately, I do like tracking the weight, height, and, head circumference. My partner isn’t really interested in this, and I can’t say it’s super helpful, I just like to see his growth represented numerically lol.

I am sure it will continue changing as well. I did end up building a pressure sensor for the crib and planned to use it to start and stop sleep timers, but he sleeps so much and in so many different places. We will soon transition to scheduled naps in the crib and I am transitioning to stay at home dad life, so I am sure my wife will want to know how many naps and how long when she’s done working.

1 Like

My counter isn’t without its issues. A agree an exposed sensor would be way better. Alternatively, some sort of web scraper would be the most accurate until baby buddy is updated to expose that sensor.

hi, I am unable to get the “count” working. Also, I don’t really understand what you mean by “XYZ yaml” – are these all in configuration.yaml? Automation.yaml? Somewhere else? I am using the Blueprint you created and it requires the “Counter” as a mandatory field. I don’t know what I need to type in which file to get counters to work. Super n00b here.

I have a work-around for the counters that actually pulls the true count from the BabyBuddy add-on via the API. There have been some requests for additional sensors as part of the HA integration, but it’s one person working on it and I’m sure it’s not his only project. Unfortunately, I have no experience working on HA integrations so I couldn’t be much help. However, I used the API in Node-RED to pull the additional information I need, including exact counts of things. I created a separate forum post, since it’s a different way of doing things.