Jump to content

WebHooks


randomevents

Recommended Posts

randomevents

WebHooks broadcaster, I originally started by upgrading the gaps in this excellent plugin -: https://emby.media/community/index.php?/topic/45318-webhooks-plugin/ , but found that there was no reason to stay with the Plex format after some forum and PM requests.

 

This version is playback events and items added (other events to come shortly), and you can use the tokens listed in the settings to create your own message, for example the current playback tokens ({Event}, {ServerID}, {ServerName}, {UserID}, {UserName}, {AppName}, {DeviceID}, {DeviceName}, {DeviceIP}, {ItemType}, {ItemName}, {ItemNameParent}, {ItemNameGrandparent}, {ItemID}, {ItemRunTimeTicks}, {ItemIndex}, {ItemParentIndex}, {ItemCriticRating}, {ItemCommunityRating}, {ItemPremiereDate}, {ItemDateAdded}, {ItemYear}, {ItemBitrate}, {ItemGenre}, {SessionID}, {SessionPlaybackPositionTicks}, {TimeStamp}) might be used to create {"event": {Event}, "user":{UserName}, "item":{ItemName}, "date":{TimeStamp}} as a valid JSON string.

 

Some items of note, {SessionPlaybackPositionTicks} will give you the the correct ticks on stop events, and I added some handlers to take care of the weird stop\pause\resume messages on next\previous track commands for anyone who is aware of that. With the proper ticks being broadcasted, one benefit is that you no longer need to call the media server for progress updates and can calculate them in your app.

 

Question: Should I add Emby's internal flag for isPlackbackCompleted (true or false depending on server settings)?

 

https://github.com/randomevents/Emby.WebHooks/releases

 

2017-11-27 -: 2.0.0.1 Small update to add option to remove quotes from token generation. Useful for crafting statements.

Edited by randomevents
  • Like 1
Link to comment
Share on other sites

randomevents

@@NeauxGeaux

 

An example of a string you showed me last week -:

 

{"text" : "Recently Added!! Vice Principals: S2E9 - The Union of the Wizard & The Warrior", "bot_id" : "XXXXXX"}

 

Check "Remove Quotes From Text Tokens"

{"text" : "Recently Added!! {ItemNameGrandparent}: S{ItemParentIndex}E{ItemIndex} - {ItemName}", "bot_id" : "XXXXXX"}

Link to comment
Share on other sites

NeauxGeaux

Just tested and can confirm this works perfectly! Thanks for adding the check for to remove quotes.

 

Edit:

 

@@randomevents

 

One thing I'm running into is this is running before any meta data for the "Item Added" is generated. So, for example, I copied every variable in your string, and this is the translation I'm receiving:

Item Added Tokens -: {Event}, {ServerID}, {ServerName}, {ItemType}, {ItemName}, {ItemNameParent}, {ItemNameGrandparent}, {ItemID}, {ItemRunTimeTicks}, {ItemIndex}, {ItemParentIndex}, {ItemCriticRating}, {ItemCommunityRating}, {ItemPremiereDate}, {ItemDateAdded}, {ItemYear}, {ItemBitrate}, {ItemGenre}, {TimeStamp}

Translates to:

 

 

Added, 30fb9b8569f2418ba900fbd0051e8e78, MyServer, movies, American.Assassin.2017.1080p, Movies, root, 878af7d4-8f13-f367-2ad9-13eaab0d926d, 0, 0, 0, 0, 0, , 11/28/2017 15:22:53, 2017, 0, , 2017-11-28 09:22:53.939

I did not run a test for TV Shows, but I assume it would render a similar result.

 

I did, however, test the Playback events and all that works perfectly; grabbing the correct meta data for that item.

Edited by NeauxGeaux
Link to comment
Share on other sites

  • 11 months later...

Hi All,

 

I've been trying to install this plugin so I can hook up Emby to HASSIO, but unfortunately it won't work. I'm seeing error-messages in the log:

