Plugin: Emby Interface

Emby Interface is a control and response interface for the Emby media server. It allows you to control Emby sessions (clients playing media), and respond to basic session events.

This plugin was developed at the request of PrincessCleavage and cw-kid, so if you’re an Emby user, be sure to thank them for stepping up to get it launched! I’d also like to thank Luke, the lead Emby developer/architect, for his support.

This project lives in a Github repository, here: GitHub - toggledbits/Emby: Emby Interface for Vera Home Automation Controllers

Documentation is in the README file in the above Github repository. As is typical for my work, the “master” branch represents the latest full release; the “stable” branch contains updates from development that have had minimal testing and are deemed “stable”; and the “develop” branch is the latest code with work in progress checkpoints (the bleeding edge). The CHANGELOG file in each branch will tell you what has evolved.

Please submit questions or bug reports here in this thread. Bug reports can instead be submitted to the issues section of the Github repo if you like that approach.


VERSION HISTORY

2019-06-08: Version 1.2. Adds the ability to bookmark media (mark current position) and later resume from a named bookmark.

2019-03-17: Version 1.1. Code cleanups.and optimizations.

2019-01-06: Version 1.0. General public release.

Version 1.0 has been submitted to the Vera Plugin Marketplace for approval (expected publicly available tomorrow morning). It is available immediately in the AltAppStore.

You can also download and install the release package manually: Release Version 1.0 · toggledbits/Emby · GitHub

Looking forward to this.
As I understand, there is no easy way to integrate Plex with Vera but Emby does this pretty easy?
And with your add on, you can do more or is it easier?

It’s available now. I would not say it was easy, but that’s mostly because the documentation is out of date and has lots of errors–code was a no-brainer, once you figured out how something worked, but figuring it out when the docs say one thing and the API wants another had some frustrating moments. I got further using swagger to pound the API than I did when I was relying on the docs. The product itself is quite robust, though, and the chief architect/developer is responsive to questions and suggestions. Clients are a bit quirky, because many are developed by third parties and so bring their own ideas (and bugs) into the mix, but that’s not different from Plex.

I have to say, I really like it. I’ve been using it every day for about a month, and it has really grown on me. I’ve been a Plex user for years, but recently the Plex UI changed dramatically on Roku and frankly, I hate it, and if that’s the direction others will be going, I will jump ship. I prefer the previous UI, and Emby’s UI is similar with its own spin, and I find it very agreeable. So Emby is getting a lot of use in my house quite suddenly.

[quote=“rigpapa, post:4, topic:200354”]It’s available now. I would not say it was easy, but that’s mostly because the documentation is out of date and has lots of errors–code was a no-brainer, once you figured out how something worked, but figuring it out when the docs say one thing and the API wants another had some frustrating moments. I got further using swagger to pound the API than I did when I was relying on the docs. The product itself is quite robust, though, and the chief architect/developer is responsive to questions and suggestions. Clients are a bit quirky, because many are developed by third parties and so bring their own ideas (and bugs) into the mix, but that’s not different from Plex.

I have to say, I really like it. I’ve been using it every day for about a month, and it has really grown on me. I’ve been a Plex user for years, but recently the Plex UI changed dramatically on Roku and frankly, I hate it, and if that’s the direction others will be going, I will jump ship. I prefer the previous UI, and Emby’s UI is similar with its own spin, and I find it very agreeable. So Emby is getting a lot of use in my house quite suddenly.[/quote]

I agree the Roku UI was shocking when I first saw it. After a while you figure out how to edit the icons at the top and it is easier to jump around than it was before.

I really like how Vera will send you messages when playback initiates on a device.
It helps me monitor my kids!!

Could another item like the “urn:schemas-toggledbits-com:device:EmbyUsers:1” device type be made for users?

Notifications to my phone and Android app are cool when someone logs into the emby server.

Especially if it was repeated login attempts.

The lua is polling server for information, the xml for serverInfo and sessionInfos. There is no persistent WebSocket connection, I don’t think?

serverRequest to “/users” will list all the current logged in userNames.

The perfect scene:
If Julia’s Geofence is “HOME”, and Julia is signed into Emby Device, started playback and time is past 10:00pm, make sure the Door is locked, and alarms are armed."

“Sessions/{Id}/Message/” is a good favorite. it can send messages to the devices the plugin has found earlier.
Might be cool for doorbell events.

If Julia’s started playback of mediaItem, and past 10:00pm, and door is unlocked then send message to emby device “Door is unlocked”.

That would be Smart Living!

Mobile has no playback interface.

I think each emby device needs to be marked as category 3 and sub_catagory 0

[quote=“chef, post:7, topic:200354”]Mobile has no playback interface.

I think each emby device needs to be marked as category 3 and sub_catagory 0[/quote]

You can try setting them and see what happens. The mobile apps have a long history of no UI for plugins.

[quote=“chef, post:7, topic:200354”]Mobile has no playback interface.

I think each emby device needs to be marked as category 3 and sub_catagory 0[/quote]

