Last active
March 15, 2023 09:45
-
-
Save JorgeDLS/06602d0c62b9afcd82ddc172e9063a1c to your computer and use it in GitHub Desktop.
Update car last parked location with Home Assistant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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