Remember where I parked in home assistant

Voted! TY for your initiative!

But my point is that we should have the option to tell HA to assume a location based on the last known good location. It should be my choice if that’s how I want my sensor to act.

Because right now I’m forced to jump thru hoops creating variables and automations to fix the issue instead of just simply having an option in the device tracker config that says “optimistic: true” or “retain: true”.

input_* entities have that similar functionality. if there is no initial state set then it gets the same value that it had when HA shut down. So they “assume” that nothing has changed in the interim. Otherwise, to be consistent, there should be no option for an initial value or that they retain their last known state after a restart. they should always show “unknown” until programmatically updated with the desired value.

I’m sure there are other entities that act that way as well.

Of course, in a perfect world every entity would be able to be instantly polled or prompted for an update instantaneously after a restart. Sometimes (like in this particular case) that’s not possible. And in this particular case that information is lost forever with no easy way to get it back until we go back to the vehicle and connect/disconnect the bluetooth (or whatever method you are using). But if you already knew where you last parked then the whole point of that exercise is completely moot. It’s a catch-22 - you have to remember where you last parked in order to find your vehicle to set the known location in order for you to remember where you last parked.

As long as it’s an option…
But I would never use that on device trackers.

What if you walk outside your house and get a good location.
You drive away and just as you leave the house a small power dip makes your HA restart.

Ha assumes your previous position was home and unlocks the doors/alarm.
Not for me…

No…
Just save the location in a variable and use device_tracker.see to set the position according to your preference using a uptime sensor and conditions on how it should assume last position.
If I restart HA it waits for two minutes to make sure everything is up and running then it sets the car position to where it was parked.

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: