Integrating Ampache with Home Assistant Using Last.FM as a Bridge

If you’ve been looking for a way to integrate Ampache with Home Assistant, here’s a solid workaround using Last.FM.

I’m currently using Ampache 6.5.0. I can’t say for sure if the Last.FM plugin works in earlier versions, but this is the version I’ve confirmed it with.

  1. Create a Last.FM account** (if you don’t already have one). It’s free! :blush:
  2. Locate your ampache.cfg.php file**, usually found at:
    /var/www/html/ampache/config/
  3. Open the file with a text editor:
    nano ampache.cfg.php
    Then locate the lastfm_api_key and lastfm_api_secret fields, and update them with your Last.FM API key and secret.
  4. Generate your Last.FM API key and secret by visiting: https://www.last.fm/api/account/create
  5. In Ampache, go to Preferences (gear icon) → Plugins, then click the plug icon next to Last.FM to activate the integration.
  6. Once Last.FM is connected to Ampache, go to Home Assistant, add the Last.FM integration, and enter the same API key and your Last.FM username.

If everything is set up correctly, you should see sensor.lastfm and its state attributes in Home Assistant’s Developer Tools.

Note: the scrobbling sensor did not work for me. Not certain if this is a bug, i haven’t dug deeper. I was more interested in the attributes that came with the lastfm sensor.

  1. Now we can fetch those attributes and use them however you’d like. In this example, I’ll use a template by editing my configuration.yaml.
template:
  - sensor:
      - name: "LastFM Play Count"
        state: "{{ state_attr('sensor.lastfm_suflylatinoguy', 'play_count') }}"
      - name: "LastFM Last Played"
        state: "{{ state_attr('sensor.lastfm_suflylatinoguy', 'last_played') }}"
      - name: "LastFM Top Played"
        state: "{{ state_attr('sensor.lastfm_suflylatinoguy', 'top_played') }}"

  1. Go ahead and add an Entity Card in your dashboard—it should look something like this:

Now, anything that you play in Ampache will be displayed in Home Assistant :slight_smile: