Jellyfin Webhook v2

@oldbaldg would you be ok to using a HACS integration called Variables?

I have thrown something together (this is very rough), using Variables and a markdown card, but I can produce:

and it will dynamically update when items start and stop.

I have been using the data from webhooks playbackstart and playbackstop to create a list and then display it via a markdown card.

the issue is that if the server is restarted, or a webhook command is missed, the list can get out of sync and never comes back in to sync again.

There is a possibility of using a rest command to query the Jellyfin API, I have not had a good look in to this yet, but it will require adding extra lines to the home assistant configuration.yaml and still using Variables on HACs (due to character limitations of text helper in home assistant).

Could still use the webhook triggers of playbackstart and playbackstop to trigger the rest command for updating the list.

Would this interest anyone? A HACS integration that reads from the API.

The only issue I have found so far is that only 1 media item is registered per client. i.e. If I am watching a movie and play a song on the same client (browser with multiple tabs) it only registers the last item to start playing as running on the client.

has ssl support:

Can handle multiple servers (I have not had a chance to try this bit out)

Scanning interval is adjustable, can be set to 0 (disable) so you can refresh it manually with in automation when a webhook call come in. This stops it polling all the time.

I am just putting the finishing touches to it.

Have updated the blueprint to v2.4.20, this allows any playback started/progress/stopped event from a jellyfin webhook to trigger an action:

This will help with the integration when polling time is set to 0 (disabled) then it can be triggered by calling: jellyfin_status.refresh

This saves the amount of calls being made to the Jellyfin API for updates.

I think I am pretty close on finalizing the component.

@oldbaldg I think I have tested as much of this as I can on this.

It produces two additional sensors, total and error. Total is the total amount of servers being monitored and an error sensor (the number of servers unreachable). These sensors attach themselves on to any generated entities… if you have multiple servers that you are monitoring then it can land on any of them, not an issue as the sensors carry the same id. You will see one with 3 sensors.

When configuring a server you can set a polling frequency time, or set to 0 to disable polling.

if disabled then use the generic playback actions for playback started and playback stopped to setup automations to refresh the sensor. The pro about this is that polling the Jellyfin API is kept to a minimum, con server going offline may not be registered as being offline. Could be a happy medium and set the scan to be every 2 minutes and use the webhook to trigger a refresh?

If any one does want to use this and find any issues please feel free to open an issue on github or post it here.

I am not a Python programmer, more .NET/powershell. So expect issues that I may not have found :slight_smile:

1 Like

Sorry for the big bump on this but I’m struggling to get it going.

I’ve followed through the configuration, setup the webhook on JF, added the bluprint and automation on HA (not using the addon).

The client ID notification worked fine so added and configured that but the automation events weren’t firing. When I tried to manually run the TV Show/Movie payload to see what information I was getting, I get the following error:

[139658926522432] Error handling message: Error rendering data template: UndefinedError: 'payload' is undefined (home_assistant_error) User from <client IP> (Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0)

Other noted errors:

 websocket_api script: Error executing script. Error for call_service at pos 1: Error rendering data template: UndefinedError: 'payload' is undefined 
Template variable error: 'payload' is undefined when rendering '{{ payload.series_name }} - Season {{ payload.season_number_00 }}, Episode {{ payload.episode_number_00 }} ({{payload.item_name}}) user: {{ payload.user_name }} position: {{ media_playback_time }} ({{ media_percentage_played }}) remaining: {{ media_remaining_time }} ({{ media_percentage_left }}) total: {{ media_total_time }}'
Template variable error: 'payload' is undefined when rendering '{{ payload.item_name }} user: {{ payload.user_name }} position: {{ media_playback_time }} ({{ media_percentage_played }}) remaining: {{ media_remaining_time }} ({{ media_percentage_left }}) total: {{ media_total_time }}'

Edit: Also the helper toggle never gets updated.

Jellyfin logs don’t really have anything regarding this so not sure how to start debugging it. Any help would be appreciated.

Thanks!

Hi @cyruz143, not a problem. Happy to help if I can .

Did you place the wbhook template (home_assistant/blueprints/jellyfin_webhook_handler_v2/webhook_template.handlebars at 5254747cd61ecb724f59df6cf12d6944009be980 · thenextbutton/home_assistant · GitHub) in to the template section of the webhook config in Jellyfin and uncheck/check the notification types? also set the Key and Value in the Request Header?

If you happen to have a Home Assistant trace of one of the events that could be handy to have as well.

I will get back to you as soon as I can.

Hi, Sorry, got distracted by life and found this which is still quite WIP in progress but works for my needs (just handling lights per room based on which media player is doing stuff).