Proximity.home always 0?

I’m looking at the composite tracker. Based on the attributes available are you able to see how far a device or devices within the composite device tracker are from a zone and the direction of travel?

Wanted to try installing it with HACS but can’t find it so maybe this isn’t maintained anymore? Could manually install as well but figured it said HACS install was available so would use it.

Thanks.

JR

It is exactly what it says - a composite of the device trackers you include in it. It functions in exactly the same manner as the device trackers you put into it.

My apologies, apparently the link I had bookmarked was an old one. Here is the new one that is compatible with HACS. You have to go to the HACS settings and add this link as a custom repository. You can also follow the directions to install manually if you wish (HACS much better option).

I’m trying it now, but seems like it may do the opposite of what I’m trying to do. Installed it and added for example the below to my configuration.yaml:

device_tracker:
  - platform: composite
    name: family
    time_as: device_or_local
    entity_id:
      - device_tracker.johniosapp
      - device_tracker.sueiosapp

When one of the two trackers was at a distance from home family was marked as away. The other phone was still showing home on it’s separate proximity sensor but the composite one showed no one was there. For distance from home, it was showing my device which was 15 miles away, and not 0 for the device that was still at home. Is this expected?

Thanks.

JR

I think you misunderstood what I was suggesting. The composite device tracker works best to aggregate all the trackers for 1 person to determine their presence / location. You’ve put device trackers for two separate people into one tracker. I was suggesting to create composite trackers for each person and use those in your proximity trigger and any anywhere else in your config where you use device trackers.

If I understand your intentions correctly you are trying to do exactly what I’ve done here, just with one proximity sensor instead of two. BTW you might have the tolerance on your proximity sensor set too low. If your GPS is only hitting a couple of satellites your GPS accuracy will probably be well above 50 and I think the automation would actually get skipped! That may be part of the issue you’re having.

Here are my composite device trackers.

  - platform: composite
    name: Jason Tracker
    time_as: device_or_local
    entity_id:
      - device_tracker.jphone_ping
      - device_tracker.jphone_bt
      - device_tracker.google_maps_<redacted>

  - platform: composite
    name: Sheri Tracker
    time_as: device_or_local
    entity_id:
      - device_tracker.sphone_ping
      - device_tracker.sphone_bt
      - device_tracker.google_maps_<redacted>

These are my proximity sensors.

  jhome:
    zone: home
    devices: device_tracker.jason_tracker
    tolerance: 500 #meters
    unit_of_measurement: km

  shome:
    zone: home
    devices: device_tracker.sheri_tracker
    tolerance: 500 #meters
    unit_of_measurement: km

Yours might look like this.

proximity:
  home:
    devices:
      - device_tracker.johns_tracker   # composite tracker for John
      - device_tracker.sues_tracker  # composite tracker for Sue
    tolerance: 50 
    unit_of_measurement: mi

And finally this is how they work together to turn my furnace on when someone is on the way home someone has arrived home. My hvac mode is controlled by the occupancy mode of my house automatically so that’s why I’m using those. In your case you can turn the furnace on in the action and test for your furnace operation mode in the conditions. In your case since you’re only using 1 proximity sensor, you’ll only need include that one in the trigger and conditions.

  - id: presence_someone_almost_home
    alias: "[Presence] Someone Almost Home"
    description: "Go into override mode to turn off HVAC eco mode when someone is almost home."
    initial_state: 'on'

    trigger:
      # run when someone is close to home
      - platform: numeric_state
        entity_id:
          - proximity.jhome
          - proximity.shome
        below: 4  #km

      # run when someone arrives home
      - platform: state
        entity_id:
          - device_tracker.jason_tracker
          - device_tracker.sheri_tracker
        to: 'home'      

    condition:
      - condition: and
        conditions:
          # only run if nobody else is home
          - condition: state
            entity_id: binary_sensor.someone_home
            state: 'off'

          # only run when person heading towards home
          - condition: template
            value_template: >-
              {% if trigger.entity_id == 'proximity.jhome' %}
                {{ states.proximity.jhome.attributes.dir_of_travel == 'towards' }}
              {% elif trigger.entity_id == 'proximity.shome' %}
                {{ states.proximity.shome.attributes.dir_of_travel == 'towards' }}
              {% else %}
                true
              {% endif %}

      - condition: or
        conditions:
          # only run if house is in away mode
          - condition: state
            entity_id: input_select.occupancy_mode
            state: 'Away'

    action:
      # occupancy mode to override so HVAC turns off eco mode
      - service: input_select.select_option
        data:
          entity_id: input_select.occupancy_mode
          option: 'Override'

