Stopping Automation Triggers on HA Restart

I currently have an automation based on the current power being drawn from a plug. Once this power drops below a certain level for 2 minutes it triggers my automation.

When restarting HA this automation gets triggered after the 2 minutes as if it had never been triggered before, even though power draw is still below the treshold.
I have a number of other automations to make that will also get hit by this rule. How do i go about stopping them getting triggered when HA is restarted?

I’ve seen the initial_state variable, but even if i have it disabled for the trigger time it’s surely going to re-trigger once HA enables it again?

What’s the right way to do this?..

Thanks

- id: '1602094314727'
  alias: Washing Machine Done
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.washing_machine_plug_watts
    below: '1'
    for: '2'
  action:
  - service: notify.notify
    data:
      message: Time to empty!
      title: Washine Machine Cycle Finished
  mode: single
1 Like

Let’s see the automation.

Add an Uptime sensor.

Then add a condition to your automation:

- id: '1602094314727'
  alias: Washing Machine Done
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.washing_machine_plug_watts
    below: '1'
    for: '2'
  condition:
  # no trigger after HA restart
    - condition: numeric_state
      entity_id: sensor.minutes_online
      above: .25
  action:
  - service: notify.notify
    data:
      message: Time to empty!
      title: Washine Machine Cycle Finished
  mode: single

I can’t guarantee this is the best solution, but I’ve used it.

p.s. I didn’t get notified when you edited your post.

What you have in that trigger is 2 seconds. Try this.

    below: '1'
    for: 
      minutes: '2'

It will still trigger after a restart, just two minutes later now.

OP was asking how to prevent a trigger from occurring as a result of restart.

I know that, and your solution will work. I was just pointing out that he does not have the trigger he thinks he has.

I’d be interested to know if this would work

Afraid i’ve tried that, but it just means it’s delayed from the original time by 2.5 minutes.

Now this was my first thought on how to do it, but couldn’t figure out how to track it’s previous state. Now i’m aware of trigger.from_state i’ll have a play and see if i can get it tracking, thanks.

I would suggest:

    - condition: template
      value_template: {{ (trigger.from_state.state) not in ['unknown', 'unavailable', 'None'] }}
1 Like

Thanks,

Now this is what I originally though to do it with, but couldn’t figure out the logic for in HA. Having just tested it i’m surprised to see it hasn’t worked.

I’m wonderig if this is something to do with the entity i’m using, i’m scraping stats from the TP-Link Kasa plug as documented here - https://www.home-assistant.io/integrations/tplink/

Could it be something to do with the template sensor?
Current automation:

- id: '1602094314727'
  alias: Washing Machine Done
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.washing_machine_plug_watts
    below: '1'
    for: 0:02:00
  condition:
  - condition: template
    value_template: '{{ (trigger.from_state.state) not in [''unknown'', ''unavailable'',
      ''None''] }}'
  action:
  - service: notify.notify
    data:
      message: Time to empty!
      title: Washine Machine Cycle Finished
  mode: single

Remove the parentheses.

  condition:
  - condition: template
    value_template: '{{ trigger.from_state.state not in [''unknown'', ''unavailable'',
      ''None''] }}'

No joy i’m afraid! Latest revision below.

- id: '1602094314727'
  alias: Washing Machine Done
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.washing_machine_plug_watts
    below: '1'
    for: 0:02:00
  condition:
  - condition: template
    value_template: '{{ trigger.from_state.state not in [''unknown'', ''unavailable'',
      ''None''] }}'
  action:
  - service: notify.notify
    data:
      message: Time to empty!
      title: Washine Machine Cycle Finished
  mode: single

I just had a look how I do this. No false triggers from:

Binary sensor:

- platform: template
  sensors:
    washing_machine_running:
      friendly_name: Washing Machine Running
      value_template: "{{ states('sensor.washing_machine_power')|float(default=0) > 2.5 }}"
      device_class: moving
      delay_off:
        minutes: 1

Automation:

- alias: 'Washing Machine Finished'
  trigger:
    platform: state
    entity_id: binary_sensor.washing_machine_running
    to: 'off'
  action:

Based on HA code changes, the best way to accomplish is using the uptime integration and template conditions. The uptime integration was changed in 2020.12 from storing minutes to starting a static datetime, so you now need to create your own sensor or a template to get the minutes of uptime.

This code can be added as a template in conditions:

{{ as_timestamp(now()) - as_timestamp(states.sensor.uptime.last_changed) |
int > 120 }}

where 120 is how many seconds after restart you want to ignore triggers.

Here is a thread on Condition Uptime to see examples of the correct syntax and usage.