jcgoette / baby_buddy_homeassistant

This custom integration provides sensors for Baby Buddy API endpoints.
MIT License
64 stars 30 forks source link

Not fully sure how to make an Entity that closes the Timer and makes it a Sleep Timer #96

Closed Tiitto closed 1 year ago

Tiitto commented 1 year ago

Can someone please explain the documentation further for me? I'm fairly new to this kind of integration.

What I am looking for, is to have a Timer with On/Off switch, that starts the timer and when you switch it Off, it automatically creates an entry to Baby Buddy with a Sleep timer, as by default it just deletes the timer after Switching Off

kguy18 commented 1 year ago

Yeah this one took me a minute to figure out. You have to make a start timer and call the service babybuddy.start_timer and leave the start field blank so it defaults to "now" and you can optionally add a name to the timer to keep track of it in Baby Buddy. To end the timer and turn it into a sleep time you make a different service call to babybuddy.add_sleep

Here is my automation.yaml that I have for the start a sleep timer, I built an ESPHome button box so we can log Baby Buddy events at night without our phones.

alias: "Baby Buddy Logger: Sleep Start Blue Button"
trigger:
  - platform: event
    event_type: esphome.bblogger.keypad_blue
    event_data:
      title: single_click
action:
  - service: babybuddy.start_timer
    data:
      name: Sleep
    target:
      entity_id: switch.your_baby_name
      device_id: z2t1ba0b2f789dvg6c53e7ea7dd82e32 #Specific to your baby ID generated from home assistant (I just put a random string here as an example - this is NOT the ID from Baby Buddy)

Here is my automation.yaml to stop the timer and log it as sleep:

alias: "Baby Buddy Logger: Sleep Stop Blue Button"
trigger:
  - platform: event
    event_type: esphome.bblogger.keypad_blue
    event_data:
      title: long_click
  - platform: event
    event_type: esphome.bblogger.keypad_blue
    event_data:
      title: hold
action:
  - service: babybuddy.add_sleep
    data:
      timer: true #This pulls in the current timer and ends the time when the service is called
      notes: From Changing Table
    target:
      entity_id: switch.your_baby_name

Hopefully this all makes sense. You will need two different calls to have it start and stop a timer. If you start the timer from the Home Assistant integration you can then create an automation to stop the timer using a different button. To make sure you don't accidentally delete the timers (as you described) I would just create a custom button to call these two automations. Hopefully that helps!

Tiitto commented 1 year ago

@kguy18 Oh my God! Thank you! You made it so simple! :D Got it to work with ease with those instructions! SO many thank YOU's! Finally something automated that the wife appreciates :D