Remember where I parked in home assistant

yeah, but that part really doesn’t matter as much as the location.

If it is important I’m sure you could also template the location_name to set it to home if the zone is the home zone.

the other thing I just noticed is that the device tracker data doesn’t seem to survive restarts.

1 Like

I managed this adding the single device to the “include” section of my recorder.

I tested the automation for 2 days and I noticed that the position is not updated sometimes. Maybe it depends from my mobile…I’m thinking to add a repeat to the position so it will be updated more often.

I changed it to

location_name: “{{ states(‘device_tracker.mobiledevice’) }}”

I tried that and it didn’t work. It still loses the state after a restart.

I built a flow in node red which saves the position on a website using GET and pulls it back using a http request when home assistant is restarted.

I assume you could do the same using a input_text.

If it’s wanted then I can post the flow.
I also added a loop to try and pull new data from the phone before it’s saved.

1 Like

Thanks for the offer but I don’t use Node-red.

I probably could get creative and save it to a variable if I really needed it.

But hopefully I won’t get into a situation where I need to remember where I parked my truck and in the meantime I’ve restarted HA. Seeing as I’m the only one who ever restarts HA so if I’m home (and presumably so would my truck…) and messing with HA I would have more serious problems to worry about than remembering that I parked my truck in the driveway! :laughing:

Not saving the state was more of a WTH than a real need.

Speaking of which…

1 Like

Power loss?
Power supply gives up?

But I understand why device trackers don’t save the state, they are not meant to save the state. That would defeat their purpose.
When HA restarts it should update all device trackers, perhaps if you could set a “manual” attribute on them.

I’m not sure that’s necessarily the case.

If that is the case then no entities in HA (aside from those controlled exclusively from within HA itself) should retain their states thru a restart. Who is to say a light wasn’t turned off while HA was down? There are many other or better examples but I hope you get my point.

We have an optional “optimistic mode” for other entities. Why couldn’t we have something similar for device trackers? I think having a “last known good location” for a device tracker could come in handy - like in the current use case.

Exactly what I’m saying.
Sensors are supposed to sense stuff, not assume.
If it retains it’s state after startup then it assumes.

Exactly my point again. HA must update states after a boot up or it will be out of sync with reality.

HA doesn’t know how long it has been off (maybe it can find it out) but giving a last known location can still be on the other side of the planet.
I would rather see “unknown” than a wild guess

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