…adding to my previous reply… category 3 is a switch, which I don’t think would be the best choice. Category 15 is A/V, and that is configured in the device file. http://wiki.micasaverde.com/index.php/Luup_Device_Categories

[quote=“rigpapa, post:9, topic:200354”][quote=“chef, post:7, topic:200354”]Mobile has no playback interface.

I think each emby device needs to be marked as category 3 and sub_catagory 0[/quote]

…adding to my previous reply… category 3 is a switch, which I don’t think would be the best choice. Category 15 is A/V, and that is configured in the device file. http://wiki.micasaverde.com/index.php/Luup_Device_Categories[/quote]

Yes category 15 of coarse… Wonderful.

This plugin is put together very well. It is a great read. Thank you. I’ll definitely put some money in the coffers for this :slight_smile:

I notice that you used require"socket" for http requests, but wasn’t sure if the lua require"websocket" would allow for server events to pass through to vera?

emby does have a url which for websockets specifically: ws://{host}?api_key={authenticationtoken}&deviceId={deviceId}

I’m really new to lua? {cringe} … it’s kinda like node… a little bit I guess …


local websocket = require’websocket’
local client = websocket.client.sync({timeout=60})

– connect to the server:
local fullurl = luup.variable_get( SERVERSID, “LocalAddress”, dev ) or “http://localhost:8096
local key = luup.variable_get( SERVERSID, “APIKey”, dev )

