Drink Water Reminder & Tracker (via helpers)

I know I’m not alone in forgetting to drink water sometimes (I’m looking at you, fellow ADHD friends). So in the spirit of better health, I decided to automate a bit of my daily life with a regular reminder to drink water, when it’s been a while.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

The basic premise is there is a date/time helper to track the last time you’ve drank water. After a configurable number of hours, you’ll get a notification to drink water. You can update the tracker right from the notification, or snooze it to be reminded later. You can set how long it is until you’re notified, and optionally get notified every subsequent hour until the tracker is updated. You can also configure during what times during the day notifications will be sent.

To use this blueprint you’ll need a few things:

  1. A mobile device running the Home Assistant app.
  2. Create a “Date and/or time” helper set to “Date and Time”.
  3. Create a button helper (to manually trigger the automation).
  4. Create a timer helper, set to the duration you wish your snooze time to be. 10-30 minutes is recommended. Can’t be longer than 59 minutes.

If you want to get even fancier and have an NFC tag to scan on your water bottle, or any other trigger you can dream up, just create another automation with the NFC tag as a trigger. In the actions, create a service call to Input Button: Press and select the button helper you created in step 3. Or add a button widget to your phone’s home screen.

Screenshot_20230401-011457

This is my first blueprint. Please let me know if you have any feedback. I hope this is able to help others with their mental and physical health. :slight_smile:

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Drinking Water Tracker & Reminder
  description:
    "Track your water drinking and remind yourself when you haven't for
    a while. This blueprint requires you to create 3 input helpers: Date & Time, Button,
    and Timer."
  source_url: https://gist.github.com/djahren/322ce13a857b2099956429005669fe4a
  domain: automation
  input:
    notify_device:
      name: Device to notify
      description:
        Device needs to run the Home Assistant app to receive actionable
        notifications.
      selector:
        device:
          integration: mobile_app
          multiple: false
    last_drank_helper:
      name: Date and Time Helper
      description:
        Create a Date and Time helper to track the last time you drank
        water.
      selector:
        entity:
          domain: input_datetime
          multiple: false
    drank_water_button_helper:
      name: Drank Water Button Helper
      description:
        "Create a button helper to press indicating you've drank water.
        This can also be added as a widget on your phone's home screen.

        To create more triggers (such as an NFC tag on your water bottle), create
        a new automation with your desired triggers and use the Call Service action,
        calling the Input Button: Press service."
      selector:
        entity:
          domain: input_button
          multiple: false
    snooze_timer_helper:
      name: Snooze Timer Helper
      description:
        Create a timer helper that is set to the duration you'd like to
        snooze notifications for. Reccomended between 10 and 30 minutes.
      selector:
        entity:
          domain: timer
          multiple: false
    reminder_delay:
      name: Reminder Delay
      description: Number of hours after drinking water to send a reminder.
      default: 4
      selector:
        number:
          min: 1.0
          max: 12.0
          mode: slider
          step: 1.0
    repeat_every_hour:
      name: Repeat Every Hour
      description:
        This will repeat a reminder every hour (between the times specified
        below) until the water tracking helper is updated. This won't create multiple
        notifications, only update an existing one.
      default: true
      selector:
        boolean: {}
    reminder_start_time:
      name: Reminder Start Time
      description: Don't send reminders before this time.
      default: "10:00"
      selector:
        time: {}
    reminder_end_time:
      name: Reminder End Time
      description: Don't send reminders after this time.
      default: "22:00"
      selector:
        time: {}
mode: parallel
max_exceeded: silent
trigger:
  - platform: state
    entity_id:
      - !input drank_water_button_helper
    id: button
  - platform: time_pattern
    minutes: "*"
    id: every_minute
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      tag: drink-water-reminder
    id: notification_action
  - platform: state
    entity_id:
      - !input snooze_timer_helper
    to: idle
    from: active
    id: timer_end
