I like to listen to music and scrobble to Last.fm throughout the day - keeping track of my listens is a good way to refresh my playlists. The players I use are all Home Assistant integrations, and while some of them have native Last.fm integrations, some only scrobbled when i was playing local tracks (vs streaming) and some had no Last.fm integration at all. So, I decided to write my own.
Full details are available in the github repository.
There are several ways to set this up and the full readme can guide you for several of the options. You’ll need an automation that sends media player events from Home Assistant to the ha-scrobble.py function and you can either use yaml based automation or Node-RED. The full-readme.md doc presents how to do this.
To start, you can clone the repo to the ha-scrobble directory in your Home Assistant user’s home directory, e.g.,
git clone https://github.com/yajrendrag/ha-scrobbler.git ha-scrobble
and follow the directions in the readme or full-readme doc in the repository.
From an overall media flow perspective, what this does is to capture the media player event data from Home Assistant, examine it to determine when a music track is scrobble-able, and when it is, it sends that metadata to your Last.fm account library via the Last.fm API.