Remember where I parked in home assistant

Tel-Aviv have a parking problem.

This means that I park my car at a different location at the start of every weekend, and forget where I parked by the start of the week :slight_smile:

I have several options to remember where I parked automatically:

  • :x: Tell google assistant to “remember where I parked”

    need to actively remember to do this

  • :x: Look at my timeline in google maps to see my last driving location

    Since I do several overlapping laps before I find a spot, it’s not easy to spot where I stopped the car on the map because of overlapping lines

  • :white_check_mark: Have some automation to do this for me

Implementation

Prerequisites

  • Home Assistant of course
  • hass-variables - allows us to create a last_parked variable that will hold the car location
  • MacroDroid - Allows you to create automation based on disconnecting from a specific Bluetooth device
  • RESTask for Tasker - Allows you to send POST requests. Even though this is a Tasker Plugin, MacroDroid can communicate with this plugin directly, so Tasker is not needed for this to work.

Algorithm

MACRODROID
  • Whenever I disconnect from the car’s Bluetooth (in my case, KIA_MOTORS), save my phone’s location to a global variable
  • Whenever a new last parked location saved, send a post request to home assistant with the device location as the body using the webhook endpoint (<hass.io>/api/webhook/last-parked)
HOME ASSISTANT
  • Whenever a last_parked webhook is received, save the map URL, longitude and latitude to our variable in home assistant

Home Assistant Automation

Create the following variable in your configuration:

variable:
  last_parked:
    value: 0
    attributes:
      friendly_name: 'Last Parked Location'
      icon: mdi:car-hatchback
      latitude: 0
      longitude: 0

Next, create a new automation to update that variable:

- id: '1590707948988'
  alias: Remeber Where I Parked
  description: Remember where I parked based on bluetooth disconnect
  trigger:
  - platform: webhook
    webhook_id: last-parked
  condition: []
  action:
  - data_template:
      attributes_template: |
        {
          "longitude": {{ trigger.data.parkingLocation | regex_replace('.*?,', '') }},
          "latitude": {{ trigger.data.parkingLocation | regex_replace(',.*', '') }},
          "source type": "gps",
          "altitude": 0,
          "entity_picture": "https://autovolostorage.blob.core.windows.net/advertimages-6691182/kia-picanto-2016-912l.jpg"
        }
      value_template: '{{ trigger.data.parkingMapLink }}'
      variable: last_parked
    service: variable.set_variable
  - data_template:
      message: '{{ trigger.data.parkingMapLink }}'
      title: Car Parked
    service: persistent_notification.create

Macrodroid Automation

You need to create two macros:

Save the RESTask command you created, and click on OK in macrodroid. You can test that everything works by entering the Remeber where I parked macro, clicking the three dots, and selecting Test Macro

I added the entity to my Lovelace map to always display the last location I parked:

10 Likes

Am I misunderstanding something…

RESTask also requires Tasker to be pre-installed for this to work?

1 Like

RESTask also requires Tasker to be pre-installed for this to work?

You don’t need tasker installed. Macrodroid can work directly with the plugin.

When you create a new macro and select your action, open Applications, and there, click on Local/Tasker Plugin. when you’ll select RESTask, it will open up restask where you can set the specific request you want to make

Thanks! I’ll give it a try.

2 Likes

Cool! Let me know if you need any help. I had a few hiccups on the way which I hope you won’t go through if you set up everything as described above, but I might have missed something.

And if everything worked, I would love to hear about that too :wink:

Also notice that in my macros I have some disabled steps (will remove them from the screenshot soon), so you don’t need to add those (the ones that are a little grayed out)

I’ve gotten to the point of adding the actions to macrodroid and I have a question (or two…or three)

What do you use for the title and message for the “Display Notification” action? The screenshot only shows one variable. Do you use one variable for the title and one for the body or do you use the same one for both?

Where do you find the “Execute HTTP shortcut” action? and where does the “test” shortcut get created?

When filling in the RESTask parameters should I need to fill them in manually or should they be presented as an option to select from somewhere?

What do you use for the title and message for the “Display Notification” action?

The notification here is just a phone notification (on the phone itself, not home assistant). you can skip this if you want. I just put in the body of the message the mapLink but didn’t do anything more with it since I used it for debugging mostly. The title of the notification for me is just Car Parked.

Where do you find the “Execute HTTP shortcut” action? and where does the “test” shortcut get created?

I have some disabled steps in my macros (will remove them from the screenshot soon), so you don’t need to add those (the ones that are a little grayed out). This was a failed attempt to do the HTTP request with another tool. Skip that step :slight_smile: sorry for the trouble :pray:

When filling in the RESTask parameters should I need to fill them in manually or should they be presented as an option to select from somewhere?

I entered the details manually inside RESTask. The parameters I filled were

  • METHOD should be POST
  • url should go to your home assistant instant <url_to_ha>/api/webhook/last-parked
  • parameter should include the two global parameters set in macrodroid. the name of the parameters should be parkingMapLink and parkingLocation (same as the ones defined in macrodroid. this is not mandatory, but I kept the same naming convention across all applications). The value should be [v=<macrodroid_parameter>]. I entered this manually, and this is how you inject the value from macrodroid to this tasker plugin.

