AirTag "integration" (user friendly + device tracker)

@NCO3 can you try this:

      {% set address = states('input_text.airtag').split('keys')[1].split('•')[0].strip().lower() %}
      {% if  "home" in address %}

this checks if ‘home’ is anywhere in the resulting string. It also strips any spaces and makes it lowercase. I think it is working for me. It will fail in the rare cases that the word “home” is in the actual address, but that is way more rare then my tags actually being at home.

1 Like

Hi John,

thank you very much!
This seems to work, but I still need to investigate a little more to confirm.

What I still dont’t understand is why I still see “Home” in “Find My” even though I have deleted my home address in “Apple Maps” (Favorites) and in “My Card”
:crazy_face:

1 Like

I am in the same situation. I can not, in any way, remove Home anymore. I have deleted my address everywhere. Also tried to make my home location somewhere completely else, but the app keeps on saying Home for the devices (that are indeed home, but I just want it to show the address).

This started I think with the last OS update.

1 Like

Thanks, so it’s not just me - good to know.

And thanks again for your alternative set address stuff. This is a big jump forward.
Much appreciated.

Next objective is to make it work for all airtags (screen swiped upwards).
I still get unknown for the input_text.airtag

1 Like

Hello and thanks to @TiToTB (by the way, your site is awesome) for this great work and especially for the excellent tutorial that makes implementing this solution so easy. For my part, the entire HA part works perfectly for me. The only issue I encounter is with the ‘shortcut’ part. When the screenshot is taken to populate the ‘input_text.airtag’, sometimes the address details are not displayed on the tracking object. I have to click on the object in question for the address to appear. As a result, I get a completely inaccurate and therefore false address. The goal is obviously to automate this, so I am asking for your help to see if there is a way to automatically display the details of the object without any manual action. Thanks in advance for your help.



Sorry for my bad english

1 Like

Hi, I don’t know why but I simply cannot use it anymore. Basically the shortcut runs but input_text.airtag is not populated.

I noticed this in the shortcut.

Can it be related?

1 Like

Thanks!! :blush::blush:

It happens when your airtag has not sent any signal for a while. Current version detects It through ‘:’ character and It should tell you.

To check last known position automatically we need to open every item somehow. For now i haven’t found i way to do that, but i ll try again with new versión.

It seems that you are using an older version of the shortcut, are you?

No I confirm I use latest version. I also deleted previous one and readded from the link in your site and I confirm there is still that voice in spanish “dividir texto” in it

Do you know if your iPhone is getting the info? Even ir It is not send to ha?

Merci pour la précision. Ca me rassure, c’est bien ce que j’avais compris :slight_smile:

Dans ce cas, hâte de voir la suite de ton travail.
Merci encore

1 Like

hello,
I also had probem whit home and had to add a line feed caracter, to get it working

resource_template: >
    {% set address = states('input_text.airtag').split('eze')[1].split('•')[0] %}
    {% if address == "\nDomicile " %}
      {% set home = "251 hugues-pommier, boucherville" %}

but now i got no location in my sensor, the problem is related to the json part

 value_template: "{{ value_json.results[0].formatted }}"
  json_attributes_path: "$.results[0]"
  json_attributes:
      - lon
      - lat
      - district
      - city
      - postcode
      - street
      - housenumber
      - state
      - country
      - country_code
  verify_ssl: true
  scan_interval: 900 # every 15 min
  force_update: true

geoapify return that:


{"results":[{"country_code":"ca","street":"Rue Hugues-Pommier","country":"Canada","county":"Longueuil","datasource":{"sourcename":"openstreetmap","attribution":"© OpenStreetMap contributors","license":"Open Database License","url":"https://www.openstreetmap.org/copyright"},"state":"Quebec","city":"Boucherville","state_code":"QC","lon":-73.455478,"lat":45.590507,"result_type":"street","formatted":"Rue Hugues-Pommier, Boucherville, QC, Canada","address_line1":"Rue Hugues-Pommier","address_line2":"Boucherville, QC, Canada","timezone":{"name":"America/Toronto","offset_STD":"-05:00","offset_STD_seconds":-18000,"offset_DST":"-04:00","offset_DST_seconds":-14400,"abbreviation_STD":"EST","abbreviation_DST":"EDT"},"plus_code":"87Q8HGRV+6R","plus_code_short":"HGRV+6R Boucherville, Longueuil, Canada","rank":{"popularity":5.576076178012012,"confidence":0.5,"confidence_city_level":1,"confidence_street_level":1,"match_type":"match_by_street"},"place_id":"510a83328d265d52c0599087bebb95cb4640c00204e203256f70656e7374726565746d61703a7374726565743a706f6c796c696e653a39333630383738","bbox":{"lon1":-73.455963,"lat1":45.589445,"lon2":-73.45432,"lat2":45.591479}}],"query":{"text":"251 hugues-pommier, boucherville","parsed":{"housenumber":"251","street":"hugues-pommier","city":"boucherville","expected_type":"building"}}}