variables:
  last_drank_helper_id: !input last_drank_helper
  reminder_delay: !input reminder_delay
  repeat_every_hour: !input repeat_every_hour
  timer_helper: !input snooze_timer_helper
  uid: "{{ this.entity_id.split('.')[1].upper() }}"
  drank_water_action: DRANK_WATER_{{ uid }}
  water_snooze_action: WATER_SNOOZE_{{ uid }}
  action:
    "{{ trigger.event.data.action if trigger.id == 'notification_action' else
    ''}}"
  snooze_minutes:
    snooze_minutes: '{{ state_attr(timer_helper, "duration").split(":")[1] }}'
  run_reminder:
    "{% set delay = reminder_delay|int %}{% set repeat = repeat_every_hour|bool
    %} {% set time_since = now().replace(tzinfo=None) - (states(last_drank_helper_id)
    | as_datetime).replace(tzinfo=None) %} {% set hours_ago = time_since.seconds //
    3600 + time_since.days * 24 %} {% set remaining_minutes = time_since.seconds //
    60 %} {% if hours_ago < delay %}off{% else %} {{ remaining_minutes % 60 == 0 and
    (repeat or (not repeat and hours_ago == delay)) }} {% endif %}"
condition:
  - condition: template
    value_template: '{{ trigger.id != "every_minute" or run_reminder }}'
action:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: and
                conditions:
                  - condition: trigger
                    id: every_minute
                  - condition: template
                    value_template: "{{ run_reminder }}"
                  - condition: time
                    after: !input reminder_start_time
                    before: !input reminder_end_time
              - condition: trigger
                id: timer_end
        sequence:
          - type: notify
            domain: mobile_app
            device_id: !input notify_device
            message:
              You last drank water {{ states(last_drank_helper_id) | as_datetime
              | relative_time}} ago. Drink more now?
            data:
              tag: drink-water-reminder
              actions:
                - action: "{{ drank_water_action }}"
                  title: "I drank some! \U0001F4A7"
                - action: "{{ water_snooze_action }}"
                  title: Snooze ({{snooze_minutes}}m)
      - conditions:
          - condition: template
            value_template: "{{ action == water_snooze_action }}"
        sequence:
          - service: timer.start
            data: {}
            target:
              entity_id: !input snooze_timer_helper
      - conditions:
          - condition: or
            conditions:
              - condition: trigger
                id: button
              - condition: template
                value_template: "{{ action == drank_water_action }}"
        sequence:
          - service: input_datetime.set_datetime
            data:
              timestamp: "{{as_timestamp(now())}}"
            target:
              entity_id: !input last_drank_helper
          - type: notify
            domain: mobile_app
            device_id: !input notify_device
            message: clear_notification
            data:
              tag: drink-water-reminder
7 Likes

Was literally searching this past month for something like this! Thank you so much for the generous offer to the community!

2 Likes

I’m so glad you find it useful, that was my hope. I’ve just setup another automation to message my partner on Telegram if my water tracker gets too out of date for accountability. :sweat_smile:

1 Like

Just noticed the automation doesn’t trigger at all, is there a step I’m skipping? :thinking:

I’m going to need more information than that. Can you edit your automation with the blueprint, choose Edit in YAML from the menu and paste the YAML here? Is there any info in Traces for the automation?

No traces since the automation never triggered. Even tried modifying the helpers manually.
Here is the yaml file, I’ve created an automation from your blueprint:

alias: Drink water test
description: ""
use_blueprint:
  path: djahren/drink_water_reminder.yaml
  input:
    notify_device: 765bafcd59838810f3ec22328592bf8f
    last_drank_helper: input_datetime.drink_water_last
    drank_water_button_helper: input_button.drink_water_trigger
    snooze_timer_helper: timer.drink_water_snooze

Hmmm, how about if you press your “drink water trigger” button?

Pressed that in various combinations of date, time, snooze button etc.

Same issue here, never fires

1 Like

Cool blueprint. And better then all reminder app’s there out that are limited customizable.
I’m a person that drinks waaaaaay to less water a day. and i’m a serious home assistant user. So i try if i can modify for the things i would like to have as extras.

I got some extra idea’s:
Sleep sensor:
I would like to make this reminder not remind me when i’m sleeping. My Home assistant has a sleep tracker (On/Of) and i want to replace the fixed time.

Amount of water drank
I would love the idea that you can change the water amount we drank every time. And a setting that tells you how much you need to in a day, and stops the notify when reached.

Sporting = extra water needed.
There is a option to connect Home assistant to Garmin, This should tell you how much water you lost in the latest activity. This amount should be added on your daily water needs as suggested above.

I’m also doing bodybuilding. So this sensor could also be converted to insert a protein shake after workout, and a micelar shake before going to sleep the day a workout is completed…

Ideas, ideas, ideas…

