Trigger automation if action not seen in N hours

I have an Aqura vibration sensor attached to my sump pump. Each time it runs, it increments a counter so I can see how many times it runs per day, and how long it’s been since it last run. I want to add an automation that triggers if the sump pump has not run in N hours (something like 4 hours). How can I do this?

Bob

An easy way would be to use a State Trigger.

alias: example
trigger:
  - platform: state
    entity_id: switch.sump_pump
    from: 'on'
    to: 'off'
    for:
      hours: 4
condition: []
action:
  ... your actions ...

It will trigger when the switch is off for 4 consecutive hours. Its countdown is reset whenever the switch turns on.

The drawback of this technique is that a restart, or Reload Automations, will also reset the countdown. If that’s a deal breaker then you will need to use a polling technique (say every 5 minutes) that checks the switch’s last_changed property to determine how long it’s been in the off state`.

Thanks, state trigger seems to be what I’m looking for.

What about an input_number for the for option?

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.