2018-11-12 06:23:53.524 Error App: Error creating Emby.WebHooks.WebHooks
	*** Error Report ***
	Version: 3.5.3.0
	Command line: C:\Users\******\AppData\Roaming\Emby-Server\system\EmbyServer.dll
	Operating system: Microsoft Windows NT 6.2.9200.0
	64-Bit OS: True
	64-Bit Process: True
	User Interactive: True
	Processor count: 8
	Program data path: C:\Users\******\AppData\Roaming\Emby-Server\programdata
	Application directory: C:\Users\******\AppData\Roaming\Emby-Server\system
	System.TypeLoadException: Could not load type 'MediaBrowser.Controller.Sync.ISyncManager' from assembly 'MediaBrowser.Controller, Version=3.5.3.0, Culture=neutral, PublicKeyToken=null'.
	   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
	   at System.Reflection.RuntimeConstructorInfo.get_Signature()
	   at System.Reflection.RuntimeConstructorInfo.GetParametersNoCopy()
	   at System.Reflection.RuntimeConstructorInfo.GetParameters()
	   at SimpleInjector.Advanced.AdvancedExtensions.Verify(IDependencyInjectionBehavior behavior, ConstructorInfo constructor)
	   at SimpleInjector.ContainerOptions.IsConstructableType(Type implementationType, String& errorMessage)
	   at SimpleInjector.Container.TryBuildInstanceProducerForConcreteUnregisteredType(Type type, InjectionConsumerInfo context)
	   at SimpleInjector.Container.GetInstanceProducerForType(Type serviceType, InjectionConsumerInfo consumer, Func`1 buildInstanceProducer)
	   at SimpleInjector.Container.GetInstanceForRootType(Type serviceType)
	   at SimpleInjector.Container.GetInstance(Type serviceType)
	   at Emby.Server.Implementations.ApplicationHost.CreateInstanceSafe(Tuple`2 typeInfo)
	System.TypeLoadException
	   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
	   at System.Reflection.RuntimeConstructorInfo.get_Signature()
	   at System.Reflection.RuntimeConstructorInfo.GetParametersNoCopy()
	   at System.Reflection.RuntimeConstructorInfo.GetParameters()
	   at SimpleInjector.Advanced.AdvancedExtensions.Verify(IDependencyInjectionBehavior behavior, ConstructorInfo constructor)
	   at SimpleInjector.ContainerOptions.IsConstructableType(Type implementationType, String& errorMessage)
	   at SimpleInjector.Container.TryBuildInstanceProducerForConcreteUnregisteredType(Type type, InjectionConsumerInfo context)
	   at SimpleInjector.Container.GetInstanceProducerForType(Type serviceType, InjectionConsumerInfo consumer, Func`1 buildInstanceProducer)
	   at SimpleInjector.Container.GetInstanceForRootType(Type serviceType)
	   at SimpleInjector.Container.GetInstance(Type serviceType)
	   at Emby.Server.Implementations.ApplicationHost.CreateInstanceSafe(Tuple`2 typeInfo)

Hoping somebody here can point me in the right direction.

Edited by D3lta3
Link to comment
Share on other sites

  • 3 weeks later...
hstamas

Hi all. I was wondering if someone could help me with what I suspect is just a syntax error Im having trying to get this plugin to trigger an IFTTT event?

 

I set up IFTTT webhooks service to trigger a Philips Hue scene. All works fine when I test it on IFTTT. When I copy and past the webhook URL into the URL section of the plugin and start a movie nothing happens.

 

This is the URL that IFTTT is providing me which I copied and pasted into the URL section of the plugin:

 

https://maker.ifttt.com/trigger/{event}/with/key/xxxxxxxxxxxxxx

 

Ive tried all combinations of filling in that {event} place holder with no luck so far. I assume I replace that with the event name I have set up in IFTTT? In this case its called "play".

 

Also in the plugin it indicates putting in the URL and also the port? Ive tried putting in my local port number which did nothing.

 

