How to tell an automation an automation has run?

TL;DR How do I write an automation that turns another automation off after it ran an hour ago?

I have been searching and trying to figure this out, but I have only found pieces that I can’t seem to make a whole out of.
What I’m trying to do is make a few automations that work together.
This is for laundry using power monitoring plugs.
I have a set for washer and dryer that send a notification after power drops below a certain level for a certain period of time. This works fine on its own, but I’m always messing with HA and restarting and this causes the automations to fire each time after I restart. I bet you can guess who in my household doesn’t like this! So I can turn them off so this doesn’t happen, but then if I turn them on before the washer/dryer are running it will go off after the time period anyway. So I made another set to turn the notify automations on if power was over a certain amount for a period of time.
So anyway I know there are multiple ways around this, but what I was trying to do is make an automation that reads when the notify automation last ran and turn it off after a time period. Let’s say an hour just for example. Not sure what event that would be though.
I thought about just turning the notify automation off inside itself after notifying, but we like to have it keep going off as the machines do the refresh thing so we are reminded to go tend to them.

Any thoughts?

Thanks

You either need to adjust your automation trigger so it doesn’t fire on a restart, or delay the automation from turning on until all your sensors have established their state.

Can you post the trigger for the troublesome automation? Maybe I can help.

trigger:
  platform: template
  value_template: "{{ ( as_timestamp(now()) - as_timestamp(state_attr('automation.the_other_automation', 'last_triggered')) |int(0) ) > 3600 }}"

You can’t use now() in a trigger and expect it to fire appropriately. It would have to be states ('sensor.date_time'). The template as you’ve written it would only be evaluated when the other automation’s state is updated, and would probably never actually fire the trigger.

Doh! I did it again. Yeah, I copied that from a condition.

Okay here is the automation for the notification of the washer being done:

- alias: Notify when washer has finished
  trigger:
    platform: numeric_state
    entity_id: sensor.washerenergy
    below: 15
    for:
      minutes: 1
  action:
  - service: notify.telegram
    data:
      message: The Washing machine has finished. 

This will repeat as our machine has a feature to keep tumbling every few mins until we get to it to keep the clothes “fresh”…so it will keep going off until we get to it.

Then the one to turn the automation on after I have manually turned it off is pretty much the opposite, but also seems to work fine:

alias: Turn On Washer Notfiy Automation
trigger:
  - above: '5'
    entity_id: sensor.washerenergy
    for: '1'
    platform: numeric_state
  condition: []
  action:
  - data:
      entity_id: automation.notify_when_washer_has_finished
    service: automation.turn_on

So I’m stuck trying to get an automation to turn off the notify automation based on the time since the completion of it. I hope that makes sense.

Thanks for the looks so far!

1 Like

Is this what you want it to do or are you trying to get it to just send one notification the first time it’s done?

If all you’re trying to do is turn the notify automation off once the washer has been off for an hour just create another automation that does just that. Also, you should add an initial_state: ‘off’ to the notify automation so it defaults to an off state on a restart (see Automation link). That will also prevent it from triggering on a restart.

- alias: Turn Off Washer Notification
  trigger:
    platform: numeric_state
    entity_id: sensor.washerenergy
    below: 15
    for:
      minutes: 60
  action:
  - service: automation.turn_off
    data:
      message: automation.notify_when_washer_has_finished

I’m not trying to have HA repeat it…it just does because the machine has a refresh thing where it continues to cycle the clothes every few mins. This causes the power usage to go up over the threshold and when it pauses the automation is true again. This is a good thing because it will keep reminding us to tend to the machine!
So nothing wrong here.

Honestly I think the initial state off is all I need.
I had a different approach in my head, but a third automation isn’t really needed. As long as it doesn’t go off when I restart HA, but it works when the machines are used all is well! For this little part of the house anyway.

Thanks for the help. Much appreciated.