after getting the input from the shortcut:

input_text.airtag:
eze Domicile • Maintenant Partagé avec Nancy Objets partagés avec moi Chien - 7Ak Avec vous Personnes Appareils Objets Moi

sensor:
latitude: null
longitude: null
status: available
last_update: 26/06/2024 13:31h
icon: mdi:bag-personal
friendly_name: cle_eze

thanks for your help

got it centrered on this


so the eroor is somewhere in there:

##resource: https://api.geoapify.com/v1/geocode/search?text=251%20hugues-pommier%2C%20boucherville&apiKey=95f133a4aaa04d5cba7b0f39ee2d81b7&format=json ## working part

  resource_template: >
    {% set address = states('input_text.airtag').split('*eze')[1].split('•')[0] %}
    {% if address == "\nDomicile " %}
      {% set home = "251 hugues-pommier, boucherville" %}
      {{
        https://api.geoapify.com/v1/geocode/search?text=
        + home | urlencode
        + "&apiKey=95f133a4aaa04d5cba7b0f39ee2d81b7&format=json"
      }}
    {% else %}
      {% set fix = address + " ,boucherville" %}
      {{
        https://api.geoapify.com/v1/geocode/search?text=
        + fix | urlencode
        + "&apiKey=95f133a4aaa04d5cba7b0f39ee2d81b7&format=json"
      }}
    {% endif %}

I just saw that you typed a blank space after “Domicile”. Try to remove It!

also add .strip().lower() to the end of the line, thay way you dont have to be concerned about spaces at the beginning or end, or upper/lowercase. Not sure if it also removes the new line, but you could try this:

{% set address = states('input_text.airtag').split('*eze')[1].split('•')[0].strip().lower() %}
{% if address == "domicile" %}

And I prefer this check as it just checks if the domicile is in the string, so the new line would have no effect.

{% if “domicile” in address %}

1 Like

thanks for that simplier test, it make the works whitout the space and the \n

resource_template: >
    {% set address = states('input_text.airtag').split('eze')[1].split('•')[0] %}
    {% if "Domicile" in address %}
    {% set home = "251 hugues-pommier, boucherville" %}

tested it in developement tool and this works but was also working with the /n and the space in a non fashion way.

the .strip().lower() %} dosn’nt work, return list object has no element 1

but i do some testing and it look like my problem is with the json attribute path.
I set the return from geoapify in the value_json to test it, and does not seem to work

- platform: rest
  name: airtag_cle_eze_geo
   {% set value_json = {
   "results":[
      {
         "country_code":"ca",
         "street":"Rue Hugues-Pommier",
         "country":"Canada",
         "county":"Longueuil",
         "state":"Quebec",
         "city":"Boucherville",
         "state_code":"QC",
         "lon":-73.455478,
         "lat":45.590507,
         "result_type":"street",
         "formatted":"Rue Hugues-Pommier, Boucherville, QC, Canada",
         "address_line1":"Rue Hugues-Pommier",
         "address_line2":"Boucherville, QC, Canada",
         "timezone":{
            "name":"America/Toronto",
            "offset_STD":"-05:00",
            "offset_STD_seconds":-18000,
            "offset_DST":"-04:00",
            "offset_DST_seconds":-14400,
            "abbreviation_STD":"EST",
            "abbreviation_DST":"EDT",
            }
            }
            ]
            }%}

  value_template: "{{value_json.results[0].formatted}}"
  json_attributes_path: "$.results[0]"
  json_attributes:
      - lon
      - lat
      - district
      - city
      - postcode
      - street
      - housenumber
      - state
      - country
      - country_code
  verify_ssl: true
  scan_interval: 10 # every 15 min
  force_update: true

the dev tool give me that return:

value_template: “Rue Hugues-Pommier, Boucherville, QC, Canada”
json_attributes_path: “$.results[0]”
json_attributes:
- lon
- lat
- district
- city
- postcode
- street
- housenumber
- state
- country
- country_code
verify_ssl: true
scan_interval: 10 # every 15 min
force_update: true

resource_template: >

  https://api.geoapify.com/v1/geocode/search?text=251%20hugues-pommier%2C%20boucherville&apiKey=APIKEY&format=json

I don’t see any error in log but maybe find an hint. Now I’m handling 4 AirTags and in my idea the text is longer than 255 and so it is not imported in input_text and sensor and automation are no longer triggered.

There’s a way to split text before sending it to ha?

Maybe creating input_text.airtag1 input_text.airtag2 or something similar?

Since we are using ‘*’ to identify airtag text, yes you can modify the shortcut to split the data into two different helpers!

1 Like

Ok. I’ll search the web to learn how to do it . If you can point me to some learning content I’ll appreciate that. :grinning:

To be honest, this is the first time i use shortcuts since i am not Apple user :sweat_smile:

Anyway, i think it should be simple if you read the shortcut. Try to clone the shortcut pointing to different helpers, then play with the Index number after splitting text.