Edit: The automation never triggered here to. investigating if i can find the problem…

There is a enter in the line:

            message:
              You last drank water {{ states(last_drank_helper_id) | as_datetime
              | relative_time}} ago. Drink more now?

maybe that is the error? should be:

            message:
              You last drank water {{ states(last_drank_helper_id) | as_datetime | relative_time}} ago. Drink more now?

Love it! And as a fellow ADHDer, I too often forget to drink during the day, so I built a workflow to use an actionable notification on my phone (the intent to log whether I did or didn’t drink, but I never finished that part - typical lol!), but this one also sends me an audio notification depending on which room I’m working from at the time.
Because my colleagues found the notification funny whenever they were on a call with me (which has in fact resulted in them all drinking more as well), I decided to incorporate my Teams presence into it so a different message plays if I’m on a call or in a meeting.

Enjoy!

alias: LORYAN - Water reminder
description: ""
trigger:
  - platform: time
    at:
      - "10:00:00"
      - "11:00:00"
      - "12:00:00"
      - "13:00:00"
      - "14:00:00"
      - "15:00:00"
      - "16:00:00"
      - "17:00:00"
condition:
  - condition: device
    device_id: 8bfc0976a96b7489154f5856e265422a
    domain: device_tracker
    entity_id: device_tracker.loryan_s_s21
    type: is_home
  - condition: state
    entity_id: binary_sensor.workday_sensor
    state: "on"
action:
  - if:
      - condition: state
        entity_id: sensor.loryan_actual_location
        state: Study
    then:
      - if:
          - condition: state
            entity_id: sensor.teams_status
            state: InACall
        then:
          - service: notify.alexa_media_study_echo
            data:
              message: >-
                Loryan, drink some water. And whoever is in the meeting with
                Loryan, you should probably drink some water as well.
              data:
                type: tts
        else:
          - service: notify.alexa_media_study_echo
            data:
              message: Loryan, drink some water
              data:
                type: tts
      - service: script.loryan_hourly_drink_check_in
        data: {}
  - if:
      - condition: state
        state: Garage
        entity_id: sensor.loryan_actual_location
    then:
      - if:
          - condition: state
            entity_id: sensor.teams_status
            state: InACall
        then:
          - service: tts.google_cloud_say
            data:
              cache: false
              entity_id: media_player.garage_play_1
              message: >-
                Loryan, drink some water. And whoever is in the meeting with
                Loryan, you should probably drink some water as well.
        else:
          - service: tts.google_cloud_say
            data:
              cache: false
              entity_id: media_player.garage_play_1
              message: Loryan, drink some water
      - service: script.loryan_hourly_drink_check_in
        data: {}
    else: []
mode: restart

1 Like

The biggest issue is that regardless of reminders - I’m still not drinking enough water. I’m seriously considering getting one of those bottles that has water level tracking in it, but only if there was a way to connect it to HA.

There ist one hardcoded helper in the Script so the Script ist Not fired.

When we Change Line 112:

snooze_minutes: '{{ state_attr("timer.abj_water_snooze", "duration").split(":")[1]}}'

To this one:

timer_helper: !input snooze_timer_helper
  snooze_minutes: '{{ state_attr(timer_helper, "duration").split(":")[1] }}'

Then the Script works perfectly.

Apologies all for the delay in updating this - I feel bad for dropping something that doesn’t work and then being unavailable. I moved halfway across the country so this hasn’t been a top priority.

Thank you so much @Kotarou for finding the fix! I’ve implemented this fix and tested it over the last day on a new installation (woo new smart home). Please let me know if anything else is amiss.

Hi,
Thanks for the blueprint.
It does not working for me in the latest version of hime assistant, i dont know if they changed something in the schema.
It would be great if this can be checked on version 2023.9.2

Ori

Hi @oriziv5, this is working for me in 2023.9.2 - in fact, I just got a notification moments ago. Was this working for your previous to updating? Can you please provide info from your traces for this automation? And filter your logs for anything regarding the drink water automation to post any relevant logs here?

I managed to get this working.
It seems that my device name as defined in the IOS itself was different than the device name as defined in the companion app, and that caused the issue.
other than that - i suggest you update your BP code and use “filter” to avoid using deprecated integration sub schema.

selector: device: filter: integration: mobile_app

instead of

selector: device: integration: mobile_app

Thanks for this work!