Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional Sensor Ideas/Info #2

Open
MattFryer opened this issue Nov 16, 2023 · 3 comments · May be fixed by #16
Open

Additional Sensor Ideas/Info #2

MattFryer opened this issue Nov 16, 2023 · 3 comments · May be fixed by #16
Assignees

Comments

@MattFryer
Copy link

Hi,
Firstly, great work!

I thought I'd share the details of some other AudioBookShelf sensors I've added to HA as rest sensors, in case you wanted to add them to this integration also. Some of which I have found really useful, especial being able to track when a new podcast episode is available and when the size of my podcasts is getting too big and I should think about pruning them.

Using the api path http(s)://[URL]/api/libraries/[LIBRARY_ID]/stats gets you stats on a library as detailed below.

The [LIBRARY_ID] is in the format "abcdef12-4567-890a-bcdef1234567". I originally found it by taking it from the URL when viewing the library in the AudioBookShelf UI so you could get users to add them as part of the config flow but ideally you can list them from the API using http(s)://[URL]/api/libraries which would obviously be better.

Audiobooks
Number of books - value_json.totalItems
Number of authors - value_json.totalAuthors
Total Duration (hours) - ( value_json.totalDuration / 60 / 60 ) | round(0)
Total Size (GB) - ( value_json.totalSize / 1024 / 1024 / 1024 ) | round(2)

Podcasts
Number of podcasts (not episodes) - value_json.totalItems
Number of podcast episodes - value_json.numAudioTracks
Total Duration (hours) - ( value_json.totalDuration / 60 / 60 ) | round(0)
Total Size (GB) - ( value_json.totalSize / 1024 / 1024 / 1024 ) | round(2)

Hope that's useful!
Matt

@wolffshots
Copy link
Owner

Amazing thanks! When I have some time I’ll sit down and take a proper look at this but I’d be keen to add these

@jdubz666
Copy link

jdubz666 commented Dec 19, 2023

I'm excited to start using ABS and this home assistant integration looks great. I haven't read too far into the API documents so I'm not sure what's possible and what's not.

I think it would be really cool if you could call a Service to "Continue playing last audio book on XYZ media player".

On top of that I'm looking forward to using this kind of stuff with Voice commands in home assistant.

@wolffshots wolffshots self-assigned this Jan 9, 2024
@wolffshots wolffshots linked a pull request May 23, 2024 that will close this issue
@wolffshots
Copy link
Owner

Okay folks, I did not know what I was doing so I have basically rewritten the integration from scratch to do it a bit better. I have push v0.1.1-pre which is a pre-release version to add some library sensing stuff.

To actually add dynamically created and removed library sensors was proving too difficult for my small non-pythonic brain so I have opted to add the details in an attribute on the Library sensor instead. I'm still going to clean it up and improve the attributes but this is what it looks like on that release:

image

The re-implementation does not support adding the integration from the UI (I hope to get to that) so for now it is from configuration.yaml as follows:

audiobookshelf:
  api_url: 'http(s)://<your ip>:<your port>'
  api_key: <your key>
  scan_interval: <optional refresh speed in seconds defaulting to 300 if not set>

Y'all are welcome to give it a go and let me know if there are any major problems but no stress if not. I'll post here again when I have something more complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants