Automation condition that checks if a state changed in the last X mins

Wondering if there’s a condition that will check if a state changed to “X” in the last “X” mins? Not a “for” condition as that will only trigger when “x” mins has passed.

What I’m basically trying to do is check if a users presence changed in the last 30mins…

As an example:

  • alias: Telegram Bot - House is Empty (Mike)
    initial_state: ‘on’
    trigger:
    platform: state
    entity_id: group.household
    to: ‘off’
    condition:
    condition: and
    conditions:

    Check if a House Mode has already been set manually

    • condition: state
      entity_id: input_boolean.away_mode
      state: ‘off’
    • condition: state
      entity_id: input_boolean.mike_home
      state: ‘off’
      In_last:
      ** Minutes: 10**
      action:
    • service: notify.telegram
      data:
      message: “Mike Looks like no one is home. How long will you all be gone?”
      data:
      inline_keyboard:
      - “Back Later Today:/away, Day or More:/holiday”
      - “I’m at Home!:/home”

Sorry if formatting is screwed on my post. Posting from a mobile on a train :slight_smile:

Only way I can think of doing this is to create a template sensor that changes state for 30mins when the users input_boolean changes to off and then use the state of that template sensor as the condition.

Appreciate someone’s help. Many thanks :slight_smile:

Just stumbled across this as I was looking at doing something similar. I know this is a very old post, but in case its helpful.

I think something along the lines of this would work?

  condition: and
  conditions:
    - condition: state
      entity_id: input_boolean.entity_id_being_monitored
      state: 'off'
    - condition: template
      value_template: "{{ (as_timestamp(now()) - as_timestamp((states.input_boolean.entity_id_being_monitored.last_updated)) <600)}}"`
11 Likes