Vera and Emby

The purpose of this thread is to discuss and develop possible app for automation of media that is controlled by home Media Center Software called Emby by using available api?s.
Two examples of a use case:
When in home mode motion is detected in the back yard play easy listing music play list from Emby on Emby device xyz
Or
When in Away mode at 5pm turn on tv (rf integration) then send command to emby to play news channel (e.g channel 2) for 2hours on emby device xyz then stop. To give the impression that someone is home and normal activity is occurring etc
Link to emby api:

Link to the Emby forum thread:
Emby Server api
https://r.tapatalk.com/shareLink?share_fid=77624&share_tid=62047&url=https%3A%2F%2Femby.media%2Fcommunity%2Findex.php%3F%2Ftopic%2F62047-Emby-Server-api&share_type=t

So how familiar are you with the Emby API ? I have never looked at it before.

To access it go to the Emby Server Dashboard, scroll down to the bottom of the page and click on the API link. It opens another web page with Swagger.

Some of it looks quite complex to me, first thing I am stuck on is how to find out what my servers “Server UuId” value is?

I can send some simple JSON http commands like this one to list all the Emby client device information:

http://192.168.1.101:8096/emby/Devices?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Or this one to start a library scan routine:

http://192.168.1.101:8096/emby/Library/Refresh?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

So now in Vera I could create a Scene to start the Emby library scan. By adding this line in to the “Also, execute the following Luup code” section of the scene.