Finally here is a snapshot for the lovelace “presence card” for my wife (I chose hers because she’t not home right now). I highlighted the composite device tracker and the proximity sensor. I included this to show you how the composite tracker can use several of someone’s trackers together to give you their location. The Person integration does the same thing but like I said before the beauty of the composite tracker is it doesn’t lose it’s lat / long attributes when the state is “Home”.

image

1 Like

Did you get something working here @jriker1?

Not sure yet. Last couple days have been busy. Want to put time aside to absorb your posting. What I’m using right now seems to kind of work but triggers the home automation even if one person is still home. Doesn’t do anything as it’s just setting the ecobee to run it’s normal programming but saw it trigger yesterday on my way home. Would include what I have there now but don’t have access to it from work.

I like your “presence card”. Do you have this shared somewhere? I am interested in the different ways you track, and how it’s presented.

          # only run if nobody else is home
          - condition: state
            entity_id: binary_sensor.someone_home
            state: 'off'

You need a condition like this one in your automation. You could put in a condition to directly test the state of each of your device trackers but chance are you’re going to need to test for someone home in several places in your configuration so I’d recommend creating sensor just for that.

Here is the instantiation for my someone home sensor. The input boolean for guest is just that, a switch I can flip if a guest is in the house but we’re not so the heat doesn’t turn off of them and all that other fun stuff.

binary_sensor:
  - platform: template
    sensors:
      someone_home:
        friendly_name: Someone Home
        icon_template: mdi:account-supervisor-circle
        device_class: occupancy
        value_template: >-
          {% if is_state('device_tracker.jason_tracker', 'home') %} true
          {% elif is_state('device_tracker.sheri_tracker', 'home') %} true
          {% elif is_state('input_boolean.guest_home', 'on') %} true
          {% else %} false
          {% endif %}

Sure! I was going to push a new update my git in the next day or so after I clean up some odds and ends. I’ll send you the link when I’ve got it updated.

1 Like

Did you ever get this working the way you wanted it to?

Hi jazzyisj. I’m just picking up this thread again now sorry for the delay. Been otherwise distracted on approach for getting my Z-Wave network solidified. Now that I’ve ordered a bunch of stuff am getting back to this. Also not sure with the new release of the iOS app version 2.0 if that provides any more options. I know it reports a lot more data. To me it seems its checking in less frequently with the GPS info and now never triggering based on proximity and just when I get home and getting on my Ubiquiti network which isn’t ideal when the temp has dropped 10 degrees…

Note this is where I’m at now without getting thru everything posted yet:

in my automation.yaml:

- alias: 'Away Mode'
  initial_state: 'on'  #or isit true with no quotes?
  trigger:
    - platform: state
      entity_id: group.everyone
      to: 'not_home'
  action:
    - service: climate.set_preset_mode
      data:
        entity_id: climate.dining_room_2
        preset_mode: 'away'

# When no one home and 2 miles away coming back resume preset ecobee
- alias: 'Home Proximity'
  initial_state: 'on'
  trigger:
    - platform: numeric_state
      entity_id: proximity.home
      below: 2 #in miles
    - platform: state
      entity_id:
         - device_tracker.john_s_iphone_unifi
         - device_tracker.sue_s_iphone_unifi
      to: 'home'
  condition:
    - condition: template
      value_template: >
        {% if trigger.entity_id == 'proximity.home' %}
          {{ is_state_attr('proximity.home', 'dir_of_travel', 'towards' ) }}
        {% else %}
          true
        {% endif %}
  action:
    - service: ecobee.resume_program
      data:
        entity_id: climate.dining_room_2
        resume_all: true

in my groups.yaml:

everyone:
  name: Whole House
  entities:
    - group.john
    - group.sue

john:
  name: John
  entities:
    - device_tracker.jiphone
    - device_tracker.john_s_iphone_unifi

sue:
  name: Sue
  entities:
    - device_tracker.siphone
    - device_tracker.sue_s_iphone_unifi

In my configuration.yaml:

proximity:
  home:
    zone: home
    ignored_zones:
      - work
      - lsp
      - Wood
      - Costco
    devices:
      - device_tracker.jiphone
      - device_tracker.siphone
    tolerance: 200 #In meters
    unit_of_measurement: mi #Used for travel distances

When the initial state option for automations first showed up I think it was supposed to be ‘on’ and ‘off’ but I see the documentation says true and false now. Mine are still all ‘on’ and ‘off’ it seems more logical to me since it falls in line with the actual state of the automation and it works so I’ve never changed them. If it ain’t broke don’t fix it? I suppose when posting examples I should keep it in line with the documentation though. ‘on’ / ‘off’ doesn’t appear to be documented and could be deprecated someday. As it stands, looks like either works right now.

You have the proximity threshold set pretty low (2 miles) how long does it take you travel the last 2 miles to your house? If your GPS is only updating every 5 minutes it could be that the proximity automation is actually triggering when you’re almost home or your unifi trigger is triggering before the proximity sensor has a chance to. Also keep in mind if your phone’s GPS isn’t getting a good signal the tolerance could be way higher than 200 (sometimes mine can be off by a km or more) which means the proximity trigger might not fire right away.

You can see for sure which trigger is firing by writing the trigger_id to the HA log by putting the following as the first step in your action: section.

    - service: system_log.write
      data_template:
        message: "** Home Proximity trigger: {{ trigger.entity_id }} **"
        level: warning

Either way, your house probably isn’t going to warm up much in the few minutes it takes you to go 2 miles unless you’re in an area with super heavy traffic or something. 2 miles would take me less than 5 minutes. My house only warms up 2-3 degrees an hour which is why I usually only let the temp drop about 5 degrees.

In the condition section of Home Proximity there is no condition to check if anybody is home.

In the action section I would have thought that the ‘true’ value of the resume_all should be in quotes but looking around I see it done both ways in various threads and you said the automation was working when you got home so I guess either works?

    - service: ecobee.resume_program
      data:
        entity_id: climate.dining_room_2
        resume_all: 'true'  #<-- should this be quoted?

The other question I have is it possible for any of your ignored zones to overlap your home zone? If so I believe that would prevent the proximity sensor from triggering your automation.

Other than that it looks like everything should work unless I’m missing something.

1 Like

Part of the problem is my family doesn’t travel far from home. So we have about a 4 - 5 miles range other than myself when at work, that we travel. So I’m struggling with how to let HA know I’m on my way home, but set the distance to high and never actually be out of that area. Like if I go to visit my grandpa in his home, he’s 4 miles away and I could be there for 4 hours. So it’s a 15 minute ride home and maybe proximity never fires but not sure how to deal with that. There are times I go 20+ miles away for a day but that’s rare.

Note I’m working in your recommendations right now utilizing composite tracker and your condition recommendations but one question. If I was to add Google tracking, assuming I can do that on an iOS device, would having two GPS trackers per person be good or bad?

I don’t know how well the google location tracker works with an iPhone, I’m only using Android. Assuming it works just fine, they are both going to be using the same GPS (your phone) so I think the only difference would be how often they update. If you put them together in a composite tracker, the tracker state will always be the last one that sent an update.

