How to read/interpret "supported_features"?

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.

1 Like

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?

1 Like

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
1 Like

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

1 Like

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

For the convenience of anyone stumbling on this conversation, here’s some quick Python3 code to print a list of which features are supported or unsupported for a given value of supported_features:

supported_features = 23997

features = {
            1: "Pause",
            2: "Seek",
            4: "Volume Set",
            8: "Volume Mute",
            16: "Previous Track",
            32: "Next Track",
            128: "Turn On",
            256: "Turn Off",
            512: "Play Media",
            1024: "Volume Step",
            2048: "Select Source",
            4096: "Stop",
            8192: "Clear Playlist",
            16384: "Play",
            32768: "Shuffle Set",
            65536: "Select Sound Mode",
            131072: "Browse Media",
            262144: "Repeat Set",
            524288: "Grouping",
           }
is_supported = {True: "[Supported]:   ", False: "[Unsupported]: "}

for key, feature in features.items():
    print(f"{is_supported[bool(supported_features & key)]}{features[key]}")

The list of features is taken from the source code, which had been updated since the original post above.

4 Likes

Good, now build one for all the other domains :slight_smile:

Hi all. In my case I have a television that supports the number 155581. So why is it that nothing can be done? Thanks

volume_level: 0.36666666666666664
is_volume_muted: false
device_class: tv
friendly_name: 43PFG5813/77
supported_features: 155581

What does “nothing can be done” mean?

In the case of this television you can see the sound but I have no way to turn it on or change the origin for example.
I have another philips that I have to control with a broadlink because it has no possibility of doing anything. Maybe it is not understood why I use a translator. Excuse me and thank you very much for answering

Tv philips (fewer options despite being newer)

device_class: tv
friendly_name: 43PFG5813/77
supported_features: 155453

The audio equipment despite having a smaller number in supported_features: 66060 shows much more information

sound_mode_list:
  - FactoryDefaults
volume_level: 0.52
is_volume_muted: false
media_content_id: file://TV
media_content_type: music
media_duration: 0
media_position: 0
media_position_updated_at: '2021-12-22T20:03:04.072292+00:00'
media_title: TV
media_track: 1
shuffle: false
repeat: 'off'
friendly_name: BDV-N9200W
supported_features: 66060

If anyone without a developer background lands in this thread, here is a tip. To find out what features are enabled, you can either do all the boolean and bitwise operations above, or you can follow a much simpler approach.

Suppose you want to find out what is supported on OP’s case (supported_features: 51765). You need to look at the constants SUPPORT_* on that file indeed (https://github.com/home-assistant/core/blob/9250dd0355eee4721b17c416acd5331d1ac84c76/homeassistant/components/media_player/const.py). But the trick is to find the largest number that is lower than your target, and subtract.

So for 51765, that largest number would be SHUFFLE_SET = 32768, as the next one (SELECT_SOUND_MODE) is already over your initial number.

So you know your device supports SHUFFLE_SET. You now have a remainder of 18997 (51765 - 32768). So you apply again, finding the largest number on the table that is lower than your target value, calculating the remainder, and you repeat until you reach zero.

PLAY = 16384 (remainder 2613)
SELECT_SOURCE = 2048 (remainder 565)
PLAY_MEDIA = 512 (remainder 53)
NEXT_TRACK = 32 (remainder 21)
PREVIOUS_TRACK = 16 (remainder 5)
VOLUME_SET = 4 (remainder 1)
PAUSE = 1 (remainder 0, stop)

Again, you are just decoding binary. Your methodology is slightly easier,

Where did you find this?

I have no idea anymore but a search just lead me to the following info as part of the Home Assistant code: