Ideas to improve a time-based automation

I have a system/project where an automation is triggered every 2 minutes. It has conditions that limits the automation to only running when I am away from home.

The automation updates my phone GPS location and then pushes the data into a traccar server using a REST api

I do need the automation to run regularly when away from home but only if I am driving so I am trying to come up with a better (more efficient way).

I have a created sensors that calculates ‘speed’ and another one that hold the ‘age’ of last GPS location data but I am struggling to work out a way to use either of these sensors to improve the automation so that fires only when:

  1. way from home (using a device_tracker)
  2. GPS data is older than 60 secs
  3. current speed > 5kmh

The issue I have at the moment is that GPS data is polled from my phone every 2 mins the entire time I am away from home but I want it to only do regular updates when I am driving (> 5kmh).

Any ideas that I can try?

The Home Assistant companion app (Android and - I assume - iOS) opens up availability of an array of sensors that could be useful. This includes presence of Android Auto, bluetooth connection status, charging status, etc. These could potentially reveal if you are in your car.

Thanks. I do have the HA app myself but not using it for GPS as it interferes with the other ways I get GPS data (icloud).

The system I am creating needs to (and does) work for members of my family that do not have the HA app installed - using icloud family sharing.

I wish people would include actual details of their sensors: IDs, states, units etc. Here’s an attempt with made-up substitutes — it’s the usual “trigger off any of them, check all of them” pattern that runs the action as soon as all three become true:

trigger:
  - platform: state
    entity_id: device_tracker.XXX
    to: 'not_home'
  - platform: numeric_state
    entity_id: sensor.gps_data_age_seconds
    above: 60
  - platform: numeric_state
    entity_id: sensor.speed
    above: 5
condition:
  - condition: state
    entity_id: device_tracker.XXX
    state: 'not_home'
  - condition: numeric_state
    entity_id: sensor.gps_data_age_seconds
    above: 60
  - condition: numeric_state
    entity_id: sensor.speed
    above: 5
action:
[YOUR ACTION HERE]

Thank you and apologies. I have something similar but the issue with all triggers being true at the same time is problematic due to the circular nature of calculating speed (as it needs GPS data do do it). I think this is the ‘real’ problem I need to solve.

here is the yaml for my main automation - that works but it is caning my mobile battery when I am away and not driving. So I think I need a a way to detect ‘driving’ somehow.

alias: "Jago iCloud GPS Away Trigger "
description: ""
trigger:
  - platform: time_pattern
    minutes: /2
condition:
  - condition: state
    entity_id: device_tracker.jago_comp
    state: not_home
  - condition: numeric_state
    entity_id: sensor.jago_speed_icloud_gps_age
    above: 60
action:
  - service: icloud3.action
    data:
      command: Locate Device(s) using iCloud FamShr
      device_name: xxxxxxxxx
  - service: script.icloud_gps_update
    data:
      GPS_update: Jago
      GPS_trigger: Away
mode: single

the other automation I have been trying (that does not work) is…

alias: iCloud GPS Update Jago
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.jago_speed_icloud_gps_age
    above: 90
condition:
  - condition: numeric_state
    entity_id: sensor.jago_speed_icloud_kmh
    above: 5
action:
  - service: icloud3.action
    data:
      command: Locate Device(s) using iCloud FamShr
      device_name: xxxxxxxxx
    enabled: true
  - service: script.icloud_gps_update
    data:
      GPS_update: Jago
      GPS_trigger: Update
    enabled: true
  - service: notify.persistent_notification
    metadata: {}
    data:
      title: iCloud GPS Update
      message: GPS Update triggered for jago!
    enabled: false
mode: single

and another that works - but only runs once to catch the transition from home/away

alias: iCloud GPS State Trigger Jago
description: ""
trigger:
  - platform: state
    entity_id:
      - person.jago_taylor
condition:
  - condition: numeric_state
    entity_id: sensor.jago_speed_icloud_gps_age
    above: 60
action:
  - service: icloud3.action
    data:
      command: Locate Device(s) using iCloud FamShr
      device_name: xxxxxxxx
  - service: script.icloud_gps_update
    data:
      GPS_update: Jago
      GPS_trigger: State
mode: single