I don’t think there are any negative consequences to having two GPS trackers (other than perhaps phone battery), but it probably isn’t necessary if one of them is reliable and updates often enough. Maybe for redundancy if one quits reporting for some reason.

Do you work a regular shift? I have another automation that fires 30 minutes before we usually get home on work days (wife and I work same place, same shift) to preheat the house. That automation triggers before I leave work (I’m only 10 minutes away) so it usually fires well before the proximity triggered automation would. Something like this might be a viable solution for you if nobody is usually home when you leave work. Also, like I already mentioned I only let the house drop 5 degrees so even if none of the automations fire (they almost always do) it’s not the end of the world. How long does it take your house to heat up 10 degrees? Do you really need to let it drop that much?

You also need to keep in mind that if your proximity automation trigger uses below 4 miles to trigger, if you never get more than 4 miles away it will never trigger, even when you are heading home. It is the state going from above 4 miles to below 4 miles that fires the trigger.

Another related point - back to using the combined proximity trigger for two people. If the wife is hanging out at a neighbours house 1 mile away and you come home from work the proximity trigger will never fire because it’s state is the closest tracker (as noted above by micque) which would be your wife’s phone until you are less than a mile from home. This means the tracker state was always less than the automation trigger threshold so it will never fire.

Thanks Jason,

So here is where I’m at right now based on your posts above. Does this look OK? If so will give it a try and replace what I have in there:

- platform: composite
  name: John Tracker
  time_as: device_or_local
  entity_id:
    - device_tracker.john_s_iphone_unifi
    - device_tracker.jiphone

- platform: composite
  name: Sue Tracker
  time_as: device_or_local
  entity_id:
    - device_tracker.siphone
    - device_tracker.sue_s_iphone_unifi


------------------

binary_sensor:
  - platform: template
    sensors:
      someone_home:
        friendly_name: Someone Home
        icon_template: mdi:account-supervisor-circle
        device_class: occupancy
        value_template: >-
          {% if is_state('device_tracker.john_tracker', 'home') %} true
          {% elif is_state('device_tracker.sue_tracker', 'home') %} true
          {% else %} false
          {% endif %}

------------------

jhome:
  zone: home
  devices: device_tracker.john_tracker
  tolerance: 500 #meters
  unit_of_measurement: mi

shome:
  zone: home
  devices: device_tracker.sue_tracker
  tolerance: 500 #meters
  unit_of_measurement: mi

--------------------

proximity:
  home:
    devices:
      - device_tracker.john_tracker   # composite tracker for John
      - device_tracker.sue_tracker  # composite tracker for Sue
    tolerance: 200 
    unit_of_measurement: mi

----------------------

- id: presence_no_one_home
  alias: "[Presence] No One Home"
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.someone_home
      to: 'off'
  action:
    - service: climate.set_preset_mode
      data:
        entity_id: climate.dining_room_2
        preset_mode: 'away'
    - service: input_select.select_option
      data:
        entity_id: input_select.occupancy_mode
        option: 'Away'


- id: presence_someone_almost_home
  alias: "[Presence] Someone Almost Home"
  description: "Go into override mode to turn off HVAC eco mode when someone is almost home."
  initial_state: 'on'
  trigger:
    # run when someone is close to home
    - platform: numeric_state
      entity_id:
        - proximity.jhome
        - proximity.shome
      below: 3  #mi
    # run when someone arrives home
    - platform: state
      entity_id:
        - device_tracker.john_tracker
        - device_tracker.sue_tracker
      to: 'home'      
  condition:
    - condition: and
      conditions:
        # only run if nobody else is home
        - condition: state
          entity_id: binary_sensor.someone_home
          state: 'off'
        # only run when person heading towards home
        - condition: template
          value_template: >-
            {% if trigger.entity_id == 'proximity.shome' %}
              {{ states.proximity.shome.attributes.dir_of_travel == 'towards' }}
            {% elif trigger.entity_id == 'proximity.bhome' %}
              {{ states.proximity.bhome.attributes.dir_of_travel == 'towards' }}
            {% else %}
              true
            {% endif %}
    - condition: or
      conditions:
        # only run if house is in away mode
        - condition: state
          entity_id: input_select.occupancy_mode
          state: 'Away'
  action:
    # occupancy mode to override so HVAC turns off eco mode
    - service: ecobee.resume_program
      data:
        entity_id: climate.dining_room_2
        resume_all: true
    - service: input_select.select_option
      data:
        entity_id: input_select.occupancy_mode
        option: 'Home'