Any help would be greatly appreciated .

Link to comment
Share on other sites

  • 5 months later...
pir8radio

Sooo  I'm trying to get this to work... anyone have a step by step?  some examples please, does it even work still?

 

I would like to send a trigger when a specific device plays a movie..   The plugin 1, looks like it doesnt work,  and 2. looks like it tries to send for every users play....   So if i have 1000 users playing movies, then it sends a webhook for every one?

2019-05-24 20:11:09.021 Error App: Error creating Emby.WebHooks.WebHooks
	*** Error Report ***
	Version: 4.2.0.8
	Command line: C:\Users\nam\AppData\Roaming\Emby-Server\System\EmbyServer.dll -noautorunwebapp
	Operating system: Microsoft Windows NT 6.2.9200.0
	64-Bit OS: True
	64-Bit Process: True
	User Interactive: True
	Runtime: file:///C:/Users/nam/AppData/Roaming/Emby-Server/System/System.Private.CoreLib.dll
	Processor count: 40
	Program data path: C:\Users\nam\AppData\Roaming\Emby-Server
	Application directory: C:\Users\nam\AppData\Roaming\Emby-Server\System
	System.TypeLoadException: System.TypeLoadException: Could not load type 'MediaBrowser.Controller.Sync.ISyncManager' from assembly 'MediaBrowser.Controller, Version=4.2.0.8, Culture=neutral, PublicKeyToken=null'.
	   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
	   at System.Reflection.RuntimeConstructorInfo.get_Signature()
	   at System.Reflection.RuntimeConstructorInfo.GetParametersNoCopy()
	   at System.Reflection.RuntimeConstructorInfo.GetParameters()
	   at SimpleInjector.Advanced.AdvancedExtensions.Verify(IDependencyInjectionBehavior behavior, ConstructorInfo constructor)
	   at SimpleInjector.ContainerOptions.IsConstructableType(Type implementationType, String& errorMessage)
	   at SimpleInjector.Container.TryBuildInstanceProducerForConcreteUnregisteredType(Type type, InjectionConsumerInfo context)
	   at SimpleInjector.Container.GetInstanceProducerForType(Type serviceType, InjectionConsumerInfo consumer, Func`1 buildInstanceProducer)
	   at SimpleInjector.Container.GetInstanceForRootType(Type serviceType)
	   at SimpleInjector.Container.GetInstance(Type serviceType)
	   at Emby.Server.Implementations.ApplicationHost.CreateInstanceSafe(Tuple`2 typeInfo)
	Source: System.Private.CoreLib
	TargetSite: Void GetSignature(Void*, Int32, System.RuntimeFieldHandleInternal, System.IRuntimeMethodInfo, System.RuntimeType)
	
Edited by pir8radio
Link to comment
Share on other sites

  • 1 month later...
PhyberApex

Bit of a late reply but I got an up and running version over at my github here.

 

No release in github as of yet but should be working alright if you compile it yourself. Will probably release something within the next few days / weeks.

 

~Cheers

  • Like 1
Link to comment
Share on other sites

  • 3 months later...
  • 2 months later...

There will be a new webhooks plugin with the upcoming Emby Server 4.3:

 

https://emby.media/community/index.php?/topic/77969-new-webhooks-plugin/

 

Anyone get this working with Home Assistant yet?

 

My Home Assistant instance is ready to receive Webhook POSTs but Emby might not be formating it correctly?

 

If I send a test POST from Postman, I get the desired automation (turning off the lights), but Emby's webhook test fails.

 

This is the payload of Postman's test which works:

