Time based notification

Hi,
I got this component installed that tells me when my trash is being picked up. But I can’t seem to find any way to make an automation with this info, as the timestamp is a state, and not an attribute.

I would like to get a notification in the morning if todays date and the pickup date from the sensor is the same. Does anyone have any tips for how this can be done?

Thanks!

One option is to use a Template trigger, you can set the time the notification will fire by changing the values in the replace function for hour and minute (the example below will trigger at 07:00 on the day from the sensor) :


trigger:
  - platform: template
    value_template: >-
      {% set x = states('sensor.papir') %}
      {{ now() >= now().replace(day=x[:2]|int, month=x[3:5]|int, hour=7, minute=0) }}

One caveat, the time at which your sensor state updates could make this template unusable. For example, if the sensor updates at 01:00 on 1/4/22 you would need to use a different method, like saving the date information in a datetime helper.

You may use time trigger smth like:

trigger:
  - platform: time
    at: "00:01:00"
conditions: > 
  {{ states('sensor.papir')|str = now().strftime('%s')|timestamp_custom('%d/%m/%Y')|str }}
action:
  - service: notify.....
:

The sensor updates the time at 00:00, but I would like to get the notification at 7 in the morning, so that might be another problem.

In that case I would at say noon the day before set a boolean to on.
Then at midnight the sensor has a new value.
But the boolean is still on, and then we use a time trigger at 7:00 to notify with condition boolean is on.
And switch off boolean after notify

Template to see if it’s tomorrow (condition):

{{ states('sensor.papir') == as_timestamp(now() +timedelta(days=1)) | timestamp_custom('%d/%m/%Y') }}

Because of the way my garbage collector does holidays, I have my garbage collection template sensor set to calculate/update at midnight every Sun and then save the value to an Input Datetime helper. You could do something similar…

trigger:
  - platform: time
    id: set helper
    at: "00:00:00"
  - platform: time
    id: notify
    at: input_datetime.papir_notification
condition: []
action:
  - variables:
      notification_time: >
        {% set x = states('sensor.papir') %}
        {{ now().replace(day=x[:2]|int, month=x[3:5]|int, hour=7, minute=0) }}
  - choose:
      - conditions:
          - condition: trigger
            id: set helper
          - condition: time
            after: '00:00:00'
            weekday:
            - sun
        sequence:
          - service: input_datetime.set_datetime
            target:
              entity_id: input_datetime.papir_notification
            data:
              datetime: "{{ notification_time }}"
      - conditions:
          - condition: trigger
            id: notify
        sequence:
          - service: notify.XXXX
            data: {}
    default: []

This turned out to work work perfectly. Thanks!

1 Like