LyraTheLycan 3 Posted December 7, 2023 Share Posted December 7, 2023 Hi, I'm using a script to get details and would like to alter it, but I don't know Python. This works to filter by type: if self.data[0]["Type"] == "Movie": return But I would like to add a filter that checks the contents of the Genres array. This is what I want but it doesn't work: if self.data[0]["Type"] == "Movie" and "Animation" in self.data[0]["Genres"][0:]: return Many thanks for assistance! Link to comment Share on other sites More sharing options...
Luke 37094 Posted December 8, 2023 Share Posted December 8, 2023 Hi, what exactly doesn't work? Link to comment Share on other sites More sharing options...
LyraTheLycan 3 Posted December 9, 2023 Author Share Posted December 9, 2023 (edited) I am trying to find how many movies in the Movies library have the Animation tag, and get that as an integer for a Home Assistant sensor.. Chances are there's a much easier way to achieve this instead of trying to manipulate a RESTful API! Specifically I am starting with the URL pointing to all items in the library, and wanting to get multiple values from it, so adding a Genres filter in the URL will not be possible. Thanks! Edited December 9, 2023 by LyraTheLycan Link to comment Share on other sites More sharing options...
Luke 37094 Posted December 9, 2023 Share Posted December 9, 2023 What are your query urls? Link to comment Share on other sites More sharing options...
Solution LyraTheLycan 3 Posted December 10, 2023 Author Solution Share Posted December 10, 2023 I've figured it out, changed my approach and used Jinja. Converted the json to string then counted the genre word, and divided by two because Genres and GenreTypes is in the list. It works for now at least! rest: - resource: http://{ip}:{port}/Items?recursive=true&ParentId={libraryid}&Fields=Genres&api_key={api} method: GET scan_interval: 3600 sensor: - name: "{name}" value_template: '{{ (value_json | string).count("{Genre}") / 2 | int }}' 1 Link to comment Share on other sites More sharing options...
LyraTheLycan 3 Posted December 10, 2023 Author Share Posted December 10, 2023 22 minutes ago, LyraTheLycan said: value_template: '{{ (value_json | string).count("{Genre}") / 2 | int }}' value_template: '{{ ((value_json | string).count("{Genre}") / 2) | int }} Link to comment Share on other sites More sharing options...
Luke 37094 Posted December 10, 2023 Share Posted December 10, 2023 Thanks for following up. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now