How to read/interpret "supported_features"?

Hi,

I’m trying to understand what the “supported_features” attribute in my media players mean, but i have not been able to find any documentation to help me.

My Spotify media player has the attribute “supported_features: 51765”. How/where do I find information to help me understand what that number means?

Thanks.

They are the sum of the various SUPPORT_ constants in here https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/media_player/const.py

1 Like

Thanks @nickrout. I have to admit that seemed counter-intuitive, as it seemed like a lot of work to find the combination of features whose constants would add up to the supported_features total for my media player. But I made a spreadsheet that added up all the constants from the page you gave, then started removing features I didn’t think my player had, and sure enough, it added up to the supported_features total.
Just out of curiosity: does anyone know why it’s done that way?

It is meant to be machine rather than human readable.

1 Like

It makes more sense in binary and is faster to interpret for humans as well,
from the linked file we can learn there’s 17 features represented so far i.e. 17 bits. (irc pythons bit size is unbounded meaning it is actually a 17 bit value so far)

so let’s look at it as binary instead:

00000000000000000 = 0 This indicates it supports nothing
00000000010000000 = 128 Supports Turn_on but nothing else
00000000100000000 = 256 Supports Turn_off but nothing else
00000000110000000 = 384 Supports Turn_on and Turn_off but nothing else
1111111110011111111 = 523519 Support everything but Turn_on and Turn_off

you could represent this as a bunch of booleans as well but this solution is a bit more elegant when you want to pass the value around since you only have to pass and process one variable.

It’s not really a “sum” as much as a bitwise OR of the different feature values, but the result is the same.

To extract one of the feature flags, you do a bitwise AND and check if it’s zero.

Sorry for a stupid question I am afraid, but where do you find the linked file?

Read the thread, it is only 8 posts long now. And there is only one file linked in any of the posts.

So sorry, I thought the thread was referring to the piece of quoted code.

I am trying to figure out what features are in included in supported_features of other entities than only ‘media_player’. Right now I want to know more about a ‘cover’ entity.

Taking a look at the code of ‘cover’ I don’t see a list of features with their corresponding meaning and binary value.

My cover entity is specified with supported_features: 3
I guess that means only two features actually?

10000000000000000
01000000000000000

So basically it means my cover probably supports open en close?

Found it:

SUPPORT_OPEN = 1
SUPPORT_CLOSE = 2
SUPPORT_SET_POSITION = 4
SUPPORT_STOP = 8
SUPPORT_OPEN_TILT = 16
SUPPORT_CLOSE_TILT = 32
SUPPORT_STOP_TILT = 64
SUPPORT_SET_TILT_POSITION = 128

3 =

00000000000000011

Of course! Sorry… :smile:

Example of conversion (mix of previous posts, thanks for inspiration):

media_player.samsung_ue40d7000
supported_features: 20281

20281 (decimal) = 100 1111 0011 1001 (binary)

20281 equals to
SUPPORT_PAUSE = 1
SUPPORT_VOLUME_MUTE = 8
SUPPORT_PREVIOUS_TRACK = 16
SUPPORT_NEXT_TRACK = 32
SUPPORT_TURN_OFF = 256
SUPPORT_PLAY_MEDIA = 512
SUPPORT_VOLUME_STEP = 1024
SUPPORT_SELECT_SOURCE = 2048
SUPPORT_PLAY = 16384
(extracted from https://github.com/home-assistant/core/blob/ff9de687c07e8df3ec25dc72e9fb11dbcd2ef0f5/homeassistant/components/media_player/const.py)

How? Easy. Open a calculator that it shows binary and decimal at same time (programmer mode).

You need type in binary and convert to decimal (I only type a 1 and several 0 according to position):

                 1 (binary) = 1 (decimal)
              1000 (binary) = 8 (decimal)
            1 0000 (binary) = 16 (decimal)
           10 0000 (binary) = 32 (decimal)
       1 0000 0000 (binary) = 256 (decimal)
      10 0000 0000 (binary) = 512 (decimal)
     100 0000 0000 (binary) = 1024 (decimal)
    1000 0000 0000 (binary) = 2048 (decimal)
100 0000 0000 0000 (binary) = 16384 (decimal)

Check: 1 + 8 + 16 + 32 + 256 + 512 + 1024 + 2048 + 16384 = 20281

So, now you know that your Samsung Player has SUPPORT_SELECT_SOURCE
Great, but how can you actually use this knowledge to create an automation?
What YAML syntax is need to get things moving?

You use the appropriate service documented here https://www.home-assistant.io/integrations/media_player/#service-media_playerselect_source