I would love monitor and track what user(s) are [actively] listening to books and what they are listening to.
I keep getting this response from API “No one is listening right now.” from my above Home-Assistant template and sensor. Any ideas?
Confirmed API in ABS and tested that it returns data:
localhost:~$ curl -H "Authorization: Bearer <removed_api>" https://absURL/API/sessions
My secrets.yaml :
# Audiobookshelf
audiobookshelf_sessions_url: https://absURL/api/sessions
audiobookshelf_token: <removedAPItoken>
Updated my home-assistant rest configuration:
rest:
- resource: !secret audiobookshelf_sessions_url
method: GET
headers:
Authorization: "Bearer !secret audiobookshelf_token"
Accept: application/json
scan_interval: 30
sensor:
- name: "Audiobookshelf Sessions Raw"
value_template: >
{{ value_json.sessions | length }}
json_attributes:
- sessions
- total
- page
- itemsPerPage
Updated my home-assistant sensor template:
template:
- sensor:
- name: "Audiobookshelf Active Listeners"
icon: mdi:headphones
state: >
{% set s = state_attr('sensor.audiobookshelf_sessions_raw', 'sessions') | default([]) %}
{{ s | map(attribute='user.username') | unique | list | length }}
attributes:
users: >
{% set s = state_attr('sensor.audiobookshelf_sessions_raw', 'sessions') | default([]) %}
{{ s | map(attribute='user.username') | unique | list }}
titles: >
{% set s = state_attr('sensor.audiobookshelf_sessions_raw', 'sessions') | default([]) %}
{{ s | map(attribute='mediaMetadata.title') | unique | list }}
Still not working…
I see this error in the ABS logs:
2025-12-21 10:44:09.805
ERROR
Cannot validate socket - invalid token
I am so close…cCan someone help me figure this out?
My Github ABS discussion post: Home Assistant / API for User Activity · advplyr/audiobookshelf · Discussion #4912 · GitHub