AirTag "integration" (user friendly + device tracker)

Btw the guide asks us to change the format in FindMy, which could be related. How can we change the format is not included in the guide.

I also normally get this, but then I reload the config, and it works. Only reload the config, not HA itself.

Thanks for the suggestions @john2014 @Vahaldor. Like you, I wasn’t seeing any geoapify utilization unless I access geoapify directly from a browser via an http call using my literal address (and several other static addresses just for good measure). That works fine. When I think set my text helper to the same literal/static address, I still can’t get the sensor to set its state nor return long/lat.

There’s a comment by @BA8870 above in this thread about adding “trim” to the end of the set address line in the code. I tried that and it didn’t change the behavior.

I’m stumped. I’ve included the full log error below in case it helps anyone find a clue.

Log Error Detail

Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:197
integration: Template (documentation, issues)
First occurred: 1:21:14 PM (4 occurrences)
Last logged: 1:21:14 PM

  • TemplateError(‘UndefinedError: list object has no element 1’) while processing template ‘Template<template=({% set home = “Christina” %} {% if “:” in states(‘input_text.airtag’).split(‘Briefcase’)[1].split(’•‘)[0] %} {{ states(‘input_text.airtag’).split(‘Briefcase’)[1].split(’•‘)[0].split(’,‘)[0] }} {% elif home in states(‘input_text.airtag’).split(‘Briefcase’)[1].split(’•‘)[0] %}Home {% else %} {{ states(‘sensor.airtag_briefcase_geo’) }} {% endif %}) renders=8>’ for attribute ‘_attr_native_value’ in entity ‘sensor.airtag_briefcase’
  • TemplateError(‘UndefinedError: list object has no element 1’) while processing template ‘Template<template=({% if “:” in states(‘input_text.airtag’).split(‘Briefcase’)[1].split(’•‘)[0] %}null {% else %}{{ state_attr(‘sensor.airtag_briefcase_geo’,‘lat’) }} {% endif %}) renders=8>’ for attribute ‘latitude’ in entity ‘sensor.airtag_briefcase’
  • TemplateError(‘UndefinedError: list object has no element 1’) while processing template ‘Template<template=({% if “:” in states(‘input_text.airtag’).split(‘Briefcase’)[1].split(’•‘)[0] %}null {% else %}{{ state_attr(‘sensor.airtag_briefcase_geo’,‘lon’) }} {% endif %}) renders=8>’ for attribute ‘longitude’ in entity ‘sensor.airtag_briefcase’
  • TemplateError(‘UndefinedError: list object has no element 1’) while processing template ‘Template<template=({% if “:” in states(‘input_text.airtag’).split(‘Briefcase’)[1].split(’•‘)[0] %}unavailable {% else %}available {% endif %}) renders=8>’ for attribute ‘status’ in entity ‘sensor.airtag_briefcase’

For others experiencing the same problem as me, this was the solve. For me, restarting HA only was insufficient.

@TiToTB, one detail question in your sensor YAML code: the sensor is named “airtag_ITEM_geo” everywhere except line 31 in your code, which is “airtag_ITEM” (no _geo suffix). Is this difference intentional? I ask because I am getting two sensors for each airtag, one with the _geo suffix and one without. Is this expected behavior.

Thanks for this awesome integration!

1 Like

Yes It is.

The “geo” sensor gets coordinates from de api. The other sensor has a custom behavior, as you can see in the template.

Thanks! :smiley:

1 Like

Thank you so much @TiToTB for this project! I found your website and I have my AirTags - device trackers running already on HA.

As I aim to use it for an automation in case my car is stolen I’m running the shortcuts on an old IPhone which is always active and unlock. My question is for the users that are using it as well for a close track. Do you know how many shortcuts can I create? I created 96 of them (every 15min) and I’m constantly receiving the error INCExtensionErrorDomain 1307, I found that this error is due to timeout in the process, but I don’t know if the cause is my old phone capacity of process of the amount of shortcuts I have.

Does anyone find the way to create only one shortcut to run every X minutes?

