I tried to download the app Aspect Ratio Detector, i tried to register for the website but I still cannot gain access… having time to play around, how about something a little bit out of the box ![]()
Within the your configuration.yaml file place this:
rest_command:
plex_get_aspect_ratio:
url: "http://<plex_server_ip>:32400/library/metadata/{{ rating_key }}?X-Plex-Token=<plex_token_id>"
method: GET
headers:
Accept: "application/json"
(changing the plex_server_ip and the plex_token_id)
Reboot your home assistant instance. This will allow a rest command to be sent to your plex instance
then you could use these in the generic playback or movie/tv show playback (which trigger for a certain player). placing this under Generic means every player that plays media wil trigger the rest command.
retrieve a bit more information about the media than what is sent within the webhook.
action: rest_command.plex_get_aspect_ratio
metadata: {}
data:
rating_key: "{{ payload.Metadata.ratingKey }}"
response_variable: plex_aspect_response
then, extract the ratio information from the data and hold it as a variable (plex_aspect_ratio)
variables:
plex_aspect_ratio: >-
{{
plex_aspect_response.content.MediaContainer.Metadata[0].Media[0].aspectRatio
}}
finally using the plex_aspect_ratio variable, use it within a choose option as needed:
choose:
- conditions:
- condition: template
value_template: "{{ plex_aspect_ratio == 1.85 }}"
sequence:
- action: persistent_notification.create
metadata: {}
data:
message: "aspect ratio: 1.85"
title: "Ratio: 1.85"
- conditions:
- condition: template
value_template: "{{ plex_aspect_ratio == 2.35 }}"
sequence:
- action: persistent_notification.create
metadata: {}
data:
message: "aspect ratio: 2.35"
title: "Ratio: 2.35"
- conditions:
- condition: template
value_template: "{{ plex_aspect_ratio == 1.78 }}"
sequence:
- action: persistent_notification.create
metadata: {}
data:
message: "aspect ratio: 1.78"
title: "Ratio: 1.78"
if you look in the trace and the changed variables from the rest command there is a lot of information about the media.
@modem7 you could also use this (with a bit of tweaking) to obtain the audio details, as the rest command does return more information about the stream.
variables:
plex_audio_codec: >-
{{
plex_aspect_response.content.MediaContainer.Metadata[0].Media[0].Part[0].Stream[1].codec
}}
plex_audio_channels: >-
{{
plex_aspect_response.content.MediaContainer.Metadata[0].Media[0].Part[0].Stream[1].channels
}}
plex_audio_layout: >-
{{
plex_aspect_response.content.MediaContainer.Metadata[0].Media[0].Part[0].Stream[1].audioChannelLayout
}}
this returns:
plex_audio_codec: ac3
plex_audio_channels: 6
plex_audio_layout: 5.1(side)