PrincessClevage 173 Posted August 24, 2018 Share Posted August 24, 2018 Hello gents, On the Mios Vera forums we have been discussing what is possible to integrate automation from Vera > emby using emby api E.g Would it be possible to use emby api to: Play live tv selecting channel xyz on emby device xyz Another example: Would it be possible to use emby api to play xyz music on emby device xyz If the above is possible could you please provide some guidance on where to find the appropriate api commands and which command might be valid to use in the above scenarios Link to comment Share on other sites More sharing options...
Luke 37118 Posted August 25, 2018 Share Posted August 25, 2018 Hi, yes, all of that is possible. I would suggest checking out our api wiki: https://github.com/MediaBrowser/Emby/wiki Please let us know if this helps. Thanks ! Link to comment Share on other sites More sharing options...
PrincessClevage 173 Posted August 25, 2018 Author Share Posted August 25, 2018 Link to the Mios Vera thread: Vera 2 Emby https://r.tapatalk.com/shareLink?share_fid=24007&share_tid=103145&url=http%3A%2F%2Fforum%2Emicasaverde%2Ecom%2Findex%2Ephp%3Ftopic%3D103145&share_type=t Link to comment Share on other sites More sharing options...
PrincessClevage 173 Posted August 25, 2018 Author Share Posted August 25, 2018 Hi, yes, all of that is possible. I would suggest checking out our api wiki: https://github.com/MediaBrowser/Emby/wiki Please let us know if this helps. Thanks ! Thanks Luke,I have started a thread on the Vera forums and hope it will get some traction there. Mios has been bought out and the new owners are suggesting deeper user interaction and improvements to the product so this will be a good benchmark to see if things improve. I must say if they get anywhere close to Embys model for employee and customer forum interaction it would be a huge improvement as I believe that Emby must be a market leader in this area! Link to comment Share on other sites More sharing options...
Luke 37118 Posted August 25, 2018 Share Posted August 25, 2018 Thanks for the feedback ! Link to comment Share on other sites More sharing options...
cw-kid 192 Posted August 25, 2018 Share Posted August 25, 2018 Hi I've been looking at the Emby API to try and send some simple http commands from Vera using wget to the Emby server to control an Emby client device etc. I can get some of the curl commands working OK but when I try to use a http command in the browser it says: Unable to find the specified file. I posted about this on the Vera forum as well here: 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 Link to comment Share on other sites More sharing options...
PrincessClevage 173 Posted August 26, 2018 Author Share Posted August 26, 2018 Can any Emby gurus help out here please? Link to comment Share on other sites More sharing options...
Luke 37118 Posted August 26, 2018 Share Posted August 26, 2018 First, did you consult the wiki? You can also review our JavaScript libraries: https://github.com/MediaBrowser/Emby.ApiClient.Javascript Emby apps use these libraries directly so you can find examples for just about everything that you need to do. Link to comment Share on other sites More sharing options...
chef 3746 Posted August 27, 2018 Share Posted August 27, 2018 There has to be specific headers in the request. I have examples of Ajax requests I can post here. I also seem to remember having to use SHA encoding and MD5 encoding if I recall. Link to comment Share on other sites More sharing options...
cw-kid 192 Posted August 27, 2018 Share Posted August 27, 2018 There has to be specific headers in the request. So looks like we won't be able to send simple one line http JSON commands from Vera to Emby then. Another usage example, would be sending popup notifications to Emby client devices from the Vera HA controller, when something happens for example a doorbell trigger. Link to comment Share on other sites More sharing options...
chef 3746 Posted August 27, 2018 Share Posted August 27, 2018 (edited) So looks like we won't be able to send simple one line http JSON commands from Vera to Emby then. Unless adding the API key to the end of the URL stops the nessessity of headers. Cw-kid Is there no way of adding headers to a Lua wget method? Edited August 27, 2018 by chef Link to comment Share on other sites More sharing options...
chef 3746 Posted August 27, 2018 Share Posted August 27, 2018 here is a weget example using lua? wget --header="User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5" \ --header="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" \ --header="Accept-Language: en-us,en;q=0.5" \ --header="Accept-Encoding: gzip, deflate" --header="Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" \ --header="Cookie: lang=us; reg=1787081http%3A%2F%2Fwww.site.com%2Fdc%2F517870b8cc7" \ --referer=http://www.site.com/dc/517870b8cc7 http://www.site.com/download?123456:75b3c682a7c4db4cea19641b33bec446/document.docx Here are the headers for emby: Authorization=Emby UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="Android", Device="Samsung Galaxy SIII", DeviceId="xxx", Version="1.0.0.0" But in order to get a list of users you would make a call to public users, the choose an ID. The public users endpoint doesn't need a token to get information. It is an open endpoint. You can then use the information from that return to build your headers for following requests. The next request would be to authorize a specific user, using the header example above. Link to comment Share on other sites More sharing options...
chef 3746 Posted August 27, 2018 Share Posted August 27, 2018 (edited) I'm thinking it might look like this: wget "{embyUrl:Port}/Users/Public" That will return a list of users. Maybe try: wget --header="User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5" \ --header="Accept: application/json" \ --header="X-Emby-Token: {ApiKey}" \ http://{EmbyIp:Port}/{ApiEndpoint} Or something similar. I also could be completely wrong. Or maybe I helped. I think it might actually be something like this: wget --header="User-Agent: Mozilla/5.0 Gecko/2010 Firefox/5" \ --header="Accept: application/json" \ --header="X-Emby-Token: {ApiKey}" \ --header="Authorization=Emby UserId=\"{userId}\", Client=\"Vera\", Device=\"{VeraDeviceType}\", DeviceId=\"xxx\", Version=\"1.0.0.0\"" http://{EmbyIp:Port}/{ApiEndpoint} Like I say if it where a C# based service monitor which watched for events in Vera, and triggered Emby command lines. I have already written it. But I know this is about a lua based plugin for vera. Edited August 27, 2018 by chef Link to comment Share on other sites More sharing options...
Luke 37118 Posted August 27, 2018 Share Posted August 27, 2018 So looks like we won't be able to send simple one line http JSON commands from Vera to Emby then. Another usage example, would be sending popup notifications to Emby client devices from the Vera HA controller, when something happens for example a doorbell trigger. Are you not able to attach request headers? Link to comment Share on other sites More sharing options...
cw-kid 192 Posted August 28, 2018 Share Posted August 28, 2018 (edited) The problem is I don't really know what I am doing. 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. 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) } 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. Maybe @@chef can give us some better Lua code examples? for interacting with Emby and sending control commands to it from Vera etc. Ideally we need a LUA based plugin for Vera to monitor / control Emby. Edited August 28, 2018 by cw-kid 1 Link to comment Share on other sites More sharing options...
cw-kid 192 Posted August 28, 2018 Share Posted August 28, 2018 I just tried Method 3 from the Vera wiki page and that code works also and the Emby Android client app pauses or plays OK: 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") Link to comment Share on other sites More sharing options...
cw-kid 192 Posted August 28, 2018 Share Posted August 28, 2018 But simply running this one line of code from Vera does not work: luup.inet.wget("http://192.168.1.101:8096/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Playing/Playpause?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") Link to comment Share on other sites More sharing options...
Luke 37118 Posted August 28, 2018 Share Posted August 28, 2018 But simply running this one line of code from Vera does not work: luup.inet.wget("http://192.168.1.101:8096/emby/Sessions/9e69a4c0f6308d51692434f33779fa5f/Playing/Playpause?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") And you understand why, right? Link to comment Share on other sites More sharing options...
cw-kid 192 Posted August 28, 2018 Share Posted August 28, 2018 And you understand why, right? Not really LOL. Because it needs a socket connection and headers? Link to comment Share on other sites More sharing options...
chef 3746 Posted August 28, 2018 Share Posted August 28, 2018 (edited) Because one is a 'post' method and the other a 'get' method. Edited August 28, 2018 by chef Link to comment Share on other sites More sharing options...
chef 3746 Posted August 28, 2018 Share Posted August 28, 2018 (edited) does this work? headers = { ["Content-Length"] = string.len(request_body), ["Content-Type"] = "application/json", ["X-Emby-Token] = {APITOKEN} ["Authorization] = "Emby UserId=\"{userId}\", Client=\"Vera\", Device=\"{VeraDeviceType}\", DeviceId=\"xxx\", Version=\"1.0.0.0\"" }, What IDE do you use for developoing LUA code? Edited August 28, 2018 by chef 1 Link to comment Share on other sites More sharing options...
cw-kid 192 Posted August 28, 2018 Share Posted August 28, 2018 So could the correct headers be added to that single line http command? It does work however OK with the other Lua code examples I found. Just easier in Vera to use a single line http command and wrap it round the luup.inet.wget("http://some-command") Thanks. Link to comment Share on other sites More sharing options...
cw-kid 192 Posted August 28, 2018 Share Posted August 28, 2018 (edited) Edited August 28, 2018 by cw-kid 1 Link to comment Share on other sites More sharing options...
chef 3746 Posted August 28, 2018 Share Posted August 28, 2018 So could the correct headers be added to that single line http command? It does work however OK with the other Lua code examples I found. Just easier in Vera to use a single line http command and wrap it round the luup.inet.wget("http://some-command") Thanks. Then yes, use one of those two examples posted that worked. the "luup.inet.wget" command probably won't because of the methods used to make the request. Just to confirm you are testing the luup code in the apps section of the vera UI? I'm totally on board to help. I'm a total newbie to luup and lua. So you'll have to pardon my learning curve. Link to comment Share on other sites More sharing options...
chef 3746 Posted August 28, 2018 Share Posted August 28, 2018 (edited) The problem is I don't really know what I am doing. 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. 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) } 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. Maybe @@chef can give us some better Lua code examples? for interacting with Emby and sending control commands to it from Vera etc. Ideally we need a LUA based plugin for Vera to monitor / control Emby. This is what you probably want to work with. Because you are using an ApiKey in the http url, you won't have to authenticate users. So creating a plugin based around this code should be straight forward. You'll definitely want to change the content type to "application/json". Note: some of this code reminds me of python here is some conditionals: if then else end if and or else end function (){ } This reminds me of Arduino Code: local VARNAME = require('LIBRARY.NAME') Also all variables are called "local" They don;t have to be defined as an integer or string. local myString = '' local myInt = 1 Edited August 28, 2018 by chef Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now