Send message only when last message has been sent longer than 30 minutes

I have a tumbler which dries my laundry. I check with a smart plug if the power is below 10 watt to know that the program has been finished and to send a message to the smartphone. The issue is that the tumbler has a routine to rotate the tumbler drum every 2 minutes to keep the laundry wrinkle-free. This send then the message again if the motor stops and the power is below 10 watt. How can I extend my yaml code, that a message will be sent only when the last message has been sent longer then 30 minutes to prevent sending tons of the same messages?

“Code start:”
alias: Benachrichtigung wenn Tumbler fertig
description: “”
triggers:

  • type: power
    device_id: a8fdeccaf24d992b333834ccf2ed9f53
    entity_id: ecf29025e8e8d65b28538fed4924af16
    domain: sensor
    below: 10
    trigger: device
    conditions:
    actions:
  • data:
    message: Wäsche aus Tumbler nehmen
    title: Tumbler ist fertig
    action: notify.mobile_app_cmr_al19
  • data:
    message: Wäsche aus Tumbler nehmen
    title: Tumbler ist fertig
    action: notify.mobile_app_sm_g990b
  • data:
    message: Wäsche aus Tumbler nehmen
    title: Tumbler ist fertig
    action: notify.mobile_app_sm_a725f
    mode: single
    “Code end:”

Best regards,
Chris

f6be36681e0da431418ec7781fb6c62712941803

Hi digeridrew,

many thanks for your reply, I need a timer who checks If my last trigger has been fired longer than 30 minutes, to send a new message again. Your proposal checks another trigger regarding HA restart. I don’t know how this might help in my scenario. It would be helpful if the additional code needed can be added directly to my yaml code. Thank you

Can you add actions at the end of your automation that disables the same automation for 30 minutes and then re-enables it? Then maybe use @Didgeridrew’s approach to re-enable the automation at HA start.

Or better yet, do a single mode automation that includes a 30 minute delay at the end of its actions? Example from the docs:

automation:
  - mode: single
    max_exceeded: silent
    triggers:
      - ...
    actions:
      - ...
      - delay: 300  # seconds (=5 minutes)

An automation which disables itself is a bad idea. You will need a separate automation to re-enable it, since it can’t re-enable itself if it’s disabled.

Ya, was unsure of the whole action sequence would commit to complete. Wasn’t in the position to check when I posted.

Can you give me please an instruction step by step what I need to configure to reach my goal? I’m quite new in yaml and are not able to follow you. Thank you.

Add the mode, the max_exceeded and the delay lines from the below to the appropriate portions of your yaml. Adjust the delay as needed.

automation:
  - mode: single
    max_exceeded: silent
    triggers:
      - ...
    actions:
      - ...
      - delay: 300  # seconds (=5 minutes)

Or, post your yaml preformatted and others can help modify/improve/correct it.

If you want to trigger an automation 30 minutes after it was last triggered, you can add this trigger:

  - trigger: template
    value_template: >-
      {{ now() -
      state_attr('automation.my_automation_name',
      'last_triggered') > timedelta(minutes=30) }}

However you’ll also need a condition to check if the notification should still be sent. That condition should be the same as the trigger that you already have.

Ok I did add the code to yaml, is this correct the way I did configure it?

alias: Tumbler fertig inkl. 30 Min Delay
description: ""
triggers:
  - type: power
    device_id: a8fdeccaf24d992b333834ccf2ed9f53
    entity_id: ecf29025e8e8d65b28538fed4924af16
    domain: sensor
    below: 10
    trigger: device
  - value_template: >-
      {{ now() - state_attr('automation.Tumbler fertig inkl. 30 Min Delay',
      'last_triggered') > timedelta(minutes=30) }}
    trigger: template
conditions: []
actions:
  - data:
      message: Wäsche aus Tumbler nehmen
      title: Tumbler ist fertig
    action: notify.mobile_app_cmr_al19
  - data:
      message: Wäsche aus Tumbler nehmen
      title: Tumbler ist fertig
    action: notify.mobile_app_sm_g990b
  - data:
      message: Wäsche aus Tumbler nehmen
      title: Tumbler ist fertig
    action: notify.mobile_app_sm_a725f
mode: single

2nd: How do I configure the needed condition?

Here is example yaml for an automation that notifies no more than once per 30 minutes as soon as power goes below 10w. Adjust your entity id and notification action as necessary.

triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.esphome_power
    below: 10
actions:
  - action: notify.pushover
    data:
      message: Cycle Complete
  - delay:
      minutes: 30
mode: single
max_exceeded: silent

The concept is it takes 30 minutes to complete the automation and only one instance of the automation is allowed to run.

Why? That’s just going to be another entity you need to create and another process you need to manage. Does it need to be exactly 30 minutes? If not, the dryer’s “anti-wrinkle” cycles are going to happen anyway, use it’s reoccurrence as your “about 30 minutes timer”.

The linked Template condition has nothing to do with HA restart.

The last_triggered property of an automation’s state is only updated when an automation triggers and conditions in the conditions block all pass. The template condition I provided in the link therefor prevents the update of last_triggered and prevents the notifications from being played again until the time threshold has been exceeded.

The variable this is HA’s self-referencing variable. In this scenario it holds the state object of the automation itself. So, it is the nearly the same functionality as what Rick shared with his trigger suggestion. But this way won’t require additional conditions to check if the dryer has already been dealt with since those power-based events won’t be occurring.

It would be helpful if your code was properly formatted. Please follow Community Question Guideline #11 by properly formatting you configuration code. This is important to avoid errors that can be caused by the copy/paste process.

conditions:
  - alias: Check if it has been at least 30 minutes since this automation's action block was last run.
    condition: template
    value_template: |  
      {% set last_run = this.attributes.last_triggered|default(as_datetime(0),1) %}
      {{ now() >=  last_run + timedelta(minutes = 30) }}