Garmin LiveTrack tracking package šŸ—ŗļø

Hi, cool project, inspired me to write some alternative because I use HA in docker and have difficulties to make imap sensors works I created fork of project:
GitHub - t-soltysiak/garmin-livetrack-to-json: Automatic Garmin livetrack stats to JSON (e. g. for Home Assistant) which is simple http json server that can be used to create template rest sensors which will base on localhost port.

Thanks for sharing this! Iā€™m just getting it setup now, and I think itā€™s close to working, but I am receiving the following error

2023-08-20 09:55:54.196 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('ZeroDivisionError: float division by zero') while processing template 'Template<template=({{ 16.666666667/(states.sensor.garmin_livetrack.attributes.speed) if 'speed' in states.sensor.garmin_livetrack.attributes }}) renders=26>' for attribute 'pace' in entity 'binary_sensor.garmin_livetrack'

any thoughts? Iā€™m looking at the logic and I canā€™t quite grasp why this is happening, because it looks correct to me:

pace: "{{ 16.666666667/(states.sensor.garmin_livetrack.attributes.speed) if 'speed' in states.sensor.garmin_livetrack.attributes }}"

If
states.sensor.garmin_livetrack.attributes.speed is 0 you will get that ZeroDivisionError error. I didnā€™t though of that.
You could use:

pace: "{{ 16.666666667/(states.sensor.garmin_livetrack.attributes.speed) if 'speed' in states.sensor.garmin_livetrack.attributes and float(states.sensor.garmin_livetrack.attributes.speed) > 0 }}"

:man_facepalming: ahh yeah, didnā€™t think of that. thanks!

Just setting this up now: bit confused by this section of the code:

  - alias: "Turn on automations with actions depending on Livetrack"
    service: automation.turn_on
    entity_id: 
    - automation.garmin_livetrack_kilometer
------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I donā€™t see the referred automation within your package file ā€” what is that referring to? Is it something that you originally wrote that wasnā€™t needed when trigger-based template sensors were released? Leaving it in gives:

image

Also:

- binary_sensor:
  - name: Garmin Livetrack
    state: "{{ is_state_attr('automation.garmin_livetrack', 'current',1) }}"
------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^

The automation, if pasted from your code, is called automation.garmin_livetrack_new_link.

With that fixed, it appears to work perfectly on first test: email to my own account gets detected, and pulls in the data. I then set up a conditional card when the binary sensor is on to show a vertical stack of the LiveTrack link and a map card feeding off the position in the binary sensorā€™s attributes.

Thanks for saving me a stack of work!

1 Like

You could remove that part:

- alias: "Turn on automations with actions depending on Livetrack"
    service: automation.turn_on
    entity_id: 
    - automation.garmin_livetrack_kilometer

Thatā€™s activating an other automation that trigger after some running distance.
Itā€™s not included in the packade.

This is next on my list of integrations to attempt! :crossed_fingers:

Hi, do you know why the links are not extracted right way on my end?

Itā€™s looks that the <a href in the mail misses the ".

Try to change to > insted of " in the regex:

token/+[a-z0-9-\n\r=][^"]+)'
token/+[a-z0-9-\n\r=][^>]+)'

Hi,
I tried to add the package but somehow I have various sensors ā€žunavailableā€œ or ā€žoffā€œ. I set up the Imap-integration as well and that works so far.

Any help would be much appreciated. Enclosed two screenshots of the not working sensors in developer tools.


Edit: forgot to fetch the first 9200 bytes from the mailā€¦ now itā€˜s working

1 Like

Hi, now facing a problem when trying to use the attribute ā€œlinkā€ of the Garmin Live Track id sensor. Somehow various CSS/HTML attributes are being attached to the link which makes it hard to useā€¦

Anyone know how to solve this?

Thanks for your help

Try to change the regex sensor to:
https://livetrack.garmin.com/session/([a-z0-9-\n\r=]+)/token/([a-z0-9-\n\r=][^"]+)

Updated yaml in the top post.

Thanks for coming back to me. When I recall correctly the regex-part looked like this:


regex_findall(find='(https://livetrack.garmin.com/session/+[a-z0-9-]+/token/+[a-z0-9-]+)

I changed it to:


regex_findall(find='(https://livetrack.garmin.com/session/[a-z0-9-]+/token/[a-z0-9-]+)

Took out the ā€ž+ā€œ right after session/ and token/. that worked as wellā€¦

By the way, great package! I used it to show the original Garmin Livetrack Website on my dashboard

Hi there

can someone explain how i can use the imap integration and grab the url. i only get the number of unread emails.
i tried to follow the documentation but im a little bit confuesd.

Dennis

As written in: IMAP - Home Assistant
the integration will trigger events that you could fetch info from email.
Ex lock at the code in top post.

If the imap integration has been set up the entity just shows the no. of email. So that part should be fine. Did you correctly set up the package? Do you see the various garmin sensors?

Hi there

no I do not see them.
when i try to test the configuration is says:

  • Setup of package ā€˜input_textā€™ failed: Integration ā€˜garmin_livetrack_linkā€™ not found.

  • Setup of package ā€˜sensorā€™ failed: Invalid package definition ā€˜sensorā€™: expected a dictionary. Package will not be initialized

  • Setup of package ā€˜templateā€™ failed: Invalid package definition ā€˜templateā€™: expected a dictionary. Package will not be initialized

  • Setup of package ā€˜automationā€™ failed: Invalid package definition ā€˜automationā€™: expected a dictionary. Package will not be initialized

i made the folder package, added the package as a yaml file.

i also added to my configuration file :
homeassistant:
packages: !include_dir_merge_named packages


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
 themes: !include_dir_merge_named themes
 
homeassistant:
 packages: !include_dir_merge_named packages



automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml


Try:
packages: !include_dir_named packages

If you keep Garmin packade in separate file.

I get the url but the binary_sensor.garmin_livetrack stays off while i get the url.