[New Binding] EMBY Server Binding - Alpha

So i have created an EMBY binding. Right now it is in very early alpha stage and more proof of concept. However, posting here so others can test and contribute as i develop this further.

I am not creating a formal pull request right now as the binding is no where near ready yet. However, i am hosting it on github at

In github you can find a build under the target folder which you can download and add to the addons folder manually. Please feel free to fork, add and create pull requests to my repo and contribute if you desire.

I have modeled the binding heaveily after the kodi binding (so any refrecences to kodi in the code are from that and really should be changed to emby names) as the emby API is able to send json in a similar manner (albeit with different tags and responses). In its current form the binding does not have the ability to control devices and only receives and process updates. However, the framework for control is there i just need to add those hooks in.

Currently configuration is all manual. EMby does broadcast over upnp so a disvoery service could be added in the future for autodiscovery of the emby server. Once the binding is added you need to add a thing and provide it with the following configurations:

api key: created in your emby server dashboard ( Dashboard -> Expert -> Advanced -> Security)
DeviceID: This is the unique ID generated by emby for each device. You enter the ID here for the device you want to monitor for now playing events. THis can either be obtained from the emby server logs or from the openhab logs once the other settings of the thing are configured and the websocket connects for the first time. For both methods you need to start playing a media file and then look for the tag deviceID.
ipaddress: this is the address of your ebmy server
port: the local port (currently the binding does not use ssl)
refresh parameter: this is the time in milliseconds that the emby server will send json updates regarding the now playing sessions. the reccomended is 10000 as this corresponds to the time the emby devices are also required to report status updates. THe server will also send updates between this refresh time when any device has a change in state so updating on 10 second intervals will keep openHAB in line with emby.

Once this is configured the binding will connect to the emby server websocket and reqeust sessions data at the refresh rate specified.

The binding will then analyze the received json and map fields under the configured deviceID for the following channels:

Control: Indicates the playing state - either playing or paused
Stop: This switch gets momentarilly trigger on then off when the media on the device stops
mute: switch on when device is muted off if not muted
showtitle: the title of the currently playing item
imageURL: this will generate a string (with percent played indicator included) to the path of the primary coverart image for the currently now playing item. There are tons of options here that could be grabbed and currently i am only grabbing the primary (for movies) and the season primary(for TV) however i have plans to add config options to this channel to allow the binding to form the primary, box, fanart, etc and make this an extensible channel so that the user could add as many as they wanted.

My current use case for this and the reason i made this binding was so that the habPanel screen which is in our den could have a template that displays the coverart of the currently playing item with percent played while the media was playing and then dissappear when not playing.

And since there was not a binding for EMBY i decided to start one myself. There is still a long way to go here to make this a full binding with control but this is a proof of concept and happy to have others test and help along the way.

5 Likes

Watching :slight_smile:

Ok so just pushed an update to github.

The structure of the binding has now been reworked with a bridge handler and child thing devices on the handler for each device you want to monitor. So if you have been using the other binding you will need to delete all the things and recreate.

The binding will discover all emby servers on the network (have to trigger a scan, no background discovery). Will need to supply the API key (obtained from the server) and the desired refresh interval. Once you have added a bridge thing for the emby server. The binding will connect to the server websocket and then will populate devices in the inbox as possible things. A device needs to start playing media before it will appear, so if the device you want to monitor doesn’t initially appear in the inbox (and the bridge is online) then start playing a file on it. There is no configuration necessary for the thing unless you want to change the imagetype the url generates.

On the imageURL i have added the option to select from any of the available options (primary, box …etc.). If none is selected the default is primary This channel is also extensible so the thing defaults with one imageurl channel but you can add as many as you want if you want to generate url strings for the other image types. As i mentioned before the handling for TV vs movies is still hard coded in (tv grabs season image instead of the episode image for primary) however i have more work to do on adding other configuration options here and open to suggestions on how people would like this handled.

1 Like

Hi volfan,
i would give some feedback. I was happy when I saw the binding to Emby and my first thought was, could be good to use for light control. Great, let’s try it out. First experience. Log entrys look well if i playing movie or serie in a browser. It does the job how it should.
Than I tried the binding with Emby Android TV and came the black soup. I don’t know why, whenever I playing back content, any of the items switching their status back and fort.

Here is the log entry:


2018-11-03 19:25:38.443 [vent.ItemStateChangedEvent] - Q5_Pro_ShowTitle changed from UNDEF to Pirates of the Caribbean: Dead Mans Chest
2018-11-03 19:25:38.449 [vent.ItemStateChangedEvent] - Q5_Pro_Stop changed from OFF to ON
2018-11-03 19:25:38.450 [vent.ItemStateChangedEvent] - Q5_Pro_ShowTitle changed from Pirates of the Caribbean: Dead Mans Chest to UNDEF
2018-11-03 19:25:38.451 [vent.ItemStateChangedEvent] - Q5_Pro_Stop changed from ON to OFF
2018-11-03 19:25:48.908 [vent.ItemStateChangedEvent] - Q5_Pro_ShowTitle changed from UNDEF to Pirates of the Caribbean: Dead Mans Chest
2018-11-03 19:25:48.958 [vent.ItemStateChangedEvent] - Q5_Pro_ShowTitle changed from Pirates of the Caribbean: Dead Mans Chest to UNDEF
2018-11-03 19:25:48.959 [vent.ItemStateChangedEvent] - Q5_Pro_Stop changed from OFF to ON
2018-11-03 19:25:48.959 [vent.ItemStateChangedEvent] - Q5_Pro_Stop changed from ON to OFF
2018-11-03 19:25:59.032 [vent.ItemStateChangedEvent] - Q5_Pro_ShowTitle changed from UNDEF to Pirates of the Caribbean: Dead Mans Chest
2018-11-03 19:25:59.048 [vent.ItemStateChangedEvent] - Q5_Pro_Stop changed from OFF to ON
2018-11-03 19:25:59.049 [vent.ItemStateChangedEvent] - Q5_Pro_ShowTitle changed from Pirates of the Caribbean: Dead Mans Chest to UNDEF
2018-11-03 19:25:59.050 [vent.ItemStateChangedEvent] - Q5_Pro_Stop changed from ON to OFF
2018-11-03 19:26:08.465 [vent.ItemStateChangedEvent] - Q5_Pro_ShowTitle changed from UNDEF to Pirates of the Caribbean: Dead Mans Chest
2018-11-03 19:26:08.466 [vent.ItemStateChangedEvent] - Q5_Pro_Stop changed from OFF to ON
2018-11-03 19:26:08.466 [vent.ItemStateChangedEvent] - Q5_Pro_ShowTitle changed from Pirates of the Caribbean: Dead Mans Chest to UNDEF
2018-11-03 19:26:08.467 [vent.ItemStateChangedEvent] - Q5_Pro_Stop changed from ON to OFF
2018-11-03 19:26:19.077 [vent.ItemStateChangedEvent] - Q5_Pro_ShowTitle changed from UNDEF to Pirates of the Caribbean: Dead Mans Chest
2018-11-03 19:26:19.079 [vent.ItemStateChangedEvent] - Q5_Pro_Stop changed from OFF to ON
2018-11-03 19:26:19.081 [vent.ItemStateChangedEvent] - Q5_Pro_ShowTitle changed from Pirates of the Caribbean: Dead Mans Chest to UNDEF

The only change what I made is I’ve raised the refresh parameter at 30000 first, later abit higher. Didn’t help.

Have any idea whats happening here?

I don’t have an android TV player so this is a new player for me. The refresh parameter should only effect the time that the sever sends messages to openhab.

Can you up your log level to debug and paste the whole log into dropbox or paste bin for me so that i can see the json output that your server is sending out when the android TV is playing. Perhaps there is something wonky going on that i need to deal with.

That is the event log what i really need to see is the openhab.log file to see what is going on.

Thanks for testing!

You’re welcome. Over the weekend i can deal with and do some log records.
I think, you can test Emby for Android TV out on any android mobile (or no?), if you have one.
And it just be beautiful, I will provide 2 different log file. Because, have 2 options with app.
When it streams through in app directly and when it passes the path of the source to an external player. In each case, the server shows different behavior.

