I ride bikes. Strava is cool. Their API… is pretty good.
I’ve been using rest sensor lately to pull some info like stats, most recent ride etc.
Why? I don’t know really, but it’s neat and I can put all the data into graphs. Graphs are cool.
- platform: rest
name: strava_ride_last_miles
resource: https://www.strava.com/api/v3/athlete/activities
method: GET
headers:
Authorization: Bearer API_TOKEN
value_template: '{{ value_json[0].distance | multiply(0.000621371) | round(1) }}'
unit_of_measurement: mi
scan_interval: 300
And even send notifications of summary of rides uploaded by specific users, something Strava does not support in their current mobile applications:
- alias: Notify Last Team Ride
trigger:
- platform: state
entity_id: sensor.strava_last_team_ride_profile
condition:
condition: template
value_template: "{{ states('sensor.strava_last_team_ride_profile') != 'unknown' }}"
action:
- service: notify.ios_myiphone
data_template:
message: "{{ states('sensor.strava_last_team_ride_name') }} just uploaded a ride titled: {{ states('sensor.strava_last_team_ride_title') }} to Strava traveling {{ states('sensor.strava_last_team_ride_distance') }} miles at an average of {{ states('sensor.strava_last_team_ride_avg_speed') }}mph at {{ states('sensor.strava_last_team_ride_avg_watts') }} watts and an average HR of {{ states('sensor.strava_last_team_ride_avg_hr') }}bpm"
data:
subtitle: "via Strava"
attachment:
url: "{{ states('sensor.strava_last_team_ride_profile') }}"
content-type: jpeg
hide-thumbnail: false
Thoughts so far…
Strava’s API rate limit is not conducive to creating rest_sensors for all the data you’d like to pull. Use of throttling through a sensor component would be ideal but scan_interval helps.
Another way I’ve dealt with this, it to pull only a handful of specific types of requests that retrieve all the json data from Strava and then use template sensors to build what information I want to see in a card or notification.
It would be ideal to create some sensors that have attributes in order to assign profile pictures, decode polylines to display a small map of the activity, names or titles as entity_id, entity_picture etc… but the only way I think that can be done is to actually create a sensor component.
A good starting point looks to be using Stravalib as the library. I’ve started poking around with some options but it’s been slow going so far.
For now the rest and template sensors seem to work pretty well. I’m really not sure how much interest there is in this but I’d personally like to see it happen for a few reasons:
- Would add another component to the very lonely Health category.
- Possibly use example example for similar types of services like Garmin, Withthings, etc.
- Explore use of encode/decode polyline data for use in existing or future Homeassistant components.
Let me know your thoughts.