Remember where I parked in home assistant

Exactly. That’s what I said.

Wouldn’t that depend on the use case that you are using the device tracker for?

I’ve given a use case where it would be completely logical to use in that way.

Right. Apparently you also missed this:

And I’ve already done all of that in my current config to solve the problem that I’m trying to address.

Once I get to a spot that I can access my config I’ll post what I’ve done to solve it.

So are you saying that you are actually doing this right now in your own config?

If so then you see my point that this use case is reasonable since you are doing exactly what I’m trying to avoid by posting the WTH.

You forgot this part.

Since I use node red it’s just two nodes that I need to add to get the function, the rest is the same as the normal sequence. I don’t find it distracting at all.
It’s so simple.

I don’t see a reason for the WTH because there is ways to do it.
Just like I would argue against premade template sensors to extract all attributes of a entity.
I would say focus on the stuff that does not work at all now and then keep these where you can make it quite easily yourself to last.
My opinion but I understand that you don’t agree.

Here is how I’m handling this in HA.

First create a variable using the custom Hass-variables component:

  tacoma_location_saved:
    value: 'unknown'
    attributes:
      latitude: ''
      longitude: ''
    restore: true

here are my updated automations:

- alias: Set Tacoma Location
  trigger:
    - platform: state
      entity_id: sensor.my_mobile_app_bluetooth_connection
  condition:
    - condition: template
      value_template: "{{ '84:DD:20:62:FA:FE' in trigger.from_state.attributes.connected_paired_devices }}"
    - condition: template
      value_template: "{{ '84:DD:20:62:FA:FE' not in trigger.to_state.attributes.connected_paired_devices }}"
  action:
    - service: device_tracker.see
      data_template:
        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_template: "{{ states.device_tracker.toyota_tacoma.state }}"
        attributes_template: >
          {
            "latitude": "{{ states.device_tracker.toyota_tacoma.attributes.latitude }}",
            "longitude": "{{ states.device_tracker.toyota_tacoma.attributes.longitude }}"
          }
    
- alias: Restore Tacoma Location After Restart
  trigger:
    - platform: homeassistant
      event: start
  action:
    - delay:
        minutes: 1
    - service: device_tracker.see
      data_template:
        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') }}"
2 Likes
        value_template: "{{ states.device_tracker.toyota_tacoma.state }}"
        attributes_template: >
          {
            "latitude": "{{ states.device_tracker.toyota_tacoma.attributes.latitude }}",
            "longitude": "{{ states.device_tracker.toyota_tacoma.attributes.longitude }}"
          }

