Last.fm sensor values into UI

I’m using the Last.fm sensor, which is great. Lets me view my listening history no matter what app I’m using to listen.

However, I just get the sensor icon. I need to click on it to expand it and find the values.

How do I render the properties of the sensor in the UI? For example, I want to create a card that shows me the info contained in the sensor.

image

Create template sensors from the attributes. Search the forum for battery levels will get you started.

Just wondering, is the sensor still working for you? If so, could you share your configuration.yaml with me? Mine right now is this:

  - platform: lastfm
    api_key: !secret lastfm_api_key
    users:
      - Nemesix_

Yet it doesn’t work.

That’s the same configuration I was using. I’ve since moved on to a different templated sensor to pull tracks from my music server rather than from Last FM, which has a good deal more lag to its updates.

Okay. Thanks for the info! :slight_smile:

What service do you use now?

Additionally, if possible, could you check if your old last.fm configuration would still work on your home assistant server? Only if it’s not too much of a hassle of course!

I checked, and by un-commenting the config I’d previously used with Last FM, and I got this in the logs:

Tue Jul 23 2019 09:44:18 GMT-0400 (Eastern Daylight Time)
lastfm: Error on device update!
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 261, in _async_add_entity
await entity.async_device_update(warning=False)
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 377, in async_device_update
await self.hass.async_add_executor_job(self.update)
File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/src/homeassistant/homeassistant/components/lastfm/sensor.py”, line 84, in update
last = self._user.get_recent_tracks(limit=2)[0]
File “/usr/local/lib/python3.7/site-packages/pylast/init.py”, line 2364, in get_recent_tracks
limit, self, self.ws_prefix + “.getRecentTracks”, cacheable, params
File “/usr/local/lib/python3.7/site-packages/pylast/init.py”, line 2785, in _collect_nodes
doc = sender._request(method_name, cacheable, params)
File “/usr/local/lib/python3.7/site-packages/pylast/init.py”, line 1132, in _request
return _Request(self.network, method_name, params).execute(cacheable)
File “/usr/local/lib/python3.7/site-packages/pylast/init.py”, line 965, in execute
response = self._download_response()
File “/usr/local/lib/python3.7/site-packages/pylast/init.py”, line 954, in _download_response
self._check_response_for_errors(response_text)
File “/usr/local/lib/python3.7/site-packages/pylast/init.py”, line 984, in _check_response_for_errors
raise WSError(self.network, status, details)
pylast.WSError: Login: User required to be logged in

I’m now using a templated sensor in combination with forked-daapd as a music server. I made a video to document how I implemented the music server in combination with home assistant. You can see it here. Any media player that’s connected with Home Assistant should work the same way.

The templated sensor configuration looks like this:

  - platform: template
    current_track:
      value_template: >
        {% if is_state('media_player.music_server','playing') %}
          {{ state_attr('media_player.music_server', 'media_artist') ~ ": " ~ state_attr('media_player.music_server', 'media_title') }}
        {% endif %}