#Get location from the tablet's coordinates
1 messages · Page 1 of 1 (latest)
the issue is that I'm trying to use ChatGPT to generate a proper automation but his code isn't accepted by HA cause "it doesn't match the LEGACY_SYNTAX" while i'm running the latest HA in supervised mode
here's the code it generated:
-
id: "adaptive_update_home_zone_from_tablet"
alias: Adaptive Update Home Zone from Tablet GPS
description: "Update HA home location using SM-X910 tablet GPS: hourly if still, every 5 min if moving"
triggers:Hourly update (minimum)
- trigger: time_pattern
hours: "/1"
Frequent update every 5 minutes when moving
- trigger: time_pattern
minutes: "/5"
conditions: []
actions:
Update latest tablet location
- service: homeassistant.update_entity
entity_id:- device_tracker.sm_x910
- sensor.sm_x910_geocoded_location
Short delay to allow sensors to update
- delay: "00:00:10"
Read coordinates and previous home coordinates
- variables:
lat: "{{ state_attr('device_tracker.sm_x910', 'latitude') }}"
lon: "{{ state_attr('device_tracker.sm_x910', 'longitude') }}"
home_lat: "{{ state_attr('zone.home', 'latitude') }}"
home_lon: "{{ state_attr('zone.home', 'longitude') }}"
distance_m: >-
{% set dx = (lat - home_lat) * 111000 %}
{% set dy = (lon - home_lon) * 111000 %}
{{ (dx2 + dy2)**0.5 }}
Skip if coordinates missing
- condition: template
value_template: "{{ lat is not none and lon is not none }}"
Only update if moved >50m or at top of the hour
- condition: or
conditions:- condition: template
value_template: "{{ distance_m > 50 }}" - condition: template
value_template: "{{ (distance_m <= 50) and (now().minute == 0) }}"
- condition: template
Update HA home location dynamically using tablet GPS
- service: homeassistant.set_location
data:
latitude: "{{ lat | float }}"
longitude: "{{ lon | float }}"
mode: single
- trigger: time_pattern