I want to realise a notification when my washing machine is finished.
The notification should repeat every 30 minutes, until it is cleared.
I’ve done this with the following action-part:
- repeat:
sequence:
- service: notify.alexa_media_esszimmer_alexa
data:
message: Die Waschmaschine ist fertig
data:
type: announce
- service: notify.alexa_media_bad_alexa
data:
message: Die Waschmaschine ist fertig
data:
type: announce
- delay: "00:30:00"
until:
- condition: state
entity_id: input_select.waschmaschinenstatus
state: Idle
But now I want that the notification is only played between 7am and 11pm. But if I just add a condition at the beginning of the repeat, it will not continue on the next day.
So I need a way which skips the notification if the condition does not match but continues to the delay, that the repeat will start again.
That is a possible solution. Thank you!
At the moment I do it with a timer which starts the automation every 30 minutes.
But I was thinking of a solution inside the automation. Without any alarms, timers or any other helpers. I like to keep it simple.
- alias: 'waschmaschine_fertig_benachrichtigung'
id: waschmaschine_fertig_benachrichtigung
trigger:
- platform: state
entity_id: input_select.waschmaschinenstatus
to: Fertig
- platform: event
event_data:
entity_id: timer.waschmaschine_fertig
event_type: timer.finished
condition:
- condition: state
entity_id: input_select.waschmaschinenstatus
state: Fertig
action:
- service: timer.start
entity_id: timer.waschmaschine_fertig
- service: notify.mobile_app_suedpack_iphone
data:
message: Die Waschmaschine ist fertig
title: Waschmaschine
data:
persistent: true
tag: waschmaschine_fertig
- service: notify.wohnzimmer_firetv
data:
title: HomeAssistant
message: Die Waschmaschine ist fertig
data:
color: indigo
fontsize: large
- condition: time
after: "07:00:00"
before: "23:00:00"
- service: notify.alexa_media_esszimmer_alexa
data:
message: Die Waschmaschine ist fertig
data:
type: announce
- service: notify.alexa_media_bad_alexa
data:
message: Die Waschmaschine ist fertig
data:
type: announce
But there will be the problem when the while condition evaluates first time false, then the repeat will stop.
I want that it restarts the next day, when the washing machine isn’t cleared.
Maybe a trigger in the morning which restarts the automation could do it….
That’s the way a repeat while works. It evaluates the conditions in while before attempting the first iteration and before all subsequent iterations. As long as the conditions evaluate to true it will continue repeating and will stop (and exit the repeat) when they evaluate to false.
Once a repeat exits it never restarts. It’s the responsibility of the automation’s trigger to execute the action containing the repeat.
What I proposed will send a notification every 30 minutes as long as waschmaschinenstatus is not Idle and the current time is within the range of 07:00 to 23:00.
Ok, got it. Thought there could be a solution inside the repeat.
My old solution let the automation run continously till the machine is cleared. But keeps the alexa notification silent between 7-23.
So I will change the automation to a repeat which runs only when waschmaschinenstatus is not idle and current time is betweend 7-23. And let the automation restart with a time trigger at 7am, then check if the waschine is still not idle.
So this automation will run every morning at 7am in contrast to the old automation which runs the whole night till the machine is cleared. But I dont need the timer. And the while-repeat saves a few lines of code compared to the old automation.
Both ways are functional, but I wanted to save the timer, and so I do.
- alias: "waschmaschine_fertig_benachrichtigung"
id: waschmaschine_fertig_benachrichtigung
trigger:
- platform: state
entity_id: input_select.waschmaschinenstatus
to: Fertig
- platform: time
at: "07:00:01"
condition: "{{ states('input_select.waschmaschinenstatus') != 'Idle' }}"
action:
- repeat:
while:
- "{{ states('input_select.waschmaschinenstatus') != 'Idle' }}"
- "{{ 7 <= now().hour < 23 }}"
sequence:
- service: notify.mobile_app_suedpack_iphone
data:
message: Die Waschmaschine ist fertig
title: Waschmaschine
data:
persistent: true
tag: waschmaschine_fertig
- service: notify.alexa_media_esszimmer_alexa
data:
message: Die Waschmaschine ist fertig
data:
type: announce
- service: notify.alexa_media_bad_alexa
data:
message: Die Waschmaschine ist fertig
data:
type: announce
- delay: "00:30:00"