[Webhook] Emby playback event in trigger.data

I am trying to make a script to dim my lights when Emby starts or unpauses a video.

The webhook variable data, partially, looks like this:

trigger:
  platform: webhook
  webhook_id: '--gEaSWWt5Yhj7dNcg7M8drUg'
  data:
    __type: <class 'multidict._multidict.MultiDictProxy'>
    repr: >-
      <MultiDictProxy('data':
      bytearray(b'{"Title":"playback.unpause","Date":"2022-11-06T13:58:21.0578819Z","Event":"playback.unpause"

My webhook looks like this but is not working

alias: "[Webhook] Emby"
description: ""
trigger:
  - platform: webhook
    webhook_id: "--abcdefg"
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.data['Event'] == \"playback.unpause\" }}"
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.living_room_lights
mode: single

What am I doing wrong?

Canā€™t you just use the media player entity state ?

How do I do that?

Am open to ideas but also would like to know how to access the trigger correctly.

Have you installed the emby integration ?

Iā€™ve added it just now to the HA configuration and setup an API key in Emby but I cannot see anything related to the Emby server media player when I set up the condition.

The media player entity will change states like playing, paused etc. I use it as a trigger to do just what you want.

Can you show me specifically like a screenshot or something? I have all sorts of different media player entities but the only ones relating to Emby are ā€œcastā€ entities and thatā€™s not what I want.

There is no media player entity specific to my Emby server.

Have you restarted after installing the emby integration ? You should have a media player entity with emby in the name. Search for emby in Dev tools/states. If not, check your logs to see if it set up ok

I have an entity in the Dev tools/states called ā€œ[media_player.emby_sony_cast_tv]ā€ which has the correct states and this works in the automation.

I think I was a bit confused with what the entity name should have been. This makes more sense because I donā€™t want to the lights going off if Emby is started on another device.

Thanks for the help.

Glad itā€™s sorted. I started with webhooks too but found the integration and use that only now. Youā€™re right that an emby media player will be generated on each device you open emby on so you can set up automations for each device if necessary.

Yeah greatā€¦I will remove the webhook and set up some triggers for the various states. Feels like a much cleaner solution. Thanks again!

The state of the media player entity is not stable.
If you change profile on Emby, or turn off, and turn back on later, HomeAssistant keeps the ā€œIdleā€ state and no longer detects the switch to Play, Stop, etcā€¦
The only way to get the correct state is to restart the HA Core.
Unfortunately, there is no documentation on the structure of webhook data received on HA.

Anyone have anything useful?

I have a similar problem I would like to check the device name in a condition and if it is present that the automation is executed further unfortunately the condition does not work.

condition:
  - condition: template
    value_template: "{{ trigger.data.DeviceName == \"PC\" }}"

Does anyone know how to search for the emby device name?

To answer my own question it is:

{{ 'DeviceName":"PC' in trigger.data['data'].decode('utf-8') }}

Indeed, searching for a string within a string works, but itā€™s not elegant.
Donā€™t tell me there isnā€™t a way to use the received structure efficiently, despite this ā€œ{ā€˜dataā€™: bytearray(bā€™{ā€¦ā€ which encapsulates the JSON structure.
Searching for a solution does not return anything.
To believe that those who know or who find the solution do not want to share it.

this is for me an really anoying bug.
even if i turn of the 'automatically close connection" in the profile menu it keeps disconecting and have to restart ha.

Still havenā€™t found a solution for this, did you found anything to fix this?

Iā€™m using this custom component now and works great, the media_players do go offline on a restart but they are back up when emby is running again

I put the files in the folder mediabrowser in the custom component folder, but cannot find in when try to add it in the intergration page.

Gonne try a bit more

Did you use HACS ?

Also, did you restart after copying ?

Yes did a restart a couple of times.
But still nothing.gonne try it from the start again