luup.inet.wget("http://192.168.1.101:8096/emby/Library/Refresh?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

Under SessionService you can use the following to list the current sessions and get a session ID number.

/Sessions Gets a list of sessions

I then used the:

/Sessions/{Id}/Playing/{Command} Issues a playstate command to a client

I wanted to try and Play / Pause a movie that was playing in Emby on my Android tablet.

The Swagger constructs the following commands:

CURL:

curl -X POST "http://192.168.1.101:8096/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Playing/PlayPause?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "accept: */*" -H "Content-Type: application/json" -d "{\"Command\":\"PlayPause\",\"SeekPositionTicks\":0,\"ControllingUserId\":\"string\"}"

The curl command works OK and pauses / plays the movie on the Android tablet.

However the http command if I run that in a browser I get the response: “Unable to find the specified file.” and it does not work.

http://192.168.1.101:8096/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Playing/PlayPause?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Current Plex user newly interested in Emby. seems cool.

I just found some sample code on this Vera wiki page here.

If I run the code below (Method 2) in the Vera Test Luup Code (Lua) window. It works and the video playback on the Emby Android client app, then pauses or plays.

[code]require(‘ltn12’)
local http = require(‘socket.http’)

– 5 Second timeout
socket.http.TIMEOUT = 5

local response_body = {}
local request_body = ‘’

local r, c, h = socket.http.request{
url = ‘http://192.168.1.101/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Playing/Playpause?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’,
method = “POST”,
port = 8096,
headers = {
[“Content-Length”] = string.len(request_body),
[“Content-Type”] = “application/x-www-form-urlencoded”
},
source = ltn12.source.string(request_body),
sink = ltn12.sink.table(response_body)
}[/code]

I have no idea if this is the proper or best way to send a wget command from Vera to Emby ?

It doesn’t seem to matter what the content type is either: [“Content-Type”] = “application/x-www-form-urlencoded” or [“Content-Type”] = “application/json” work.

I then tried Method 3 from the Vera wiki page and that code works also and the Emby Android client app pauses or plays OK:

[code]local http = require(“socket.http”)

– 5 Second timeout
http.TIMEOUT = 5

– The return parameters are in a different order from luup.inet.wget(
)
result, status = http.request(“http://192.168.1.101:8096/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Playing/Playpause?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”, “run=run”)[/code]

Ideally we need a LUA based plugin for Vera to monitor / control Emby.

With two kids and a lot of devices and media, I’m curious and intrigued. So, I’m looking at it, but if anyone else wants to do it, I’d be happy to wait for theirs.

With two kids and a lot of devices and media, I’m curious and intrigued. So, I’m looking at it, but if anyone else wants to do it, I’d be happy to wait for theirs.[/quote]

I wouldn’t know where to start writing a plugin, I just about get by using code snippets from here and there.

Why have you got the skills to maybe write an Emby plugin for Vera?

I’ve got 10+ current and supported public plugins in the Vera world (and most also run on openLuup, goal is all), and a couple that aren’t in general release yet. As long as their API exposes the necessary functions, I don’t foresee any problems. Since my last reply I’ve put up a VM and have a running emby server that’s scanning media now. To set expectations with regard to plugin timing, I’ve got a vacation coming up (second and third weeks of September), so short of a preliminary/“work in progress” early look before I leave, I would not be releasing anything until later in September.

So tell me, what do you want to do with it on Vera? What functions and features are expected?

Wow great!

Which other Vera plugins have you made?

I’ll put together some usage ideas and desired functions.

My most recent plugins are LuaView and Venstar ColorTouch. This year’s new published work also includes Reactor and DelayLight, and LockValet, which is in a closed beta/not yet published. And before that AutoVirtualThermostat, IntesisWMPGateway, SiteSensor, Rachio Irrigation, VirtualSensor, and DeusExMachinaII. I’ve been working for some time on a plugin that tries to address the support issues around scene controllers (Leviton VRCS4/VRCZ4, EnerWave SC-7, and that ilk), and fixes problems with Vera’s delayed actions in scenes (that part of the project also recently made its way into Reactor). I’m also doing ongoing work on a rethought approach to DeusExMachinaII. And I’ve done some customizations of other existing plugins and new special-purpose plugins for a few people in the community who have asked. Helping out where I can.

1 Like

My most recent plugins are LuaView and Venstar ColorTouch. This year’s new published work also includes Reactor and DelayLight, and LockValet, which is in a closed beta/not yet published. And before that AutoVirtualThermostat, IntesisWMPGateway, SiteSensor, Rachio Irrigation, VirtualSensor, and DeusExMachinaII. I’ve been working for some time on a plugin that tries to address the support issues around scene controllers (Leviton VRCS4/VRCZ4, EnerWave SC-7, and that ilk), and fixes problems with Vera’s delayed actions in scenes (that part of the project also recently made its way into Reactor). I’m also doing ongoing work on a rethought approach to DeusExMachinaII. And I’ve done some customizations of other existing plugins and new special-purpose plugins for a few people in the community who have asked. Helping out where I can.[/quote]

Thank you Rigpapa for these. It is devs like you that make Vera great!

I don’t think I’ve used any of your plugins before, but yes I totally agree its talented people like rigpapa who have made the Vera platform that much better. :slight_smile:

This git page shows all the endpoints in the wonderful world of emby :slight_smile:

So some thoughts on what an Emby plugin for Vera might be used for ?

For those not familiar, Emby is an open source Media Server platform along the lines of Plex. It came out of the Windows Media Center MCE world and was originally a plugin for MCE called Media Browser, which over the years has been developed in to a full blown Media Server solution, handling your media libraries and metadata for Movies, TV Shows, Music etc. Allowing remote clients to access your media library. Live TV integration and much more.

The server software can be run on Windows, Linux, Mac, NAS devices etc. They have various mobile client applications for Android, iOS, Windows 10 / phone. And also apps or support for devices like Android TV, Amazon FireTV, Nvidia Shield, AppleTV, Roku, Smart TVs, ChromeCast support, games consoles and a brilliant plugin for Kodi.

https://emby.media/

So what do we want to do in Vera with Emby client devices?

  1. Maybe to be able to add a device in to Vera that represents an Emby client device, perhaps with transport control buttons for playback control. Play, Pause, Stop etc. To see the currently status of the Emby client device, what is it playing etc. Maybe to be able to run Vera triggers off the status.

NOTE: There is already an Emby Server side plugin for Vera in the other direction. Developed by Chef. “Trigger Scenes with your Vera products with Emby Events. Dim z-wave compatible lights when you start a movie. Turn the lights back on when the movie stops.”

But we would like to be able to send commands out from Vera to Emby client devices and to the Emby server, which is the other way.

  1. To be able to send popup notifications on screen to Emby client devices from Vera to notify users of something happening like the doorbell for example. I believe the Emby API supports this in Swagger there is a NotificationService section. And perhaps automatically pause media playback during such an event like the doorbell being triggered.

  2. To be able to send commands to an Emby client device to start playing certain media, e.g. a TV channel or a music playlist for example as the OP wanted.

  3. Perhaps send commands from Vera to the Emby server to start server side tasks, like starting a library scan to update media.

What else ?

Thanks for your input Rippa, your reactor plugin is great!
In my opinion having a plugin that can poll emby for a list of possible clients to select and media to select (music, video and live tv channels) would be grand. This way many scenarios could be automated two of which I have given examples of in the start of this thread but there could be many use cases, another example might be if motion is detected in the baby?s room between xyz hours (known sleeping time)while in home mode play playlist baby lullaby on device xyz (Sonos speaker in baby room for example)etc. I think sending a message to a current session is more difficult and a nice to have (I believe that chef has achieved this after some degree of trouble) but the core abilities would be what I have described at the start of this post in my opinion.
Thanks Rippa!
P.s I was hoping we would also see some interaction/input from the new Mios team given the leader recent posts about improvements

I think the mios team will be concentrating on the core Vera product
and Z-Wave devices and other popular smart home devices, rather than integration with 3rd party systems like Emby Media server.

[quote=“cw-kid”]I think the mios team will be concentrating on the core Vera product
and Z-Wave devices and other popular smart home devices, rather than integration with 3rd party systems like Emby Media server.[/quote]
Increase forum support from the employee of Mios to customer and support of 3rd part developers was mentioned

My most recent plugins are LuaView and Venstar ColorTouch. This year’s new published work also includes Reactor and DelayLight, and LockValet, which is in a closed beta/not yet published. And before that AutoVirtualThermostat, IntesisWMPGateway, SiteSensor, Rachio Irrigation, VirtualSensor, and DeusExMachinaII. I’ve been working for some time on a plugin that tries to address the support issues around scene controllers (Leviton VRCS4/VRCZ4, EnerWave SC-7, and that ilk), and fixes problems with Vera’s delayed actions in scenes (that part of the project also recently made its way into Reactor). I’m also doing ongoing work on a rethought approach to DeusExMachinaII. And I’ve done some customizations of other existing plugins and new special-purpose plugins for a few people in the community who have asked. Helping out where I can.[/quote]

+1 for your tremendous contributions.

To send a popup notification to an Emby client app / user.

In Swagger its under:

SessionService - /Sessions/{Id}/Message Issues a command to a client to display a message to the user

You need the correct SessionID number of the Emby client device you want to send the message to and your Emby server API key.

In the examples below the SessionID number for the Emby app on my Android tablet was “9e69a4c0f6308d51692434f33779fa5f”.
Change “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx” with your Emby Server API key.

Curl Command Example:

curl -X POST "http://192.168.1.101:8096/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Message?Text=Hello%20World&Header=Test&TimeoutMs=5000&api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "accept: */*"

HTTP Command Example:

http://192.168.1.101:8096/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Message?Text=Hello%20World&Header=Test&TimeoutMs=5000&api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Lua Code Example:

[code]local http = require(“socket.http”)

– 5 Second timeout
http.TIMEOUT = 5

– The return parameters are in a different order from luup.inet.wget(
)
result, status = http.request(“http://192.168.1.101:8096/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Message?Text=Hello%20World&Header=Test&TimeoutMs=5000&api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”, “run=run”)[/code]

I’m not sure how you send a message to all connected clients ?