Need help with apparently simple automatisation

Hi, so i configured a nmap device_tracker in configuration.yaml to track if im home or not.
Now i wanna try to turn on some lights when i get back home. I added a time condition to ignore the rare false positive or network instability. Thats were im stuck i cant make my condition to work, if anyone have tried something similar im interested. Here’s my code atm.

alias: When i get home
description: ''
trigger:
  - platform: state
    entity_id: person.me
    to: home
condition:
  - condition: state
    entity_id: person.me
    state: not_home
    for: '00:30:00'
action:
  - type: turn_on
    device_id: eace4c11d5b2d8bcd6fd2b98a52371dc
    entity_id: light.yeelight_color_0x0000000004566673
    domain: light
mode: single

Hi, @Eratz. Welcome to the forum!

Reading through your automation:

  1. You first trigger it when you get home.
  2. Then you have a condition that says only continue if I haven’t been home for 30 minutes (i.e., the state of person.me has been not_home for 30 minutes).

So if the scenario is to turn on a light when you get home, then this won’t work (you can’t be home and not_home at the same time - by the time the condition is checked, the state of person.me has already changed to home).

My understanding is that you have the condition to prevent false positives. Assuming those false positives only happen for a second or two, a possible approach is to add a for condition (I made it 30 seconds - adjust to what works for you) to the trigger as well as a from condition to make sure the automation doesn’t trigger if the state goes to unknown and then back to home for a second or so):

alias: When i get home
description: ''
trigger:
  - platform: state
    entity_id: person.me
    to: home
    from: not_home
    for: '00:00:30'
action:
  - type: turn_on
    device_id: eace4c11d5b2d8bcd6fd2b98a52371dc
    entity_id: light.yeelight_color_0x0000000004566673
    domain: light
mode: single

Let me know if this works for you!

This solution waits 30sec before turning the light on.
If one bad nmap scan says im not home, it will turn the light on, just 30 sec later.

I also tried with 2 triggers and no condition :

 trigger:
  - platform: state
    entity_id: person.me
    to: home
  - platform: state
    entity_id: person.me
    to: not_home
    for: 00:30:00

Im gonna keep looking, i haven’t checked node-red yet.
I need a way to ignore those false positive.

It shouldn’t trigger unless person.me stays in the not-home state for at least 30 seconds. It’s kind of like a delay. In this case, the state needs to stay in not_home for 30 s in order to trigger.

Another option is to use a router to check if you are home. I have that configured, and then as long as one of them says I’m home, then my state is home. That tends to smooth out some of the false positives.

Good i will look into that, for the moment its seems to work a bit better.
I added –host-timeout 5s so he give up after 5sec.

device_tracker:
  - platform: nmap_tracker
    hosts: 192.168.0.12
    home_interval: 10
    scan_options: " --privileged -sn --host-timeout 5s"   
1 Like