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:
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:
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.
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.
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.
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.
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_triggeredand 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) }}