Create a timer and alert based on user input

I think I should be able to do this with Helpers, but not sure exactly how.
I want to input some value, and when I’ve inputted a value a countdown timer should be set. I want to show this on the dashboard.
When the timer is at 0, I’d like to trigger an alert in the Home Assistant App (on phone, is this possible?)

The value would be updated every 3 hours or so, and on updating the value the timer should be reset.

A further nice to have would be to also add the value to a database.

To be clear; it’s for the drinking behaviour of our newborn. Would be great to keep track of this easily and digitally :wink:

What type of value will your input be?
Is the timer for a set period or will it need to be changed regularly?

the timer can be a fixed period. from what I gathered I should be calling timer.start ?
not sure however how to use the numerical input or the counter as trigger in an automation.

So input could be either numerical or counter, but preferably both (but the counter could be increased whenever the numerical input will be done)

So, are you trying to track volume consumed, the number of feeding events, or both?

This is what I’m thinking for the automation from what you have described:

alias: Baby Feeding Counter-Timer-Notification
description: ''
mode: single
  - platform: state
    entity_id: input_number.ztest_number
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
    id: New Input
  - platform: state
    entity_id: timer.ztest_timer
    id: Timer End
    to: idle
condition: []
  - choose:
      - conditions:
          - condition: trigger
            id: New Input
          - service: counter.increment
              entity_id: counter.ztest_couter
          - service: timer.start
              duration: '03:00:00'
              entity_id: timer.ztest_timer
      - conditions:
          - condition: trigger
            id: Timer End
          - service: notify.mobile_app_chris_cell
              message: The baby's feeding timer has ended
    default: []

The most basic lovelace card that will do what you want is:

type: entities
  - entity: input_number.ztest_number
  - entity: timer.ztest_timer
  - entity: counter.ztest_couter

That’s awesome, thanks!
I’m still new to home assistant and only now found the yaml editor for the automation. This will make things so much easier :wink:

Do you know by any chance if I can have an insert into a database (script) triggered from the automation yaml as well? (so I insert the input number value along with the timestamp)

Will work from here to reset the input number after some time, and will have to figure out the notification as this isn’t working right away.
And a daily reset of the counter. fun things to fix :slight_smile:

By default, Home Assistant stores an entity’s state value in its SQLite database. You can access the database, using a compatible SQL management tool, in order to query it for whatever purpose you require.

For the notification, the service I placed is for the basic notification function of the Home Assistant Companion app. You do not have to use it. If you prefer you can use one of the other supported notification integrations.

Databases are not my forte, so I’ll leave that piece for others to answer…

One thing I might do to get all the data into one place would be to create a template sensor which updates whenever the timer is restarted like:

  - trigger:
      - platform: event
        event_type: timer.started
          entity_id: timer.ztest_timer
      - name: "Baby Feeding "
        state_class: measurement
        unit_of_measurement: "fl oz"
        icon: mdi:baby-bottle-outline
        state: >-
          {{ states('input_number.ztest_number')}}
          last_timestamp: >-
            {{ states.input_number.ztest_number.last_changed |as_local }}
          counter_value: >-
            {{ states('counter.ztest_couter')}}

That will get you a single sensor like this:

thanks again! This little use case is helpful in learning the system a bit more :slight_smile:
Got the notification to work, had the device name wrong at the start. Now need to set some exceptions/conditions that it won’t wake me up at night with a notification :slight_smile: