LyraTheLycan 4 Posted December 7, 2023 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!
LyraTheLycan 4 Posted December 9, 2023 Author 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
Solution LyraTheLycan 4 Posted December 10, 2023 Author Solution 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
LyraTheLycan 4 Posted December 10, 2023 Author 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 }}
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