Ok I do have an android tablet so I will download Emby onto that and test it out but still post the logs when you get a chance.

Hey! I did it.

You find here the debug files:
https://1drv.ms/f/s!AhhiEcdnNMaOgZcXI2Rb-LBQsU1VWQ

THX

@Krisztian Thanks for this finally able to look through these. As an initial question what did you have your refresh parameter set at?

As you mentioned in first post, I set to 10000 ms. I tried to increase the refresh time, but didn’t help. Did you try out the app on your table?

I wasn’t able to get Android tv to run on the tablet. It’s an older version. So I thank you for the logs. They are inmensely helpful.

The reason I was asking about the refresh rate is because it looks like from my pursing the logs that the server was sending updates app way faster than once every 10 seconds based on your logs. It looked liked openHAB was receceving a packet once every second or faster. I need to look deeper into the logs. I’ll get to that soon. I’ve been working on development for another binding that just was completed so now can focus back on Emby again.

@Krisztian i have pushed an update that i would like you to try. let me know if it fixes the issue on your system.

Thanks!

About to start really working on this binding to flesh it out from the alpha state that it is currently in.

Hello Zachary!

The latest version doesn’t work for me. After few second the server goes offline.
In the log file stands:
“Unhandled Error (closing connection), ID segment contains invalid characters.”

I don’t know what happening. I have changed settings on Emby also. May I ask you to share with me somehow the previous version. I just give a try to it. Unfortunatly, I deleted it.

can you post the full log for me. Thanks. The old version would be in the commit history on github. But I would like to see the logs to see what was causing the error to see if it is something i need to fix.

Hi there!

Here is the link to log file:
https://1drv.ms/u/s!AhhiEcdnNMaOgZcubH99HHPO2SUT8g

It’s only one file from the begining of start process. And one more question:

When the addon have been installed on the system, I always see 2 things appearing in the Inbox. The one belongs to server and its name “Emby Server”, That’s OK. And just in time, the second comes with the name “Emby Binding Device”. Meanwhile I didn’t triggered any content playback on my other devices to identify them. If I remember fine, that didn’t come up with the previous version.

What do you think? Should it work like that way?

Do you already have a server thing added?

Once you add an emby binding server the thing will start adding emby binding devices to the inbox that represent the players. Just to confirm in the karaf console do an uninstall of the emby bundle and completely remove all things. I want to make sure that you are starting from a clean slate.

Sometimes with manual installs of bindings the previous bundle doesn’t get uninstalled cleanly when you drop the new jar in over the old one.

So follow these steps.

  1. remove all emby things
  2. uninstall all emby bundles from the karaf console
  3. shutdown openhab
  4. move the emby jar out of the addons folder temporailly
  5. restart openhab
  6. check karaf bundle list to make sure there aren’t any floating emby bundles left and remove them
  7. shutdown openhab
  8. move emby jar back in
    9 restart openhab

Thanks

I have a good news and a bad news!
The good news is was your guidance great to clean up OH. Now the server is online in any circumstance.

The bad news: I still get the bouncing state of items from Emby ATV app. Have a look into the DEBUG files. Been logged from fresh install.

Oh, one more thing, Item “Title” doesn’t give any info to file events.log. Not like item “Show Title”, which works as it should.

Weren’t you thinking about that to create a topic on Emby community site? You can reach peoples there too and ask them to help testing your binding.

@Krisztian i have pushed a new version with some more logging entries. Can you install that version so i can try and track down what is going on.

Thanks

Hi!
new DEBUG files
it’s done. I’ve added the Emby serves’ log, too. Maybe help to figure out the problem.

Hey @Krisztian so not sure what is going on and i may have to reach out to the android app developer to see how the deviceId is generated on Embys side. But first question for you since in looking through your logs there are two instances of the deviceID dcd12b402627809d (this is supposed to be the unique deviceId generated by emby for each device) one of them is the one that is playing your media and the other one has stale info. Thats why it keeps fluctuating.

Have you had this installed on multiple android clients before? I can perform some error checking to ignore other device id’s and compare if i need to to but want to rule out if this is an edge case or something that is going to be a recurring problem.