Detect if state has not changed for x minutes

I have an LG washing machine where the countdown timer on some occasions gets stuck on the same time for any amount of time without notifying me. E.g washer says 6 minutes until it finishes but in reality it keeps going “infinitely”

How can I detect if state is above 0:00:00 and at the same time the x remaining time state is not longer than e.g 5 minutes?

Edit: Using this template seems to solve this question. (Trigger automation if no state update for x minutes - #23 by Oliviakrk)

It requires to enable the Time & Date - Home Assistant integration

platform: template
value_template: >-
  {% if as_timestamp(states.sensor.time.last_updated) -
  as_timestamp(states.sensor.lg_pracka_f2wv9s8p2_remaining_time.last_updated) >
  5*60 %}true{% endif %}

Full automatization:

alias: LG Washer stuck countdown
trigger:
  - platform: template
    value_template: >-
      {% if as_timestamp(states.sensor.time.last_updated) -
      as_timestamp(states.sensor.lg_pracka_f2wv9s8p2_remaining_time.last_updated)
      > 5*60 %}true{% endif %}
condition:
  - condition: state
    entity_id: sensor.lg_pracka_f2wv9s8p2
    state: "on"
action:
  - service: notify.alexa_media_echo_dot_gen_4
    data:
      message: "Washing machine countdown timer is stuck"
mode: single

To check if the template condition is evaluated, you should put it in the Developer Tools > Template.
On the right, you’ll see when the template is evaluated.

image

I’d rather do

trigger:
  - platform: template
    value_template: >-
      {{ ( now() | as_timestamp() - states['sensor.lg_pracka_f2wv9s8p2_remaining_time'].last_updated | default(0,true) | as_timestamp() | default(0,true)) > 5*60 }}

The use of now() in the trigger will ensure that it is evaluated at the start of each minute

EDIT: Then add a condition like

condition:
  - condition: and
    conditions:
    - condition: state
      entity_id: sensor.lg_pracka_f2wv9s8p2
      state: "on"
    - condition: template
      value_template: " {{ states('sensor.lg_pracka_f2wv9s8p2_remaining_time') > '00:00:00' }} "

Interesting solution, thanks for that!

I’ve just tested both templates side by side and they both trigger at the start of each minute. There shouldn’t be any difference running one template against other.