---------------

You left a couple of things in there that only pertain to my config so I took them out. I should have removed them before I posted the examples. You can also change the automation descriptions and names to fit your own naming conventions also if you like. I just name them like that to group related automations.

You also have to split up the almost home/ arriving home automations. If you have a trigger that says fire when someone arrives home and then a condition that says don’t run if anyone is home it’s never going to run!

You can also now use the someone_arrives_home automation for anything else you want to do when someone arrives home ( turn on lights, announcements etc.)

Here’s the corrected automations. Give them a whirl see how they work out. Worst that can happen is your burn your house down right? :thinking:

- id: presence_no_one_home
  alias: "[Presence] No One Home"
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.someone_home
      to: 'off'
  action:
    - service: climate.set_preset_mode
      data:
        entity_id: climate.dining_room_2
        preset_mode: 'away'

- id: presence_someone_almost_home
  alias: "[Presence] Someone Almost Home"
  description: "Turn off HVAC eco mode when someone is almost home."
  initial_state: 'on'
  trigger:
    - platform: numeric_state
      entity_id:
        - proximity.jhome
        - proximity.shome
      below: 3  #mi
  condition:
    - condition: state
      entity_id: binary_sensor.someone_home
      state: 'off'
    - condition: template
      value_template: >-
        {% if trigger.entity_id == 'proximity.shome' %}
          {{ states.proximity.shome.attributes.dir_of_travel == 'towards' }}
        {% elif trigger.entity_id == 'proximity.bhome' %}
          {{ states.proximity.bhome.attributes.dir_of_travel == 'towards' }}
        {% else %}
          true
        {% endif %}
  action:
    - service: ecobee.resume_program
      data:
        entity_id: climate.dining_room_2
        resume_all: true

- id: presence_someone_arrives_home
  alias: "[Presence] Someone Arrives Home"
  description: "Turn off HVAC eco mode when someone arrives home."
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id:
        - device_tracker.john_tracker
        - device_tracker.sue_tracker
      to: 'home'      
  #condition:
    # you can put condition here to test if eco mode already off if you want
    # functionally i don't think it makes any difference and you probably won't want
    # it here if you end up using this automation for anything else.
  action:
    - service: ecobee.resume_program
      data:
        entity_id: climate.dining_room_2
        resume_all: true

Thanks Jason. I’m going out in a couple hours so will get this plugged in so I can see how it works. For reference I added in your occupancy_mode input_select but forgot to mention that. Also for the leaving part, since based on your guidance it sounds like the arrival won’t work if the family doesn’t exceed the return trigger distance so should I have something similar in the away logic? So if I say a family member is within 3 miles and moving toward turn the heat back on, should I have similar logic to wait until people area ll more than 3 miles away before triggering the off function? So add in a trigger like:

    - platform: numeric_state
      entity_id:
        - proximity.jhome
        - proximity.shome
      above: 3  #mi

I added in your occupancy_mode input_select

Cool. It will probably be handy for some of your other automations. I actually use 6 modes in mine. Home, Night, Guest, Away, Vacation, and Override. Override is really only used for allowing the HVAC turn off eco mode to preheat the house when someone is one the way home (sound familiar? lol) because my Away mode prevents the HVAC from leaving eco mode. Clear as mud yet? :laughing:

It would be redundant unless you are replacing the “when everyone leaves” trigger because the furnace would already be in eco mode when you cross the threshold. Unless you actually want to prevent the HVAC from going into eco mode until everyone is more than 3 miles away from home (which may very well be the case for you based on what you’ve said). I’d get what you have here working reliably first, see how it works for the fam, and then tweek it from there.

