I case you want a different approach this is what I’ve been using.
It creates a device tracker to show the vehicle location on the HA map instead of sending a notification of the location. But you can combine this with yours if you want both.
First you need to create a device tracker in your known_devices.yaml (create that file in your config directory if it doesn’t exist):
toyota_tacoma:
icon:
name: Toyota Tacoma
picture: /local/tacoma.jpg
track: true
then create a variable to save the GPS location. I use the custom integration hass-variables for this but you might be able to use your existing location sensor:
tacoma_location_saved:
value: 'unknown'
attributes:
latitude: ''
longitude: ''
restore: true
then you can use the following to update everything:
- alias: Set Tacoma Location
trigger:
- platform: state
entity_id: sensor.my_mobile_app_bluetooth_connection
- platform: state
entity_id: person.me
to: 'home'
action:
choose:
- conditions:
- "{{ trigger.entity_id == 'sensor.my_mobile_app_bluetooth_connection' }}"
- "{{ '84:DD:20:62:AA:AA (TOYOTA Tacoma)' in trigger.from_state.attributes.connected_paired_devices }}"
- "{{ '84:DD:20:62:AA:AA (TOYOTA Tacoma)' not in trigger.to_state.attributes.connected_paired_devices }}"
sequence:
- service: device_tracker.see
data:
dev_id: toyota_tacoma
location_name: "{{ states('device_tracker.my_mobile_app') }}"
gps:
- "{{ state_attr('device_tracker.my_mobile_app', 'latitude') }}"
- "{{ state_attr('device_tracker.my_mobile_app', 'longitude') }}"
- delay:
seconds: 10
- service: variable.set_variable
data:
variable: tacoma_location_saved
value: "{{ states('device_tracker.toyota_tacoma') }}"
attributes:
latitude: "{{ state_attr('device_tracker.toyota_tacoma', 'latitude') }}"
longitude: "{{ state_attr('device_tracker.toyota_tacoma', 'longitude') }}"
- conditions:
- "{{trigger.entity_id == 'person.me'}}"
sequence:
- service: device_tracker.see
data:
dev_id: toyota_tacoma
location_name: home
gps: [41.00000, -85.000000]
- delay:
seconds: 10
- service: variable.set_variable
data:
variable: tacoma_location_saved
value: "{{ states('device_tracker.toyota_tacoma') }}"
attributes:
latitude: "{{ state_attr('device_tracker.toyota_tacoma', 'latitude') }}"
longitude: "{{ state_attr('device_tracker.toyota_tacoma', 'longitude') }}"
- alias: Restore Tacoma Location After Restart
trigger:
- platform: homeassistant
event: start
action:
- delay:
minutes: 1
- service: device_tracker.see
data:
dev_id: toyota_tacoma
location_name: "{{ states('variable.tacoma_location_saved') }}"
gps:
- "{{ state_attr('variable.tacoma_location_saved', 'latitude') }}"
- "{{ state_attr('variable.tacoma_location_saved', 'longitude') }}"
it’s a bit more involved but it gives you a marker on the map and it survives HA restarts.