codingcyclist / ha_strava

Pipe your Activity Data from Strava directly into Home Assistant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extract date from latest activity

nckslater opened this issue · comments

I have been using the Strava integration and love it.

I'm needing a bit of motivation to get up and go in the morning so I have set up an automation for my Google Home to let me know the weather and also the last time I ran and what disance.

I am having a problem with the date element of this.

The sensor that shows the last date and time is sensor.strava_0_0 (friendly name).

So I first added this to TTS:

Your last running day was on the {{ state_attr('sensor.strava_0_0', 'friendly_name'}}

But my Google Home read it out wrong. Ten point zero eight blah blah blah

So I then tried creating a sensor

 strava_last_date:
         friendly_name: strava last activity
         value_template: "{{ state_attr('sensor.strava_0_0', 'friendly_name') }}"

and splitting it:

Your last running day was on the {{states.sensor.strava_last_date.state.split(".")[0] }} of {{states.sensor.strava_last_date.state.split(".")[1] }}  with a distance of {{states.sensor.strava_0_3.state}}

But this also gets read out kind of wrong.

How can I convert my sensor (sensor.strava_last_date) to a date? Once I get it into a date I could then start playing around with TTS saying 'Your last running day was' yesterday, or 2 days ago ect

Much appreciated if someone could give me a hand.

I modified the integration to show the date as d/m/y so it looked better in the UI.. I assume this would also mean TTS could say it properly?

Look at line 374 in sensor.py

With that changed to %d/%m/%Y , my TTS (I use amazon_polly_say) correctly speaks the date (17th August 2021)

@wishie Awesome thank you 👍