Proximity Automation - help wanted

I have created the following automation that works great. However I was looking for some tweaks to allow it to work for all the proximity sensors I have for all the people in my house. I am trying to avoid copying the automation 4-5 times. Bonus if I can setup the same automation for all those people for SEVERAL different proximity states (ie. 5 miles, 25 miles, 50 miles)

here is the automation:

- id: 'five_miles_away_david'
  alias: David is 5 miles away and heading home
  mode: single
  trigger:
  - platform: numeric_state
    entity_id: proximity.david_home
    below: 5
  condition:
  - condition: and
    conditions:
    - condition: template
      value_template: '{{ states.proximity.david_home.attributes.dir_of_travel  == "towards" }}'
  action:
  - service: script.sonos_announce
    data_template:
      message: "David is 5 miles away and heading home!"

I know I can add the other proximity sensors to the trigger, but how can I check the appropriate conditions and send an appropriate message for these other sensors? (Hope this makes sense) Thanks in advance!

- id: 'five_miles_away'
  alias: Someone is 5 miles away and heading home
  mode: single
  trigger:
  - platform: numeric_state
    entity_id:
      - proximity.david_home
      - proximity.joe_home
      - proximity.jane_home
    below: 5
  condition:
  - condition: and
    conditions:
    - condition: template
      value_template: '{{ trigger.to_state.attributes.dir_of_travel  == "towards" }}'
  action:
  - service: script.sonos_announce
    data_template:
      message: "{{trigger.to_state.object_id[:-5] | capitalize}} is 5 miles away and heading home!"
1 Like

Hey great! Thanks for your help! HA seemed to take that just fine, I should be able to test it out later today. Much appreciated!

BTW does the [:-5] remove the last 5 characters from the Object_ID?

Yes. I’ve made an assumption that all your proximity sensors follow the same naming format as david_home. It slices off the last 5 characters leaving behind just the person’s name. If the other proximity sensors don’t adhere to the same format, then the template for message needs modification.

1 Like

Thanks again!

1 Like

Just a note about a housekeeping issue. You categorized this topic as ‘Share your projects’ but it’s a better fit for Configuration > Automation.

‘Share your projects’ is typically for sharing things you’ve designed and constructed (software and/or hardware projects) that serve as an example for others to use. In this case, it’s simply a request for technical assistance (for configuring an automation).

1 Like

How you configured the proximity option inside configuration.yaml to have those sensors?

You directed your question to me but you should be directing it to orphan264. I have not configured any proximity sensors; I helped to fix the automation posted by orphan264.

Ok, sorry…

This is how I configure the sensors for us. This should be compatible with the automation above:

proximity:
  richard_home:
    zone: home
    devices:
      - person.richard
    tolerance: 50
  ann_home:
    zone: home
    devices:
      - person.ann
    tolerance: 50
1 Like