Hello, I have been trying to build a RESTfull sensor for the Jellyfin API.
However, I have some trouble consuming it.
There are multiple states I am interested in knowing about in HA, so I’d like sensors to know when;
- nothing is playing
- a single user plays an item (user name and file name)
- multiple users play items (user name and file name)
The response of the Jellyfin API call
- when nothing is playing response is empty array:
[]
- when one user is playing a file, response i:
[
{
"PlayState": {
"PositionTicks": 1194405010,
"CanSeek": true,
"IsPaused": false,
"IsMuted": false,
"VolumeLevel": 70,
"AudioStreamIndex": 1,
"SubtitleStreamIndex": -1,
"MediaSourceId": "72e99dc9b04b41d6ce6b5343be961a3c",
"PlayMethod": "DirectPlay",
"RepeatMode": "RepeatNone"
},
"AdditionalUsers": [],
"Capabilities": {
"PlayableMediaTypes": [
"Audio",
"Video"
],
"SupportedCommands": [
"MoveUp",
"MoveDown",
"MoveLeft",
"MoveRight",
"PageUp",
"PageDown",
"PreviousLetter",
"NextLetter",
"ToggleOsd",
"ToggleContextMenu",
"Select",
"Back",
"SendKey",
"SendString",
"GoHome",
"GoToSettings",
"VolumeUp",
"VolumeDown",
"Mute",
"Unmute",
"ToggleMute",
"SetVolume",
"SetAudioStreamIndex",
"SetSubtitleStreamIndex",
"DisplayContent",
"GoToSearch",
"DisplayMessage",
"SetRepeatMode",
"SetShuffleQueue",
"ChannelUp",
"ChannelDown",
"PlayMediaSource",
"PlayTrailers"
],
"SupportsMediaControl": true,
"SupportsContentUploading": false,
"SupportsPersistentIdentifier": false,
"SupportsSync": false
},
"RemoteEndPoint": "192.168.1.22",
"PlayableMediaTypes": [
"Audio",
"Video"
],
"Id": "ca2b2e75e8663e03f44e013db9dde2c6",
"UserId": "1bbb895fdd65414faa68f54947e25e70",
**"UserName": "sam",**
**"Client": "Jellyfin Web",**
"LastActivityDate": "2023-01-03T18:18:27.2549077Z",
"LastPlaybackCheckIn": "2023-01-03T18:18:27.2549078Z",
"DeviceName": "Edge Chromium",
**"NowPlayingItem": {**
**"Name": "Keeping the Peace",**
"ServerId": "43ce93b98b93409dbe3e455b51bcd69f",
"Id": "72e99dc9b04b41d6ce6b5343be961a3c",
"DateCreated": "2022-08-30T01:25:08.6139961Z",
"Container": "mkv,webm",
"PremiereDate": "2016-11-11T00:00:00.0000000Z",
"ExternalUrls": [],
"Path": "/tv_shows/Shaun the Sheep/Season 5/Shaun.The.Sheep.S05E15.Keeping.The.Peace.720p.HDTV.x264-DEADPOOL[rarbg].mkv",
"EnableMediaSourceDisplay": true,
"ChannelId": null,
"Overview": "After spending the night putting together the bed instead of sleeping in it, the farmer has a lie in and Bitzer is in charge of making sure his master's rest is uninterrupted.",
"Taglines": [],
"Genres": [],
"RunTimeTicks": 4196900096,
"ProductionYear": 2016,
"IndexNumber": 15,
"ParentIndexNumber": 5,
"ProviderIds": {
"Tvdb": "5544594",
"sonarr": "2232"
},
"IsHD": true,
"IsFolder": false,
"ParentId": "47cbd030cd7c72344fa14be1df0a5663",
"Type": "Episode",
"Studios": [],
"GenreItems": [],
"ParentLogoItemId": "bc5b9f22c4d25fc70fb4b34a7782870e",
"ParentBackdropItemId": "bc5b9f22c4d25fc70fb4b34a7782870e",
"ParentBackdropImageTags": [
"9395732216bb93e70f3bdb09bdd07ca8"
],
"LocalTrailerCount": 0,
"SeriesName": "Shaun the Sheep",
"SeriesId": "bc5b9f22c4d25fc70fb4b34a7782870e",
"SeasonId": "47cbd030cd7c72344fa14be1df0a5663",
"SpecialFeatureCount": 0,
"PrimaryImageAspectRatio": 1.7777777777777777,
"SeriesPrimaryImageTag": "abe249fa5ce31052ae1b84c3a02b11cd",
"SeasonName": "Season 5",
"MediaStreams": [
{
"": ""
},
{
"Codec": "aac",
"TimeBase": "1/1000",
"DisplayTitle": "AAC - Stereo - Default",
"IsInterlaced": false,
"ChannelLayout": "stereo",
"BitRate": 192000,
"Channels": 2,
"SampleRate": 48000,
"IsDefault": true,
"IsForced": false,
"Profile": "LC",
"Type": "Audio",
"Index": 1,
"IsExternal": false,
"IsTextSubtitleStream": false,
"SupportsExternalStream": false,
"Level": 0
}
],
"VideoType": "VideoFile",
"ImageTags": {
"Primary": "8892ba0ef1daccdeb8c50f3e03c58860"
},
"BackdropImageTags": [],
"ParentLogoImageTag": "887f9a90b769cbbf45426ee5e55601bd",
"ImageBlurHashes": {
"Primary": {
"8892ba0ef1daccdeb8c50f3e03c58860": "[email protected]|sQn~fStTtmofoHWBbb",
"abe249fa5ce31052ae1b84c3a02b11cd": "dXH:jG.k%|%2x[nlRkxuu2VsXOtQ-:t7tQoy%MoNRRof"
},
"Logo": {
"887f9a90b769cbbf45426ee5e55601bd": "HCFPB0ay?a-:M|t7-:xu9Z~p-:oe-;xaoe%LofRj"
},
"Backdrop": {
"9395732216bb93e70f3bdb09bdd07ca8": "WRFr@KtOkW%KNFxutpIVM{WUWURkKUadsDWZjcxaKSj]oyoyWCa|"
}
},
"SeriesStudio": "Netflix",
"Chapters": [
{
"StartPositionTicks": 0,
"Name": "Chapter 1",
"ImageDateModified": "0001-01-01T00:00:00.0000000Z"
}
],
"LocationType": "FileSystem",
"MediaType": "Video",
"Width": 1280,
"Height": 720
},
"FullNowPlayingItem": {
"Size": 75739504,
"Container": "mkv,webm",
"IsHD": true,
"IsShortcut": false,
"Width": 1280,
"Height": 720,
"ExtraIds": [],
"DateLastSaved": "2022-10-20T21:32:39.039725Z",
"RemoteTrailers": [],
"SupportsExternalTransfer": false
},
"DeviceId": "7d8587e1-2d7d-4c2e-ba7b-4bfed6732e2d",
"ApplicationVersion": "10.8.8",
"IsActive": true,
"SupportsMediaControl": true,
"SupportsRemoteControl": true,
"NowPlayingQueue": [
{
"Id": "72e99dc9b04b41d6ce6b5343be961a3c",
"PlaylistItemId": "playlistItem0"
},
{
"Id": "30c9f5900be30a356dfd0e9c27256695",
"PlaylistItemId": "playlistItem1"
}
],
"NowPlayingQueueFullItems": [
{
"removed_for_brevity" : true
}
],
"HasCustomDeviceName": false,
"PlaylistItemId": "playlistItem0",
"ServerId": "43ce93b98b93409dbe3e455b51bcd69f",
"SupportedCommands": [
"MoveUp",
"MoveDown",
"MoveLeft",
"MoveRight",
"PageUp",
"PageDown",
"PreviousLetter",
"NextLetter",
"ToggleOsd",
"ToggleContextMenu",
"Select",
"Back",
"SendKey",
"SendString",
"GoHome",
"GoToSettings",
"VolumeUp",
"VolumeDown",
"Mute",
"Unmute",
"ToggleMute",
"SetVolume",
"SetAudioStreamIndex",
"SetSubtitleStreamIndex",
"DisplayContent",
"GoToSearch",
"DisplayMessage",
"SetRepeatMode",
"SetShuffleQueue",
"ChannelUp",
"ChannelDown",
"PlayMediaSource",
"PlayTrailers"
]
}
]
I have tried the following syntax:
- platform: rest
name: DEBUG_1
method: GET
resource: https://192.168.1.41:8920/Sessions
json_attributes_path: $..*
json_attributes:
- name
- NowPlayingItem
verify_ssl: false
headers:
Authentication: !secret jellyfin_api_token
- platform: rest
name: DEBUG_2
method: GET
resource: https://192.168.1.41:8920/Sessions
# json_attributes_path: $..NowPlayingItem.*
verify_ssl: false
value_template: "{{ value_json.NowPlayingItem.Name }}"
headers:
Accept: application/json
Authentication: !secret jellyfin_api_token
- platform: rest
name: DEBUG_3
method: GET
resource: https://192.168.1.41:8920/Sessions
json_attributes:
- NowPlayingItem
verify_ssl: false
headers:
Authentication: !secret jellyfin_api_token
But I am not sure how to continue; I am not sure what sensor is actually want.
How would I build this ? Ideas / tips welcome.
note: i use hardcoded IP as resource, because a DNS resolve issue