Error with compensation integration

Fairly new to HA and am mostly getting where I need to go through trial and error, but running into an error I can’t seem to resolve. I want to use the compensation integration to normalize volume levels for my AVRs (I have a Yamaha where the volume scale goes from -80dB to +16dB and an NAD where it goes from -92dB to +1dB). I want 100 on HA to equal the max and 0 to equal the minimum.

Here’s the code from my configuration.yaml file:

compensation:
  - media_player_db_volume:
    source: media_player.office
    attribute: volume_level
    unit_of_measurement: dB
    data_points:
      - [0.2, -80.0]
      - [1.0, 16.0]
     
  - media_player_db_volume:
    source: media_player.nad_receiver
    attribute: volume_level
    unit_of_measurement: dB
    data_points:
      - [0.2, -90.0]
      - [1.0, 1.0]

Here’s the error log (just for the Yamaha but it’s doing the same for the NAD):

2024-01-20 07:49:16.854 ERROR (MainThread) [homeassistant.config] Invalid config for 'compensation' at configuration.yaml, line 57: expected a dictionary for dictionary value 'compensation', got [{'media_player_db_volume': None, 'source': 'media_player.office', 'attribute': 'volume_level', 'unit_of_measurement': 'dB', 'data_points': [[0.2, -80.0], [1.0, 16.0]]}, {'media_player_db_volume': None, 'source': 'media_player.nad_receiver', 'attribute': 'volume_level', 'unit_of_measurement': 'dB', 'data_points': [[0.2, -90.0], [1.0, 1.0]]}], please check the docs at https://www.home-assistant.io/integrations/compensation

Any ideas? Thanks …

Check the indentation and use of - in your config with the documentation, the media players should not be a list and the information below it is indented differently. Indentation matters in yaml.

Thanks, but without making it a list with the -, I get a duplicate mapping error:

duplicated mapping key (66:3)

 63 |       - [0.2, -80.0]
 64 |       - [1.0, 0.0]
 65 | 
 66 |   media_player_db_volume:
--------^
 67 |     source: media_player.nad_receiver
 68 |     attribute: volume_level

The indentation came directly from copy and paste but I can redo that, but how do I resolve the duplicate mapping?

The documentation could do with some improvement. It shows duplicate keys. These actually have to be unique. E.g.

compensation:
  media_player_db_volume:
    source: media_player.yamaha_receiver
    attribute: volume_level
    unit_of_measurement: dB
    data_points:
      - [0.2, -80.0]
      - [1.0, 0.0]

  media_player_zone_2_db_volume: # can't be the same name as the one above.
    source: media_player.yamaha_receiver_zone_2
    attribute: volume_level
    unit_of_measurement: dB
    # Ensure that the sensor's value will not have a state lower than -80.0
    # when the source sensors value is less than 0.2
    lower_limit: true
    # Ensure that the sensor's value will not have a state greater than 0.0
    # when the source sensors value is greater than 1.0
    upper_limit: true
    data_points:
      - [0.2, -80.0]
      - [1.0, 0.0]

I’ll submit a PR to update this later today.

Thanks Tom, that fixed it. One other question, the scale is capped at 100 = 0dB, but my AVR goes to 16db (this is fine for the NAD which only goes to 1dB). I am looking to have the volume scale mirror the percentage of max volume as close as possible. I’ve tried

upper_limit: false

but that didn’t resolve, any ideas?