The LastFM Scrobbler integration allows tracks played on selected media players to be scrobbled directly to a user's Last.fm account. This document provides instructions on how to set up and use the LastFM Scrobbler integration with Home Assistant.
- Ensure that you have a working installation of Home Assistant.
- Install HACS following the official instructions.
- A valid Last.fm account is required. Create one here if you don't have one.
- Obtain your API Key and API Secret by creating a new API application on Last.fm here.
Install Python from the official Python website. Ensure you have Python 3.x installed on your machine.
-
Install the
pylast
library using pip:pip install pylast
-
Create a new Python script get_session_key.py with the following content, replacing "your_lastfm_api_key" and "your_lastfm_api_secret" with your actual Last.fm API Key and API Secret:
import pylast import getpass API_KEY = "your_lastfm_api_key" API_SECRET = "your_lastfm_api_secret" username = input("Enter your Last.fm username: ") password = getpass.getpass("Enter your Last.fm password: ") password_hash = pylast.md5(password) network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=API_SECRET, username=username, password_hash=password_hash) session_key = network.session_key print(f"Your Session Key: {session_key}")
-
Run the script in your terminal or command prompt:
python get_session_key.py
-
Follow the prompts to enter your Last.fm username and password. The script will display your session key.
- Ensure you have HACS installed in your Home Assistant instance.
- Go to HACS -> Integrations -> ... (three dots in the top right corner) -> Custom repositories.
- Add the repository URL:
https://github.com/valentin-gosselin/lastfm-scrobbler-ha-integration
, with the category: Integration. - Click on "Add".
- Now you should see the LastFM Scrobbler Integration available in HACS under "Integrations".
- Click on it and then click on "Install".
- Restart Home Assistant to load the new integration.
- Clone or download this GitHub repository.
- Copy the
lastfm_scrobbler
directory from the repository to yourconfig/custom_components
directory in your Home Assistant configuration directory. - Restart Home Assistant to load the new integration.
As of version 1.3.0, configuration via configuration.yaml
is no longer supported. You must delete any lastfm_scrobbler
entries in your configuration.yaml
file and migrate to the GUI-based ConfigFlow.
- Remove the old YAML configuration:
# Remove this from your configuration.yaml lastfm_scrobbler: API_KEY: !secret API_KEY API_SECRET: !secret API_SECRET SESSION_KEY: !secret SESSION_KEY
- Restart Home Assistant to apply the removal.
-
Go to Settings -> Devices & Services in Home Assistant.
-
Click Add Integration and search for LastFM Scrobbler.
-
Follow the on-screen prompts to:
- Provide your Last.fm API credentials (API Key, API Secret, and Session Key).
- Configure your scrobbler's behavior, including the percentage of the track to scrobble, and whether to update "Now Playing".
- Select one or more media players to scrobble from.
- Optionally, set up entity conditions (
check_entities
) to control when scrobbling is allowed (e.g., only when you're home or a specific switch is on).
-
Repeat these steps for each additional Last.fm account or source configuration.
Once the integration is set up:
- Simply play music on any of the configured media players.
- The integration will scrobble tracks automatically to Last.fm according to the settings you defined in ConfigFlow.
- Use
check_entities
to control scrobbling with automation-friendly entities, such as:- Persons: Only scrobble when specific people are home (
person.my_name == "home"
). - Switches: Activate or deactivate scrobbling via a toggle switch (
switch.scrobble_toggle
). - Input booleans: Use automations to turn scrobbling on or off.
- Persons: Only scrobble when specific people are home (
If scrobbling isn't working as expected, check the Home Assistant logs for any errors related to the LastFM Scrobbler integration. Filter the logs using keywords such as "scrobble" to quickly identify relevant entries.
You can also set the log level to debug
for this integration in your configuration.yaml
to get more detailed log messages:
logger:
default: info
logs:
custom_components.lastfm_scrobbler: debug