I see this is far less clearly written than I thought. I’ll fix the original post to reflect most of what was discussed here :slight_smile:

thank you! :pray:

1 Like

Changed the original post to reflect the confusing data and define more clear steps :point_up_2:

2 Likes

I just got everything set up and tested by using the three dots menu and it seems to be working.

I’ll get a chance to test it in the real world pretty soon when I go home.

Thanks! This can come in pretty useful. Especially as we get older and start having those “senior moments” :older_man:

But who am I trying to kid…I’ve had those “senior moments” for the last twenty years. :laughing:

1 Like

I was wondering if this could be done solely with Tasker?

1 Like

I was wondering if this could be done solely with Tasker?

You can. You need to create a profile that is active when connected to the Bluetooth device and set up an exit task to run whatever you want when the profile becomes inactive due to the device disconnects.

Since I didn’t have any automation using tasker or macrodroid up until now, it sounded a little easier to do with macrodroid.

But if you do create this with Tasker alone, please share it :slight_smile:

Thank you so much, I’ve had this issue for a while, especially in lockdown where I took my car about 3 times in 2 months, I always forget where I park it!
Juste tested it with a bluetooth headset, seems to work perfectly well!

1 Like

Great to hear!

Yeah, this problem became bigger for me as well now with Covid-19. That’s why it became so essential.
I drive so little now, it’s even harder to remember where I parked lol.

Glad it helps! :slight_smile:

I’m not really sure what’s going on but now that I’ve had time to test it for a couple of days I seem to not get a good GPS position when I disconnect.

For example right now it says my car is parked off the west coast of Africa. :grimacing:

ex4

I can’t see what would be causing it tho.

weird! I’ll try and check it out myself. Can you send the info when you click on the point in the map?

I’m not sure why it was doing it but I went into macrodroid and clicked around on a few of the settings in the macros and when I tested it again it now seems to be working.

As far as the point on the map it was at 0 latitude & 0 longitude so obviously the coordinates weren’t getting updated correctly. But also the persistent notification wasn’t being triggered either even tho it was sending the update action in the webhook.

It was definitely strange but it seems to be working again for now.

If it stops again I’ll let you know.

I do this too! I also keep track of my bluetooth headset this way. Although admittedly its not exact enough to tell me where in the house they are, more like are they in the house or did I leave them somewhere else.

I don’t use hass-variables, I used to but then I found you can make custom device trackers using device_tracker.see. It’s basically the same process I just call the device_tracker.see service from tasker after doing a get location call on disconnect from the bluetooth device I’m tracking.

Also for the car instead of using ‘bluetooth disconnect’ as the event I use ‘bluetooth near becomes false’. I do this because my wife and I often drive together and only one of our phones connect. Bluetooth near immediately becomes false when the car is off so effectively this is the same trigger except it doesn’t matter which of our phones actually connects to the car.

Another neat trick I added is I created a task that i can use as a shortcut on my phone called “Navigate to car”. When I run the task it uses the get state API to get the last known location of my car from HA and then launches google maps navigation in walking mode with directions from my current location to my car.

I do actually use Tasker for all this so I can’t really share exports for you, I’m not familiar with MacroDroid. Looking at your screenshots it seems like they fulfill similar purposes so I’m sure these can be recreated there. If someone wants me to share my tasker exports let me know though.

1 Like

Yes, please share.

Ironically right after I posted above that things were working again I noticed that the automations didn’t run when I got to work. It seems that macrodroid isn’t very reliable for some reason - at least on my phone.

That is Null island

2 Likes

So I’ll share everything you need here but at the very base of these is essentially this package. Granted I adjusted that authors tasks a little bit as you can see further down in that thread here but that’s the base package used for communicating with HA. I’m going to share my versions of those tasks but you should also be fine just using the originals if you prefer or already have them.

For basic HA communication you’ll need these 4 tasks:

To make these work you just need to fill in the two global variables referenced in them. Put your Home Assistant URL in %HA_ADDR and a long-lived access token in %HA_TOKEN.

Then for car tracking you’ll need these two tasks and the profile that triggers them:

Once you import these you’ll see two new referenced global variables to fill in. Put your car’s bluetooth name in %CAR_BT_NAME and its mac address in %CAR_BT_MAC. Then whenever your phone goes from being near the car’s bluetooth to not near it will stash its location in HA. It does this using device_tracker.see so its a custom device tracker. The Bluetooth name will be used as the tracker name.

Then finally the last 3 tasks are shortcuts you can put in your home screen or quick tiles menu to immediately launch into navigation mode and navigate to your car:

And that’s it, should be good to go. If you take a look you’ll see that all the real logic here is in Track Device Location and Navigate to Location which both take the device ID as a parameter. This way if you want to track other bluetooth devices (like I did with my headset) its very simple. You can clone the other tasks and just replace CAR_BT_NAME and CAR_BT_MAC with the name and mac of some other device.

One FYI though - I do depend on the Tasker add-on AutoTools. I basically just use it for JSON processing so you can get by without it but. you’ll need to change some things. Tasker’s OOTB JSON handling options are a lot more difficult to use unfortunately.

1 Like