local ok,err = client:connect(“ws://” … fullurl … “?api_key=” … urlencode(key) … “&deviceId=” … {STILL NEED DEVICE ID}",‘echo’)
if not ok then
print(‘could not connect’,err)
end


I wondering what kind of magical things vera could do when parsing event info from emby.
I keep thinking of interesting utilization. With in reason, we don’t want lights to change state each time there is an authentication error, but I’m just loving the playback notifications from vera, they are extremely useful.

I notice that Alexa is unable to register emby devices through vera. I don’t think that matters.

I personally use OWIN Self hosted server to create endpoints that Alexa can hit, for most directives my custom Emby plugins or Vera endpoints can’t handle.
These OWIN instances keep code in the realm of C#, which means coding is lighting fast for me :wink:

Cool you did add message capabilities:

function actionSessionMessage( );

Fantastic! Will we be able to use it in vera scenes?

Perhaps if the Server was available as a device in scene creation, with the ability to use the message action, by selecting an emby device to message.

Then vera could check conditions of zwave products and message appropriately.

Sorry for so many posts, the lua is a great read sir.
The MVP is luke. Swagger didn’t work for a long time when they added authentication. But, yeah…

Also, if you wanted specific endpoints in the emby server for something, I can whip them up for you.

That is, if there is something you’d want the emby server to handle and return to vera.

[quote=“chef, post:11, topic:200354”]Cool you did add message capabilities:

function actionSessionMessage( );

Fantastic! Will we be able to use it in vera scenes?

Perhaps if the Server was available as a device in scene creation, with the ability to use the message action, by selecting an emby device to message.[/quote]
Alas, if it is to be done in the scene editor, it has to be done using the limited UI capabilities of Vera’s “static JSON” page/action/control description. Anything dynamic, like presenting a list of Emby servers, won’t be happening, at least not in UI7. We can hope for better days ahead, perhaps. If I did it in JavaScript, you’d have it on the control panel, but it wouldn’t show up in the scene editor.

For now, the way to send a message in a scene is to use scene Lua (or you can use the action-running abilities of a Reactor activity, or Rules Engine, PLEG, etc.).

-- Send a message to an Emby session (devnum = its Vera device number) luup.call_action( "urn:toggledbits-com:serviceId:EmbySession1", "Message", { Text="hello world!", Header="Greeting" }, devnum )

Sorry for so many posts, the lua is a great read sir. The MVP is luke. Swagger didn't work for a long time when they added authentication. But, yeah...

Ah hahah! Indeed, those docs were killing me. The most trivial tasks turned into hours-long fussing about, until I found swagger. But I get it. The Remote Control API is probably not the most used, so between not getting a lot of in-team attention, and probably very few people looking at it outside, it’s bound to slip off. Swagger is the white knight.

Also, if you wanted specific endpoints in the emby server for something, I can whip them up for you.

That is, if there is something you’d want the emby server to handle and return to vera.

You’ve probably seen the discussion with Luke regarding a real “resume”–start replaying the whole queue from where it stopped. I faked it trivially, as you’ve now seen, by tracking the current media item playing, but since I also can’t access the session’s queue, I don’t know what comes after the current playing media item. The simplest thing for me would be a resume, that simply restarts the last queue on the session (which would imply that the session’s queue has to have some persistence, of course, which currently does not appear to be the case. Second best would be a way to fetch the session’s queue–a simple list of all the media items that are to be played (and perhaps even those played, and some kind of pointer to the current position on the list). That’s a user request, by the way. I’m not sure how useful it is, myself. I’m not sure I’d use it. If I want my queue to stop so I can pick it up later, I’d pause and unpause. If I want media queued up so I can start it playing, I’d create a playlist and use PlayMedia to launch it on demand. Relying on the client’s or server’s memory of what to play doesn’t seem like the right approach. But, it was requested, so I passed it along, and did what I could for now.

The other thing I’d like to get done that I think would really cool, expanding on the “Message” action, would be text-to-speech. I could pull that off if I could get a session to play media by URI (even if its just a file:///tmp/foo.mp3 to play a file that’s local to the server, but ideally, any common protocol/location). Basically, play media that isn’t in the library. I’ve mentioned that to Luke as well. Not a priority for anyone (self included), but could be useful.

Websocket… I have a whole implementation for that. I did it all, made it work. But the real benefit–update immediately when a message arrives–can’t be realized. If I block on the socket, Vera eventually deadlocks, trips the watchdog and reboots. They’re not hooked in deep enough to yield on I/O waits. They want the plugin routines to execute in five seconds or less, or they start logging warning messages. Even if I block for just five seconds, then, I have to give control back to them, I have to return; and then the only way to get control back is with a timer action (one second resolution)–basically polling again. Benefit gone. So I backed it out and shelved it. There is another method, an old, crusty method that’s actually modeled for collecting data from serial devices, that I can try, but I haven’t gone there yet; it would require restructuring all the I/O into that model. I look at this plugin more as a command and control thing, not as a replacement UI for the client UIs. Even if I overcame the socket blocking, Vera only updates its UI about once every two seconds at best, so it will still look jittery and, well, crappy. I can’t even do a free-running clock in JavaScript and try to sync it with the session play progress–UI7 isn’t that flexible on the dashboard cards. If Vera used ALTUI’s model, it would be easy. Hopefully they go that direction. But anyway, for now, it’s command and control, with just enough UI that you can generally see what’s going on.

A request to “NextUp” would give the info for the next item in a queue, but I’m not sure if emby creates a new queue of items each time a session is started.

Specifically when dealing with TV shows emby can be set to play the next item (episode) automatically, and music can be played by album.

A persistence plugin could be made with an accessable endpoint.

If it is about audio, persisting a playlist of favorites, starting where it left off, then I can see some usefulness in having it.

I use text to speech with a home brew Alexa skill and emby plugin. When I ask for a media item, Alexa will read the overview.

I made a video once about it…

Getting emby to play a background audio track for TTS is a very interesting concept.
Wait! There is Theme Song plugin for emby which does exactly that, plays audio behind the interface.
Leave that with me, and I’ll talk to the plugin Dev about how he initalized a background playback instance without hijacking the player.

Thank you for the Lua Message service example as well, it is invaluable! It is pure magic sir!

Benny

The theme song and video plugins purely just download the media to the correct location and name for emby server to pick up. It is up to the cilent devices to implement the display/playback of them

I just discovered this Plugin.

I also use @chef 's Vera Plugin in Emby. Any known conflicts?

Thanks.

I cannot get it to connect to my Emby Server using either Run Discovery or Discover IP. I tried the Emby server IP address with and without the Port Number.

I am not on the same PC as Emby but on the same network. Is there a setting in my Emby Server I need to make?

Guess it is just a matter of waiting a bit. I’m hooked in now.

Now to play around and see what this plugin does for me.

Any tips?

The Wiki states

[Code]Hiding Sessions and Reducing Device UI Clutter

Emby servers can end up having a lot of clients, and the presentation of all of those clients as child devices in the Vera UI can lead to quite a bit of clutter. Two options for automatically hiding sessions are available: hide offline sessions, and hide idle sessions. The visibility of individual sessions can be controlled via the “Sessions” tab on the Emby Server device. This lets you force hide or show a session, overriding the automatic hiding actions of the plugin if those features are enabled.
It may take a moment for the UI to reconcile itself with changes made on this tab. In some cases, it may also be necessary to refresh your browser before the visiblity changes take effect.

[/code]

Where do I find the Sessions Tab?

I need to clean up the clutter before I can dig in to this app.

Thanks

Sent from my SM-G960U1 using Tapatalk

[quote=“Sammy2, post:18, topic:200354”]The Wiki states

[Code]Hiding Sessions and Reducing Device UI Clutter

Emby servers can end up having a lot of clients, and the presentation of all of those clients as child devices in the Vera UI can lead to quite a bit of clutter. Two options for automatically hiding sessions are available: hide offline sessions, and hide idle sessions. The visibility of individual sessions can be controlled via the “Sessions” tab on the Emby Server device. This lets you force hide or show a session, overriding the automatic hiding actions of the plugin if those features are enabled.
It may take a moment for the UI to reconcile itself with changes made on this tab. In some cases, it may also be necessary to refresh your browser before the visiblity changes take effect.

[/code]

Where do I find the Sessions Tab?

I need to clean up the clutter before I can dig in to this app.

Thanks

Sent from my SM-G960U1 using Tapatalk[/quote]

It’s in the Emby master each Emby Server device.

Edit: low caffeine reply

Thanks. I was looking in the Emby Server but I just found it.

Time to see what this will do but it looks like it is controlled by settings in the Advance Tab for each device?

Sent from my SM-G960U1 using Tapatalk