Thanks for the code. Unfortunately it doesn’t work for me. (“Cannot call service variable.set_variable extra keys not allowed @ data[‘attributes_template’]. Got None extra keys not allowed @ data[‘value_template’]. Got None”
Perhaps it has to do with a recent update of HA. FYI I am running HA 2021.12.10.
I had to change value_template and attributes_template and remove _template from both.
Even though this is an old post I hope this helps somebody.

yeah, that was changed quite a while back.

thanks for updating the thread.

Hi

I’m trying to do this too.
My wife (y) and i (x) drive the car, so the automation should work for 2 phones.
I also want a button in the gui, so i can press it, and it gives me a navigation route to the point i parked the car, is that possible (not using android auto cause i want it for walking too)

Here’s my automation, but it doesnt work 100% and i have no button to navigate

- id: 'Slaat de locatie van de auto op wanneer geparkeerd'
  alias: Bewaar parkeerlocatie
  trigger:
    - platform: state
      entity_id: sensor.auto_bluetooth_x
      from: "True"
      to: "False"
      id: verlaat_auto_x
    - platform: state
      entity_id: sensor.auto_bluetooth_y
      from: "True"
      to: "False"
      id: verlaat_auto_y
    - platform: homeassistant
      event: start
      id: ha_start
  condition: []
  action:
    - choose:
        - conditions:
            - condition: trigger
              id: verlaat_auto_x
          sequence:
            - alias: "Schrijf variabelen in input_text"
              service: input_text.set_value
              target:
                entity_id: input_text.auto_locatie
              data:
                value: >
                  {{
                    [
                      states('sensor.smartphone_x_geocoded_location'),
                      state_attr('device_tracker.smartphone_x', 'latitude'),
                      state_attr('device_tracker.smartphone_x', 'longitude')
                    ] | to_json
                  }}
            - alias: "Update device tracker"
              service: device_tracker.see
              data:
                dev_id: auto
                host_name: Parkeerlocatie
                location_name: "{{ states('sensor.smartphone_x_geocoded_location') }}"
                gps:
                  - "{{ state_attr('device_tracker.smartphone_x', 'latitude') }}"
                  - "{{ state_attr('device_tracker.smartphone_x', 'longitude') }}"
        - conditions:
            - condition: trigger
              id: verlaat_auto_y
          sequence:
            - alias: "Schrijf variabelen in input_text"
              service: input_text.set_value
              target:
                entity_id: input_text.auto_locatie
              data:
                value: >
                  {{
                    [
                      states('sensor.smartphone_y_geocoded_location'),
                      state_attr('device_tracker.smartphone_y', 'latitude'),
                      state_attr('device_tracker.smartphone_y', 'longitude')
                    ] | to_json
                  }}
            - alias: "Update device tracker"
              service: device_tracker.see
              data:
                dev_id: auto
                host_name: Parkeerlocatie
                location_name: "{{ states('sensor.smartphone_y_geocoded_location') }}"
                gps:
                  - "{{ state_attr('device_tracker.smartphone_y', 'latitude') }}"
                  - "{{ state_attr('device_tracker.smartphone_y', 'longitude') }}"
        - conditions:
            - condition: trigger
              id: ha_start
          sequence:
            - alias: "Maak device tracker aan bij start HA"
              service: device_tracker.see
              data:
                dev_id: auto
                host_name: Parkeerlocatie
                location_name: "{{ (states('input_text.auto_locatie') | from_json)[0] }}"
                gps: "{{ (states('input_text.auto_locatie') | from_json)[1:] }}"

Any idea?

I have one driver to one car and I used to have a button that navigated using Google maps but by some reason the button is not on the GUI anymore. :thinking:
I believe I can figure out what the button did looking at automations and stuff.

But since you can’t get a dynamic link on the GUI (at least not with standard cards) I routed to a static php page that directed me to google maps navigation.

The automation that parks the car sends the coordinates to the same php page with a simple GET url.
Do you have a webpage you can use for this?

Hi
I’m curious how you did it.
Why do you say i cant get a dynamic link, if i just point to the device tracker as an entity i do have a link right?

I don’ t have a webpage.
Also any idea why my automation doenst always work?

I changed my host_name afterwards, might that be the cause?
CAuse in my GUI i dont see the new host name but the old one, and HA didnt make a second device tracker. (cant get rif of it either)

Old:

sequence:
            - alias: "Maak device tracker aan bij start HA"
              service: device_tracker.see
              data:
                dev_id: auto
                host_name: Locatie Auto

New:

sequence:
            - alias: "Maak device tracker aan bij start HA"
              service: device_tracker.see
              data:
                dev_id: auto
                host_name: Parkeerlocatie

If there is any state at all between going from True to False (unknown, unavailable, etc) then the trigger will fail.

you should probably remove the “from: True” line and just leave the "to: " line

But that won’t open google maps, right?
You can use the map card if you want to do a basic/manual navigation, but if you want to open google maps navigation then you need to supply it with a dynamic URL.
You might be able to do it easier now with notifications to the phone.

hows that?

service: notify.mobile_app_andreas
data:
  message: "command_activity"
  data:
    intent_package_name: "com.google.android.apps.maps"
    intent_action: "android.intent.action.VIEW"
    intent_uri: "google.navigation:q={{state_attr('device_tracker.kraftan', 'latitude')}},{{state_attr('device_tracker.kraftan', 'longitude')}}&mode=w"

Replace the device tracker with your car and your phone should open Google maps in navigation mode with walking mode selected.
Change the mode parameter if that is not correct Google Maps Intents for Android  |  Maps URLs  |  Google Developers

1 Like

My solution involves 3 parts:

  • mobile automation using tasker
  • sending a webhook that is watched by node-red
  • having an entity to represent the car in home assistant

Mobile automation using tasker

haven’t tested it on other devices so hopefully this works fine for you:
https://taskernet.com/?public&tags=Bluetooth,Car,Location&time=AllTime
the tasker profile is called HA Car Location and it has a starting task to allow you to configure parameters like when to update, name of car, HA instance, etc.

Sending a webhook that is watched by node-red

You need to create a flow in node-red that will create a car instance that will update based on the webhooks defined in tasker

Known issues

  • When restarting the phone, the phone sends a notification to update the parked car. This is fixable (already fixed in the version on my phone). will update a fix soon

I’ll try and post the complete solution once I’m home and have everything available

Gonna try that, i will create a button that triggerst that service then (or something like that)
Bit busy now, but will try asap

Multiple lessons to be learnt:
I setup this style of device tracker system for many devices around my house, utilising Espresense and bluetooth connections with the phones to create a last known location for headphones, smartwatches, ble keytags, etc.
So my son lost his Fitbit, and in theory my new system ‘should’ have been able to tell the rough last known location, all device_tracker entities were listed in recorder.yaml.

I apparently missed the part where HA does not save the device_tracker data through a restart.

You can create a input text with the coordinates in and when HA restarts have an automation set the device tracker position

Thanks, thats the same idea I came up with, a lot of ‘extra’ work. Oh well :wink:

Not really extra work in my opinion.
HA can’t possibly know what happens during a restart, or for how long it has been offline.
So the only thing it can do is to say “I don’t know”, what you want is to make HA assume everything has been static during the offline time. It could be true, but a device could be moved and run out of battery during this time also.

HA can’t possibly know what happens during a restart, or for how long it has been offline.
So the only thing it can do is to say “I don’t know”, what you want is to make HA assume everything has been static during the offline time. It could be true, but a device could be moved and run out of battery during this time also.

True, but then the HA companion app that I installed on an old tablet to use as a wall mount is still showing a battery level of 45%, despite the fact that tablet hasn’t been turned on in 6 weeks.
I guess it just seems odd that other entities if you include them in recorder, then they get recorded.

EDIT: See the next post. I misread the problem
:roll_eyes: :man_facepalming:


Surely that wouldn’t work in your ‘lost device’ case? It would be too late when HA restarts, you’d have lost the data.

Maybe better to write the location before a shutdown (restart)?

  - alias: System HA Shutdown
    id: system_ha_shutdown
    trigger:
      #=== HA stopping
      - platform: homeassistant
        event: shutdown

    action:
      #=== Save some device tracker co-ordinates to survive restarts
      - service: script.system_event_write_to_log
        data:
          log_event: DEVICE_TRACKER_LOCATION
          event_time: >
            {{ now() }}
          devices:
            phone1: >
              {{ state_attr('sensor.phone1_geocoded_location', 'location') }}
            phone2: >
              {{ state_attr('sensor.phone2_geocoded_location', 'location') }}

I have a script (script.system_event_write_to_log) that writes stuff to a file as and when I need it too.