Do you know if there is a maximum amount of quantity of shortcuts that could affect the process?

Tito if you think it’s worth it I can ask about it on your telegram channel, I joined a couple of days ago but it’s hard to follow because I’m a newbie.

Thank you all!

Saludos desde Madrid :smile:

Manuel

1 Like

Thanks Manuel! Of course you can ask anything you want in our community :slight_smile:

I also started to create a lot of shortcuts to have it activate every X minutes, but I was getting way annoyed by adding them. I then noticed that in the latest ios version you can also trigger it by listening to a certain email with an automation.

So now I just send and email to myself from HomeAssistant every 5 minutes with a certain subject and that will then trigger the shortcut.

I have script running in gmail ( My Projects - Apps Script (google.com) ) to delete all the send and received mails (it is sent from the same address as it is receiving on) every 30 minutes to not fill my email with the trigger emails.

2 Likes

Hi @john2014 , it sounds nice and eaiser, and most important not that killing for the old Iphone compared to the many time checkers (I hope). Would you please give me some indications to do it?
How do you schedule emails from HA?
What exactly should I search for on Gmail for the scripts? it would be my first time as well. I’m sorry for silly questions, it’s only a couple of weeks since I joined this world : )

Thank you in advance!

Be aware, you do need an iphone that runs IOS 17 I think as older ones can not be triggered by an email.

To add gmail to HA, see Google Mail - Home Assistant (home-assistant.io) . Then with an automation you can just schedule a mail with an automation that runs every 5 minutes.

This is the script i run every hour in Apps Script – Google Apps Script
( i coped it from somewhere so dont mind the ebay reference in the name :slight_smile: )

function removeOldEbayEmails(){

  // Define the search string to identify emails 
  var searchString = "subject:'Update Location items'  older_than:1h ";

  // Get all threads matching search string
  var threads = getThreadsMatchingSearch(searchString);

  // Check whether thread search returned some results
  if (typeof threads !== 'undefined' && threads.length > 0) {
    
    // Mark as read and remove threads
    moveThreadsToTrash(threads);
  }  
}


function getThreadsMatchingSearch(searchString){

  // Get all threads matching search string
  try{
    var threads = GmailApp.search(searchString);
  Logger.log("Found " + threads.length + " threads (conversations of emails) matching search string (" + searchString + "). Note that size limited to 500.");
  }
  catch(error){
    Logger.log("Warning! Unable to complete email search: " + error.message);
  } 

  return(threads);
}


function moveThreadsToTrash(threads, batchSize=100){

  // Work through the threads in batches (100 is the limit that batch operations can work on)
  for (j = 0; j < threads.length; j += batchSize) {

    // Select the current batch of threads
    var batch = threads.slice(j, j+batchSize);
    
    // Move the threads to the trash
    try{
      GmailApp.moveThreadsToTrash(batch);
      Logger.log("Moved " + batch.length + " threads to trash.");
    }
    catch(error){
      Logger.log("Warning! Unable to move threads to trash: " + error.message);
    }    
  }
}
1 Like

Hello!

I was trying notify setting in configuration.yaml, then a script to finally create the automation. First step didn’t work, that’s why I asked you about it. And seems to be a different method. I’ll try it.

I just checked the old siphon running iOS 15 and apparently it seems to have the email trigger. Thank you for the support!

I remember there was something about email support in automation, but forgot what it exactly was, just found it.

iOS 15 will support an email trigger, but it will not be able run automatically. See this page:

Enable or disable a personal automation in Shortcuts on iPhone or iPad - Apple Support

If you choose iOS 17 then you will see that email is added to the automatic triggers. So you will need iOS 17, because you want the shortcut to be triggered without human intervention.

hey John, yes, I ended up with that confirmation message. Furtunatelly I could get an iOS 17 device, I’ll work on that and come back if something else is needed. Thank you so much for your support!

Hi John, I have set the Iphone with iOs 17 + Google script and everything is working just fine now.

