Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 102840

Jellyfin REST API sensor

$
0
0

Hi there!
I have installed the Jellyfin integration and am having trouble detecting playback.

The integration itself keeps producing many media_player entities (that’s a different issue), so I decided to try an poll the REST API directly.
The /Sessions endpoint returns a JSON list of objects, one for each session. As I understand it, if that object has the NowPlayingItem key it means playback is active.
See Jellyfin API reference here (and yes, the “X-Emby-Authorization” header is incorrect in the docs, it’s supposed to be “X-MediaBrowser-Token”)

I’m trying to detect that key. Where is wrong with my code?

binary_sensor:
- platform: rest
  name: Jellyfin playing
  device_class: running
  resource_template: "{{ states('input_text.jellyfin_url') }}/Sessions"
  headers:
    X-MediaBrowser-Token: !secret jellyfin_apikey
  value_template: >
    {% set bool = 'false' %}
    {% for item in value_json %}
      {% set bool = 'true' if item.NowPlayingItem is defined %}
    {% endfor %}
    {{ bool }}

I also tried a different condition: if 'NowPlayingItem' in item with no luck.

Just for debugging purposes, I created a REST sensor with the value:

value_template: "{{ value_json[0].NowPlayingItem.Name }}"

…and when there’s playback, I get the media name just fine.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 102840

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>