Geofencing

Hi, I was just wondering: in some of my automations I use the ‘geofencing’ capabilities of the device_tracker items. I noticed that when I track a iphone, and use its, icloud address, it switches to the ‘gps’ source_type. This often goes wrong, when for example I try to track a phone that has mobile data turned off. When it leaves the WiFi range, and has no mobile data signal, the gps tracker keeps the last position, which does not get updated.
Is there any way around this? Can I turn off the use of the ‘gps’ source type?

Perhaps a template sensor that checks for the gps attribute?

Good idea, I will try that. Do you have an example?

I’m sorry, not really. Nothing that is based on a device tracker.

Ok, after scraping all kinds of information off the internet about Jinja2, templates, global variables, etc., I have a solution that works:
I made a binary sensor as follows, using the group ‘smart_phones’ to hold all of my mobile devices:

- platform: template
  sensors:
    phone_home:
      friendly_name: 'Phones at Home'
      device_class: presence
      value_template: >-
        {% set glob=namespace(phone_home=False) %}
        {%- for item in states.group.smart_phones.attributes.entity_id %}
        {%- set domain, device = item.split('.') %}
        {%- if states[domain][device].state == 'home' %}
        {%- set phone = states[domain][device].attributes.friendly_name %}
        {%- if states[domain][device].attributes.source_type != 'gps' %}
        {%- set glob.phone_home = True %}
        {%- endif %}
        {%- endif %}
        {%- endfor %}
        {{ glob.phone_home }}

So now I can use this sensor to check the presence of my mobile phones, using only the ‘router’ and ‘bluetooth’ source types (or any others that may be added later, except for ‘gps’).
Just wanted to share this.