The only point that I think that could be improved is the interval of time of the Iphone to “hear” the emails. It means it’s not always every 15min or so, but some time it takes an hour, then the next email is heard couple of minutes later. I add a screenshot as an example.

Did you face this “issue”? my Maill app setting is push notification and “every 15 min”, as “automatically” option seems to be working only when the device is charging + connected to WiFi. In my case I have schedule it to charge 4 times (30min each) a day, so not always plugged into power.

I don’t know if receiving the email every 5 - 10min (current15min) would help, as it seems to be a refresh related issue.

If you found a better setting please share it : )

I haven’t tried Gmail app yet… could it be better for receiving the emails on time?

Thank you!

Hi, I think I’m facing your same issue and maybe found the reason (but not the solution): tracking a lot of devices (4 in my cases) shared with my wife create a string that is longer than 255 characters (limit of HA) so input_text is not created correctly and automation does not works.

My workaround was to create 2 automation one to manage 2 devices and the other to manage other 3 devices but it would be great to find a better solution. @TiToTB any hint? There’s a way to reduce text to send to HA ?

With last version i experimented with clic simulation, in order to get info from each airtag and additional information. I was close, but didn’t succeed.

To be honest, i haven’t tried anymore, but i think that could be the way

Thank you for the help and @TiToTB for his great accomplishment / website / support.

I’m not familiar at all with Apple but trying the stuff on iphone of my wife.

I’m testing this airtag through HA and shortcut was running fine with one device but when I added the second airtag, I’m not receiving anymore the data to the input. Do I need to create 2 input_text ?

Where can I found the documentation about Shortcuts ?

hi there!
I gave up with the refresh time through emails, I guess refreshing the status every 30-40 min max is not that bad : )

I was working very well with 2 Airtags, but yesterday I added 4 more clones to the family and it seems to be very long text for the helper.

Is it possible to maximize the lenght of the parameter? We fixed it as 255 when we created the helper but I don’t know if this is a system restriction for helpers-text or it was self-set. I just read the whole thread and somebody wrote that he figured it out that we can change this value… I have tested it changing it to 1000 and when running the shortcut the status of the helper changed to Unknown… therefore I understand that this is not possible…

@Jokerigno I saw you got a way to deal with it… I’ll try to work on it later today. Why do you want to improve it? is it failing somehow?

Thanks!!!

1 Like

hi again! I could set the shortcut to trigger 3 call service to HA by defining a variable after segmenting by *.

Now I have 3 helpers. Could you please help me out on how to merge and clean them to make them fit into 255 lenght value?? I’m sorry if this question is getting out of this project. I think it could help ppl with many devices.

Thank you in advance for support!

1 Like

I tried to do it but without success. I have here the part your are missing:

alias: Airtag Meta Input Text
description: ""
trigger:
  - platform: state
    entity_id:
      - input_text.airtag1
      - input_text.airtag2
condition: []
action:
  - metadata: {}
    data:
      value: >-
        {{ states('input_text.airtag1') | replace("Identifica un oggetto
        trovato", "") | replace("Ce l'hai tu", "") | replace("Ultimo
        rilevamento","") | replace("Ce l'hai tu", "") | replace("Persone", "")|
        replace("Persone", "") | replace("Dispositivi", "") | replace("Oggetti",
        "") | replace("Condiviso con Irene", "") }} {{
        states('input_text.airtag2') | replace("Identifica un oggetto trovato",
        "") | replace("Ce l'hai tu", "") | replace("Ultimo rilevamento","") |
        replace("Ce l'hai tu", "") | replace("Persone", "")| replace("Persone",
        "") | replace("Dispositivi", "") | replace("Oggetti", "") |
        replace("Condiviso con Irene", "")}}
    target:
      entity_id: input_text.airtag
    action: input_text.set_value
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - metadata: {}
    data: {}
    action: rest.reload
mode: single

Please notice that text like “Identifica…” is the text in my local language that i want to replace with “”. With this tricki merge the 2 input_text coming from the two shortcuts in the regular input_text.airtag shorter than 255 used by the automations.