Alright, so first voyage with the new setup worked good. Triggered when no one was home but faster than it does when I wasn’t using the composite tracker since the prior path required all my devices to be away before it would trigger. On the way home it triggered and turned up the heat. Only part I’m questioning is the last part triggered twice after we both got home. Is that expected or desired? From the code seems that’s expected just trying to identify if that makes sense or if it should only trigger that if input_select.occupancy_mode is still at Away when someone gets home.

So here’s what I have for the automation.yaml:

  alias: "[Presence] No One Home"
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.someone_home
      to: 'off'
#    - platform: numeric_state
#      entity_id:
#        - proximity.jhome
#        - proximity.shome
#      above: 2  #mi
  action:
    - service: climate.set_preset_mode
      data:
        entity_id: climate.dining_room_2
        preset_mode: 'away'
    - service: input_select.select_option
      data:
        entity_id: input_select.occupancy_mode
        option: 'Away'


- id: presence_someone_almost_home
  alias: "[Presence] Someone Almost Home"
  description: "Turn off HVAC eco mode when someone is almost home."
  initial_state: 'on'
  trigger:
    # run when someone is close to home
    - platform: numeric_state
      entity_id:
        - proximity.jhome
        - proximity.shome
      below: 3  #mi
  condition:
    - condition: and
      conditions:
        - condition: state    # only run if nobody else is home
          entity_id: binary_sensor.someone_home
          state: 'off'
        # only run when person heading towards home
        - condition: template
          value_template: >-
            {% if trigger.entity_id == 'proximity.jhome' %}
              {{ states.proximity.jhome.attributes.dir_of_travel == 'towards' }}
            {% elif trigger.entity_id == 'proximity.shome' %}
              {{ states.proximity.shome.attributes.dir_of_travel == 'towards' }}
            {% else %}
              true
            {% endif %}
    - condition: or
      conditions:
        # only run if house is in away mode
        - condition: state
          entity_id: input_select.occupancy_mode
          state: 'Away'
  action:
    # occupancy mode to override so HVAC turns off eco mode
    - service: ecobee.resume_program
      data:
        entity_id: climate.dining_room_2
        resume_all: true
    - service: input_select.select_option
      data:
        entity_id: input_select.occupancy_mode
        option: 'Home'

- id: presence_someone_arrives_home
  alias: "[Presence] Someone Arrives Home"
  description: "Turn off HVAC eco mode when someone arrives home."
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id:
        - device_tracker.john_tracker
        - device_tracker.sue_tracker
      to: 'home'
  #condition:
    # you can put condition here to test if eco mode already off if you want
    # functionally i don't think it makes any difference and you probably won't want
    # it here if you end up using this automation for anything else.
  action:
    - service: ecobee.resume_program
      data:
        entity_id: climate.dining_room_2
        resume_all: true
    - service: input_select.select_option
      data:
        entity_id: input_select.occupancy_mode
        option: 'Home'

Makes total sense that this fired each time someone came home. That means everything is working as expected! This what I was talking about in the commented out condition in that automation. You could put a condition that checks to see if the eco mode is still on (meaning the proximity automation failed to trigger) but it’s really not necessary because it just doesn’t do anything if you reset it to the mode it was already in.

The downside of putting in this condition is that you wouldn’t be able to use this same automation for anything else you want to do that isn’t related to the HVAC such as turn on entrance lights because it would be dependent on the hvac still being in eco mode which it usually shouldn’t be if your proximity automation is working properly.

You can however use a separate automation for those things if you really want put the condition in. I don’t think there is a right or wrong here, just depends on how you want to do it. I’m not sure how the state attributes are represented with the ecobee but here’s how I would do it with my nest.

- condition: template
  value_template: "{{ is_state_attr('climate.upstairs_thermostat','preset_mode','Away and Eco') }}"