POST http://10.0.0.212:8123/api/webhook/light1 HTTP/1.1
User-Agent: PostmanRuntime/7.21.0
Accept: */*
Cache-Control: no-cache
Postman-Token: a97a4a83-202c-486d-b5ec-8f0ba8bdda42
Host: 10.0.0.212:8123
Accept-Encoding: gzip, deflate
Content-Length: 0
Connection: keep-alive

And the payload Emby's test:

POST http://10.0.0.212:8123/api/webhook/light1 HTTP/1.1
Host: 10.0.0.212:8123
User-Agent: Emby Server/4.3.1.0
Accept-Encoding: deflate
Content-Type: multipart/form-data; boundary="686df1f0-cc64-4525-b3a3-567ffa4732f1"
Content-Length: 267

--686df1f0-cc64-4525-b3a3-567ffa4732f1
Content-Type: application/json; charset=utf-8
Content-Disposition: form-data

{"Event":"system.webhooktest","Server":{"Name":"Emby Server","Id":"6372a9c3d4f54e8b9f784ae086a6496b"}}
--686df1f0-cc64-4525-b3a3-567ffa4732f1--

Home Assistant gives this error from Emby POSTs

Error processing webhook light1
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/webhook/__init__.py", line 77, in async_handle_webhook
    response = await webhook["handler"](hass, webhook_id, request)
  File "/usr/src/homeassistant/homeassistant/components/automation/webhook.py", line 33, in _handle_webhook
    result["data"] = await request.post()
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_request.py", line 645, in post
    out.add(field.name, value)
TypeError: MultiDict keys should be either str or subclasses of str
Edited by Xorp
Link to comment
Share on other sites

Right you'll to setup something to receive the webhooks such as ifttt or zapier, and then send a request to your home assistant.

Link to comment
Share on other sites

Aw dang, I was hoping to cut out the middleware and send events directly from Emby to Home Assistant, and do automations based on those events.

Link to comment
Share on other sites

  • 1 month later...

I suppose that's possible. Currently you can sort of do that by setting up multiple using one for each category.

Link to comment
Share on other sites

No, you can do on Playback events and then it will trigger on Play + Stop + Pause etc. It would be nice to have Play > do this, Stop > do something else

Link to comment
Share on other sites

seanbuff

Yes, I would also like to be able to split out the playback events - this would really help with home automation

Link to comment
Share on other sites

JustEric78

If it helps this request move forward I would love play and pause etc. broken out similar to how the Hue plugin works. I went through setting up Webhooks to get some automation for my Lutron lighting when I hit the same limitation I would imagine most others did. I would even be happy to pay for this plugin and I am sure others feel the same. 

Link to comment
Share on other sites

JustEric78

Unfortunately webhooks doesn't allow for those variables unless I'm missing something? I was able to get this working well with Zapier but if you have more then one variable it wants you to pay $20/mo. I would imagine setting it up like the Hue plugin would be difficult and lots of users would get use out of it that aren't developers.

Link to comment
Share on other sites

If it helps this request move forward I would love play and pause etc. broken out similar to how the Hue plugin works. I went through setting up Webhooks to get some automation for my Lutron lighting when I hit the same limitation I would imagine most others did. I would even be happy to pay for this plugin and I am sure others feel the same.

Link to lutron API please?

  • Like 1
Link to comment
Share on other sites

JustEric78

Link to lutron API please?

Doing some searches and it appears that they do not release their API, there are a few github projects on it however. The link below is to an integration guide although, I do not know if it is accurate for the regular hub or just the pro hub. They do integrate with IFTTT however which was why I was pushing to have the current webhooks made more granular. I could just create a different webhooks applet for play, pause, resume, and stop. 

 

http://www.lutron.com/TechnicalDocumentLibrary/040249.pdf

Link to comment
Share on other sites

JustEric78

I know it is not as much as the time that would go into it, but I have a $100 donation for the modification of the existing plugin to be broken down by event.

Link to comment
Share on other sites

JustEric78

Yes, I meant it would be fairly simple for the developers to implement it (I think).

 

I just posted a walk through on implementing this via a third party that was willing to set it all up for us.

 

https://emby.media/community/index.php?/topic/82998-webhooks-free-method-to-trigger-different-ifttt-applets-using-httpssequematiccom-walk-through/

Link to comment
Share on other sites

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...