baby_buddy_homeassistant
baby_buddy_homeassistant copied to clipboard
Unable to specify start & end time for pumping
I'm trying to add a button that will add a pumping entry with a specific start and end time, but that doesn't seem to be possible currently.
When I add the button via the Lovelace UI, this is the YAML that gets created:
show_name: true
show_icon: true
type: button
tap_action:
action: call-service
service: babybuddy.add_pumping
target:
entity_id: sensor.baby_name
data:
amount: 33
time: '22:33:00'
entity: sensor.baby_name
name: Add Pumping
I've tried using a template, and just entering in specific values -- nothing seems to work for setting the start time.
I looked at the OpenAPI schema ( which I found by going to /api/schema
on my Baby Buddy instance ) and the arguments for adding a pumping don't specify time
as a field:
Pumping:
type: object
properties:
id:
type: integer
readOnly: true
child:
type: integer
amount:
type: number
start:
type: string
format: date-time
end:
type: string
format: date-time
duration:
type: string
readOnly: true
nullable: true
notes:
type: string
nullable: true
tags:
type: array
items:
type: string
required:
- child
- amount
It looks like the API supports setting a start and end time as of version 2.0.0, same as for feedings -- but the code is only sending a time
field.
I've tried to update the code so that it has a start
and end
like async_add_feeding and created a PR: #121 -- I'm not a Python dev though, I'm a Go dev; so I probably missed something 😅
I have tried playing with adding this myself and had no luck, the wife has been asking for this feature!
This one issue was throwing me off. I was setting a time via the service call but it was not actually setting in baby buddy. I would like to bump this for a fix too
I was running into this issue as well and was causing my wife frustration. I ended up using a rest_command
within HA to replace the broken add_pumping
service from this integration.
If you add this to your configuration.yaml
for Home Assistant you can call the service as below
rest_command:
add_pumping:
url: [[your instance]]/api/pumping/ # be sure to set this to the address of your baby buddy instance
method: POST
headers:
authorization: !secret baby_buddy_token # but auth token is stored in `secrets.yaml` in the format of `Token abc123`
accept: "application/json, text/html"
content_type: 'application/json'
verify_ssl: false # This was false for me since I don't use ssl
payload: '{"amount": "{{ amount }}", "notes": "{{ notes }}", "child": "{{ child }}", "start": "{{ start }}", "end": "{{ end }}"}'
Then in my automation I have
service: rest_command.add_pumping
data:
start: >-
{{(states('input_datetime.pumping_start_time') |
as_datetime).strftime('%Y-%m-%dT%H:%M:%S')}}
end: >-
{{(states('input_datetime.pumping_start_time') |
as_datetime).strftime('%Y-%m-%dT%H:%M:%S')}}
amount: "{{states('input_number.pumping_amount')}}"
notes: "{{states('input_text.pumping_notes') or ''}}"
child: 1
This update should make this easily implementable.
https://github.com/babybuddy/babybuddy/pull/861