Skip to content

Instantly share code, notes, and snippets.

@JorgeDLS
Last active March 15, 2023 09:45
Show Gist options
  • Save JorgeDLS/06602d0c62b9afcd82ddc172e9063a1c to your computer and use it in GitHub Desktop.
Save JorgeDLS/06602d0c62b9afcd82ddc172e9063a1c to your computer and use it in GitHub Desktop.
Update car last parked location with Home Assistant
# First of all, create the following Helpers in Home Assistant:
# input_text.{Car}_last_parked_geocoded_location
# input_number.{Car}_last_parked_latitude
# input_number.{Car}_last_parked_longitude
# Then, in the file: automations.yaml, add the following block
# replacing {Car} for your car model and {Phone} for your phone model in Home Assistant.
- alias: Store location for {Car} from {Phone} when Android Auto disconnects
trigger:
- platform: state
entity_id: binary_sensor.{Phone}_android_auto
to: 'off'
action:
- service: device_tracker.see
data_template:
dev_id: {Car}
gps:
- '{{ state_attr(''device_tracker.{Phone}'', ''latitude'') }}'
- '{{ state_attr(''device_tracker.{Phone}'', ''longitude'') }}'
source_type: gps
- service: input_number.set_value
target:
entity_id: input_number.{Car}_last_parked_latitude
data:
value: '{{ state_attr(''device_tracker.{Phone}'', ''latitude'') }}'
- service: input_number.set_value
target:
entity_id: input_number.{Car}_last_parked_longitude
data:
value: '{{ state_attr(''device_tracker.{Phone}'', ''longitude'') }}'
- service: input_text.set_value
target:
entity_id: input_text.{Car}_last_parked_geocoded_location
data:
value: '{{ states(''sensor.{Phone}_geocoded_location'') }}'
- service: notify.telegram
data:
message: {Car} aparcado en <a href="http://www.google.com/maps/place/{{ states('input_number.{Car}_last_parked_latitude')}},{{
states('input_number.{Car}_last_parked_longitude') }}">{{ states("input_text.{Car}_last_parked_geocoded_location")}}</a>
data:
parse_mode: html
# Also, for the functionality working after a reboot, you have to add the following block to the same file
- alias: Update {Car} from helpers on Start
description: Update {Car} from helpers on Start
trigger:
- platform: homeassistant
event: start
action:
- service: device_tracker.see
data_template:
dev_id: {Car}
gps:
- '{{ states(''input_number.{Car}_last_parked_latitude'') }}'
- '{{ states(''input_number.{Car}_last_parked_longitude'') }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment