Jump to content

Count of streams through API ?


Recommended Posts

Posted

Hi

I try to get a sensor in my Home-Assistant system (home-automation system) for my emby server. All integrations I have tried either don't report it or are buggy and instable.

I'm trying to get that data through the API using a POST or REST request from HA to Emby server. Unhappy I can't find any command in the API documentation that reports that stat from server.

Isn't there any direct way to get that data through the API ? or a JSON I could retrieve from Emby server.

Thanks

 

Vincèn

hthgihwaymonk
Posted

you'll want to do a GET of the /sessions endpoint and look at (count) playstate
SWAGGER will help you sort through what you need from playstate

  • Agree 1
  • Thanks 1
Posted
On 8/29/2024 at 6:03 PM, hthgihwaymonk said:

you'll want to do a GET of the /sessions endpoint and look at (count) playstate
SWAGGER will help you sort through what you need from playstate

Thanks for the indication and I found out how to get datas needed but it's out of my competence to do the count of playstate in Home-Assistant unhappy :(

  • 10 months later...
Posted

I managed to get the active emby sessions into Home Assistant
- Create a API key in your emby admin page.
- Put the yaml below in your configuration.yaml

sensor:  
  - platform: rest
    name: Emby Active Sessions
    unique_id: sensor.emby_active_sessions
    resource: "http://<embyserver>:<port>/emby/Sessions?ActiveWithinSeconds=60&api_key=<APIKEY>"
    value_template: "{{ value_json | length -1 }}"
    scan_interval: 30
  • Like 2
Posted
16 hours ago, LuxTux said:

I managed to get the active emby sessions into Home Assistant

Thanks a lot @LuxTux works perfect 👍

Posted

Actually i noticed that this is not reliable it keeps jumping between 1 and 0 every few calls. to fix this i've filtered the api session out of the result. i attempted this with the -1 in the vlaue template but this isnt working great.

You will need the name you gave to the api key in emby; be aware its case sensitive. in the example below my api key is called  "Home Assistant"

 

sensor:  
  - platform: rest
    name: Emby Active Sessions
    unique_id: sensor.emby_active_sessions
    resource: "http://<embyserver>:<port>/emby/Sessions?ActiveWithinSeconds=60&api_key=<APIKEY>"
    value_template: "{{ value_json | rejectattr('Client', 'equalto', 'Home Assistant')| list | length }}"
    scan_interval: 30

 

 

  • Thanks 1
Posted
23 hours ago, LuxTux said:
sensor:  
  - platform: rest
    name: Emby Active Sessions
    unique_id: sensor.emby_active_sessions
    resource: "http://<embyserver>:<port>/emby/Sessions?ActiveWithinSeconds=60&api_key=<APIKEY>"
    value_template: "{{ value_json | rejectattr('Client', 'equalto', 'Home Assistant')| list | length }}"
    scan_interval: 30

Thanks a lot for the update and I confirm it works a lot better ;) 👍

  • 3 weeks later...
Posted
On 7/12/2025 at 1:21 PM, vincen said:

Thanks a lot for the update and I confirm it works a lot better ;) 👍

Unhappy I have to correct my previous message, it works as bad as before :( I think it's still the same issue of ghost sessions in Emby server as it reports often more streams than really are or sometimes report some streams during hours while server is not streaming anything 😕

  • 3 weeks later...
Posted

Weird. any other processes that have api access maybe. e.g. the software that downloads your linux distos :) 

looking at the data returned, i noticed that only users that have an actual username and password have the an attribute username in the session info. so you could filter it maybe like this.
 

sensor:
  - platform: rest
    name: Emby Active Sessions
    unique_id: sensor.emby_active_sessions
    resource: "http://<embyserver>:<port>/emby/Sessions?ActiveWithinSeconds=<LastActivitySecondsAgo>api_key=<APIKEY>"
    value_template: "{{ value_json | selectattr('UserName', 'defined') | list | length }}"
    scan_interval: 30

 

We could also filter on just the sessions that are currently playing or have paused something. that could look like this:

sensor:
  - platform: rest
    name: Emby Active Sessions
    unique_id: sensor.emby_active_sessions
    resource: "http://<embyserver>:<port>/emby/Sessions?api_key=<APIKEY>"
    value_template: "{{ value_json | selectattr('NowPlayingItem', 'defined') | list | length }}"
    scan_interval: 30

 

  • Like 1
  • 2 weeks later...
Posted
On 8/19/2025 at 5:36 PM, LuxTux said:

We could also filter on just the sessions that are currently playing or have paused something. that could look like this:

@LuxTuxSorry for late answer and thanks for the suggestion, I'm going to try that one and see if it works better ;) 

  • 1 month later...
Posted

I use the Jellyfin integration (HACS) for my emby server in Home assistant.

That gives me a sensor showing active users that works great and insta updates.

And it also gives me all my media in home assistant under media tab! :) 
image.thumb.png.ceaa2d9e6efb9a30414f0218f9cbc27a.png

Will try the template sensor above now too :)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...