I did something similar with my pepwave (which also has a GPS antenna and API access to some features of the router.) (Well, I say “did” but I really ripped it off from here.) Here is my pared-down usage, which only covers your question:
In my rest.yaml (referenced in configuration.yaml via rest: !include rest.yaml
):
- resource_template: "https://192.168.50.1/api/info.location?accessToken={{ states('sensor.pep_token') }}&connId=2"
scan_interval: 300
verify_ssl: false
sensor:
- name: pep_gps
value_template: "{{ value_json.response.gps }}"
json_attributes_path: "$.response.location"
json_attributes:
- "latitude"
- "longitude"
- "altitude"
- "heading"
- "timestamp"
- name: pep_speed
value_template: "{{ ( value_json.response.location.speed ) | round(0) }}"
Where sensor.pep_token holds an access token that is also updated automatically:
- resource: "https://192.168.50.1/api/auth.token.grant"
scan_interval: 172700
verify_ssl: false
method: POST
headers:
Content-Type: application/json
payload: '{"clientId":"my_client_id","clientSecret":"my_client_secret","scope":"api"}'
sensor:
- name: pep_token
value_template: "{{ value_json.response.accessToken }}"
(Note that pep_token is required because of the authentication method that my router’s API requires; your needs may vary.)
This is my recent history for sensor.pep_gps, e.g.:
Finally, the automation that updates my home location based on the sensor.pep_gps attributes that are updated above:
alias: Set Home Location from Pepwave
description: ""
triggers:
- entity_id: sensor.pep_gps
trigger: state
actions:
- data:
dev_id: pepwave
gps:
- "{{ state_attr('sensor.pep_gps', 'latitude') }}"
- "{{ state_attr('sensor.pep_gps', 'longitude') }}"
action: device_tracker.see
- data_template:
latitude: "{{ state_attr('sensor.pep_gps', 'latitude') }}"
longitude: "{{ state_attr('sensor.pep_gps', 'longitude') }}"
action: homeassistant.set_location
Hope this helps!