Help setting up a daily notification

I have searched all afternoon for figuring this out and haven’t gotten anywhere! I have an ultrasonic sensor measuring the salt level in my water softener. I want to get a daily notification when it reaches a low level and a different one if it’s empty. I have two binary sensors setup for when these conditions are met, i can’t figure out how to get the notifications to come through daily.

If you want this notification only once per day, make a binary_input that is turned on at the first notification.
Then make the binary_input a condition in your notification automation.

Another automation turns the binary input off at midnight, or whenever you want your day to end

1 Like

Make your trigger a daily time, see https://www.home-assistant.io/docs/automation/trigger/#time-pattern-trigger

Make the condition that the sensor is either low or empty. https://www.home-assistant.io/docs/scripts/conditions/#or-condition

Make the action to send a notification of the state of the sensor.

It will look something like this


trigger:
  platform: time
    # Military time format. This trigger will fire at 3:32 PM adjust to what time suits you.
  at: "15:32:00"

condition:
  condition: or
  conditions:
    - condition: state
      entity_id: 'sensor.salt'
      state: 'low'
    - condition:  state
      entity_id: 'sensor.salt'
      state: 'empty'
action:
      - service: notify.notify
        data:
          message: Salt needs attention.

The message could be templated to say “Salt is low” or “Salt is empty” - that is left as an exercise for someone who hasn’t had a bottle of wine yet!

I’d combine @jivesinger and @nickrout approaches because the time alone might not work if HA is not working at that specific point of time (reboot/stop etc).
So adding another trigger (homeassistant: start) and accounting for input_boolean (actually, counter might do the job better?) looks the way to go for me (haven’t tried it yet though).

UPDATE: I have even better idea - input_datetime. no need to reset it, just check.

Here is the code

input_datetime:
  last_notification_sent:
    has_date: true


automation:
  - alias: notify_on_salt_level
    trigger:
      - platform: time
        at: "15:32:00"
      - platform: homeassistant
        event: start

    condition:
      condition: template
      value_template: >
        {{
          not is_state_attr('input_datetime.last_notification_sent', 'day', now().day) and
          (is_state('sensor.salt', 'low') or is_state('sensor.salt', 'empty'))
        }}
        
    action:
      - service: notify.notify
        data_template:
          message: >
            Salt is {{ states('sensor.salt') }}.
      - service: input_datetime.set_datetime
        data_template:
          date: "{{ now().strftime('%Y-%m-%d') }}"

That’s to start with. Try it and let us know if it does the job.

UPDATE: forgot to set a new date after sending notification (and the original condition didn’t have not). Fixed now :wink:

1 Like

good point.

Nice !

Don’t forget to reset your counter at midnight :wink:

I have a better idea, see the update :wink:

This worked quite well! It notifies at the specific time and when HA starts. I just have to wait until tomorrow to see how the notifications repeat. I definitely appreciate the help!

Good stuff. Let me know if it works and I’ll add it to my setup as well as I always wanted something like that :wink:

So this morning came and went but I did not get a notification. I opened the automation yaml and noticed some odd characters that I didn’t notice before. There were periodic /n that must’ve popped in when I pasted and saved the automation script. I’ve updated it and will check back tomorrow to give another update.

still nothing? :wink:

Anyway, I’d recommend to have a yaml syntax checker so you’ll immediately see if something is wrong with your config.
And don’t forget to check config before reloading HA.

thanks

for futur readers
your code is incomplete, input_datetime entity_id is missing

      - service: input_datetime.set_datetime
        entity_id: input_datetime.last_notification_sent
        data_template:
          date: "{{ now().strftime('%Y-%m-%d') }}"