Automation when switch is turned of after duration

Hi, I would like to fire an action when a switch is turned of, but only if it was ON before for 1 hour.

This one doesnt work:

alias: Test - Neue Automatisierung
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.testschalter
    from: "on"
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 0
    id: stromverbrauch.hoch
condition:
  - condition: state
    entity_id: input_boolean.testschalter
    state: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 10
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.waschmaschine_fertig
mode: single
alias: Test - Neue Automatisierung
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.testschalter
    from: "on"
    to: "off"
    id: stromverbrauch.hoch
condition:
  - condition: template 
    value_template: "{{ now() - trigger.from_state.last_changed > timedelta(seconds=10) }}"
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.waschmaschine_fertig
mode: single

After testing it you can change timedelta(seconds=10) to timedelta(hours=1) to meet your original requirement.

1 Like

Thank you, that works perfect!

So

is the time when input_boolean.testschalter switched from off to on, correct?

1 Like

Yes, you’re correct.

1 Like