Device tracker automation

No I’m not sure that it will happen, which is why I said “may”. If the other solution works, then stick with it.

I’ve just found it helps to consider any coding as literal as possible since that is usually how the system will read it.

The difference here is you have the

from: 'home' 
to: 'not_home'

entries in yours. Which means it is looking for a state change. The OPs code does not have that so it is just looking for a state of “home” to activate it.

I only said it “may” cause an infinite loop of activations because I wasn’t sure if it would or wouldn’t. I just try to keep code as specific as possible to avoid issues like that.

For reference, here is one of my working automations using the zone platform instead of state:

alias: 'Chrissy Arrive Work'
trigger:
  platform: zone
  event: enter
  zone: zone.barclaycard
  entity_id: device_tracker.iphoneha
action:
  service: notify.HomeAssistantFE
  data:
    message: 'Chrissy has arrived at work'
1 Like

this might be the key for why its not working. Looks like zone enter only works for GPS enabled trackers.

@oembob Oh, OK. Sorry, my english is soooo weak :slight_smile:
It is working just fine, I think “from to” is a good solution. Nothing repeat.

  trigger:
    platform: state
    entity_id: device_tracker.huawei_mate_8
    from: 'away'
    to: 'home'

And now I have a new question, because you are so smart and helpful guys :wink:

What then, when I want to run this automation if “from away to home” AFTER SUNSET.

Can I use more platform in the trigger? Or how can I set the logic “AND”?

  • platform: sun
    event: sunset

Yes it is possible to have multiple triggers. See here:

If you only want this action to fire after sunset you want to add a condition.

Trigger: If a device comes home

Condition: it is after sunset.

action: turn on the light

  condition:
     - condition: state
       entity_id: sun.sun
       state: 'below_horizon'
1 Like

GREAT! Thanks guys!
And the last one :smiley:

I live with my partner. What I have to do when I want an action only happen when both of us phones left the house?

I have my family device tracker entities all in a group called “family”. I then use the state condition. Here is my example:

alias: 'Motion when nobody home'
trigger:
  platform: state
  entity_id: binary_sensor.living_room_motion_motion
  state: 'on'  
condition:
  condition: state
  entity_id: group.family
  state: 'not_home'
action:
  service: notify.HomeAssistantFE
  data:
    message: 'Motion detected in the Living Room'

This is great, but this group thing is a mistery for me a while.
How do you create a group? In groups.yaml file?
How does a group look like?

Groups are pretty easy. Yeah, you use the groups.yaml file. More info with examples here:

OK, thanks guys! You are very helpful and patient with me. I’m so grateful.

1 Like

Hi, I am new in Home Assistant. My first goal is to track when my kids get home. I have this working and I can see it in the dashboard. What I cannot figure out is how it can send me an email when the kids arrive home.

Can please someone help ?

Thank you.

Look at the notify component


Can help you to setup smtp notifications via smtp email.

I am having trouble getting device tracker automations to work. I have two automations that are very similar. One works and one doesn’t and I can’t figure out why.

This automation detects when I arrive and it works fine:

  # Any device can indicate that I am home.  If any device can see me, I should be here.
  - alias: Jeremy Detected Live
    initial_state: True
    hide_entity: False
    trigger:
      - platform: state
        entity_id: device_tracker.jeremy_phone_bt, device_tracker.jeremy_phone_ip
        from: 'not_home'
        to: 'home'
    action:
      - service: input_boolean.turn_on
        entity_id: 
          - input_boolean.jeremy_home_live
          - input_boolean.jeremy_home

This automation should detect when I leave. It never updates.

  # All devices need to agree that I am not home.  Any device can trigger the checking of whether all devices indicate I am gone.
  - alias: Jeremy Gone Live
    initial_state: False
    hide_entity: False
    trigger:
      - platform: state
        entity_id: device_tracker.jeremy_phone_bt, device_tracker.jeremy_phone_ip
        from: 'home'
        to: 'not_home'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: device_tracker.jeremy_phone_bt
          state: 'not_home'
        - condition: state
          entity_id: device_tracker.jeremy_phone_ip
          state: 'not_home'
    action:
      - service: input_boolean.turn_off
        entity_id: 
          - input_boolean.jeremy_home_live
          - input_boolean.jeremy_home

Any ideas on what is wrong?

I figured it out. I had the initial_state of the non-working automation set to False which made it so the automation never ran.

@RonJ103, this is exactly the approach I’ve been gravitating toward, so it’s awesome to see this example of it working as intended. Did you try with any other tracking components? I don’t keep my BT on but I like the idea of using ping or nmap to verify that a device is gone, as long as I won’t get false negatives.

My problem with now with router tracking through AsusWRT is that one phone constantly goes into sleep mode and gives false negatives on presence, which triggers a bunch of unintended consequences…

I currently use this approach with bluetooth, wifi (nmap) and GPS with zanzito (was using owntracks). If any source says I’m home, my status will indicate home. In order for my status to change to away, all sources must indicate that I am away. This seems to help avoid false triggers and has been working quite well for me.

I see all these examples with ‘value’ in quotes. I put the values in quotes but it keeps removing them. Here’s the automation I’ve got. It runs when triggered manually, so I know the triggers are the problem.

- id: '1527986882929'

alias: Front Light - Arrival
trigger:

  • entity_id: device_tracker.b4f7a1e3bdad
    from: not_home
    platform: state
    to: home
  • entity_id: device_tracker.b4f1daefb5c7
    from: not_home
    platform: state
    to: home
    condition:
  • after: sunset
    before: sunrise
    condition: sun
    action:
  • data:
    entity_id:
    • light.front_entryway_light_7
      service: light.turn_on

Any thoughts? If it’s the quotes, how do I get it to stop deleting them? I can do this easily with PLEG on the Vera, but I’m working towards using it for little more than the device radios…