Trigger Automation on did come home in last 5 minutes

Hi :slight_smile: I am new to HA and I would like to create an Automation that triggers only if I arrived at home in the last 5 minutes.

I‘m using a fritzbox to track that my phone connected to the wifi as a devicetracker.

As trigger I‘m using a vibration sensor on the door, which changes the state if vibration is encountered.

It seems I can‘t get the condition to work.

I did a lot of research but i can‘t figure out how to set up the condition to only do something if I arrived recently at home.

Does anyone have an idea how to solve it?
Best regards :slight_smile:

You could do something like this:

automation:
- alias: "Just arrived home"
  trigger:
  - platform: state
    entity_id: device_tracker.your_phone
    to: 'home'
  condition:
  - condition: not
    conditions:
    - condition: state
      entity_id: binary_sensor.door_vibration
      state: 'off'
      for: '00:05:00'
  action:
  ...

When your phone is detected as arriving home it will check to see if the door sensor has been off for no more than 5 minutes. The state will either have to be on or it will have been off for less than 00:05:00.

Thank you for your answer.

Wouldn‘t that mean that the sensor needs to be triggered before the state of the tracker changes to home? The phone connects to the wifi way sooner that I can trigger the vibration sensor

So add some more logic :wink:

automation:
- alias: "Just arrived home"
  trigger:
  - platform: state
    entity_id: device_tracker.your_phone
    to: 'home'
  - platform: state
    entity_id: binary_sensor.door_vibration
    to: 'on'
  condition:
  - condition: not
    conditions:
    - condition: state
      entity_id: binary_sensor.door_vibration
      state: 'off'
      for: '00:05:00'
  - condition: state
    entity_id: device_tracker.your_phone
    state: 'home'
  - condition: not
    conditions:
    - condition: state
      entity_id: device_tracker.your_phone
      state: 'home'
      for: '00:05:00'

  action:
  ...

Now it will run when either:

  1. The door opens and you have been home for less than 5 minutes
  2. You are detected as home and the door is currently open, or has been closed for less than 5 minutes

So I figured something out now. It isn‘t the best solution but it works. I tried yours but for some reason it didn‘t really work.

I created one Automation, which starts a script when my phone gets detected. The script sets a inlit boolean to true for 5 Minutes and than turn it back off again.

Another Automation will trigger by the sensor but only if the input boolean is on

Nice, this is what I was looking for, I’m making an automation to trigger an Alexa Actionable Notification when get home and open the door to ask me if I want to turn some lights on. As I’m using the new zone entities number value with gps location to determine who is at home, when I open the door I’m already “at home” so the automation won’t trigger. Could you show me your automation and script to set the boolean?

Thanks!