New proximity integration - migration issues from the old one

Hello everyone!

There was a new proximity-integration introduced a while ago and the old integration is going away in HA 2024.8. So, it’s time to update my automations and everything before then.

I have been using the old proximity integration, where I had everything in one entity:

I had automations that would trigger:

 platform: state
 entity_id:
   - proximity.proxA
   - proximity.proxB
   - proximity.proxC
   - proximity.proxD
 attribute: dir_of_travel
 to: towards
 for:
   hours: 0
   minutes: 2
   seconds: 0

And then I would have a condition:

 {{trigger.to_state.state|int < 90000}}

So this would trigger if a person was travelling home and the distance was under 90km.

IN the action I would have something like this:

 {{trigger.to_state.attributes.nearest}} reist naar huis, hij is
     {{(trigger.to_state.state|float / 1000)|round(2)}} km hier vandaan.

(where of course in the attribute ‘nearest’ I put the name of the person, so that person’s name was announced together with the distance.

However, in the new version of Proximity, it looks like this:


So I made some changes.
trigger:

 platform: state
 entity_id:
   - sensor.thuisA_nearest_direction_of_travel
   - sensor.thuisB_nearest_direction_of_travel
   - sensor.thuisC_nearest_direction_of_travel
   - sensor.thuisD_nearest_direction_of_travel
 attribute: dir_of_travel
 to: towards
 for:
   hours: 0
   minutes: 2
   seconds: 0

(>> Edit: I probably need to delete the line ATTRIBUTE above, don’t I? The direction_of_travel is now in the state itself. Just noticed this after posting)

But now I’m at a loss with the distance.
I want to rewrite my condition but I do not have the distance available in this new sensor anymore. It is in a different sensor of course, but that other sensor does not have the direction of travel.

How can I translate my old condition of:

 {{trigger.to_state.state|int < 90000}}

to work with the new sensor?
I was thinking something like left(trigger.to_state,len(trigger.to_state)-19) & “distance”.state
That would take the name of sensor.thuisesther_nearest_direction_of_travel, strip away the right 19 characters (direction_of_travel) and add ‘distance’ instead so it would look like sensor.thuisesther_nearest_distance.state and then I would get the distance of the corresponding distance-sensor.
I have no idea how to translate this into YAML properly and I don’t really think this is the best way to go either.
But I’m not seeing a better way.

And I also had a different automation with a trigger on distance and then a condition of direction of travel ({{trigger.to_state.attributes.dir_of_travel == “towards”}}).
But of course, that automation can’t work anymore either because now the trigger is on sensor.thuisesther_nearest_distance and that entity doesn’t have an attribute dir_of_travel.
But if I know the solution to the first problem, I’ll be able to solve the second one myself.

Any help would be greatly appreciated!

The information provided by the integration has been split out across multiple sensors instead of as attributes, so you will need to use either Or conditions and Choose actions and/or templates to define the relationship between the triggering “Direction of Travel” sensor and its corresponding Distance sensor. Be careful to not confuse “Direction of Travel” and “Nearest Direction of Travel”.

trigger:
  - platform: state
     entity_id:
       - sensor.thuisA_direction_of_travel
       - sensor.thuisB_direction_of_travel
       - sensor.thuisC_direction_of_travel
       - sensor.thuisD_direction_of_travel
     to: towards
     for:
       hours: 0
       minutes: 2
       seconds: 0
variables:
  person: |
    {{trigger.entity_id|replace('sensor.thuis','')|replace('_direction_of_travel','')}}
  km_distance: |
    {% set target = 'sensor.thuis'~person~'_distance'  %}
    {{ (states(target)|float(0)/1000) | round(2) }}
condition:
  - condition: template
    value_template: "{{ km_distance < 90 }}"
action:
  - service: notify.EXAMPLE
    data:
      message: |
        {{ person }} reist naar huis, hij is {{km_distance}} km hier vandaan.
1 Like

Thanks a lot!
I will try this this weekend, but by the looks of it this will work great!
Thanks again for helping out!

I made some minor adjustments and everything is working fine!
Thanks again for your help!

1 Like