Using dimmer switch for volume control

Trying to work this out but my head hurts just thinking about it.

I have a Yamaha Reciever which records volume in dB. When in media player this appears as a percentage 0-100%

I would like to use my Tuya dimmer switch to control the volume. Both appear in Home Assistant successfully.

I can’t work out if I should attempt to use a compensation integration so that the states keep in sync or if I will need a template.

Having been through the maths and using desirable volumes from -60dB (which should be 0% dimming) to -20dB I am looking at 4dB for every 10% volume increase. This will also need to be rounded to the nearest 0.5dB

Does anyone have any clues on the best way to implement this? Should I be looking to set media_player.volume_set to percentage (i.e. 0.5 = 50%) or using dB?

Update: Light brightness is 0 -255 so I have tried creating a compensation but no luck so far:

compensation:
  media_player_db_volume:
    source: media_player.yamaha_rx
    attribute: volume_level
    unit_of_measurement: dB
    data_points:
      - [-20.0, -60.0]
      - [1.0, 0.0]

  dimmer_light_brightness:
    source: light.dimmer_light
    attribute: brightness
    #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:
      - [255.0, 0.0]
      - [1.0, 0.0]

Next update. Getting closer using and automation, just need to work on the formula

alias: Update media player volume
description: ""
trigger:
  - platform: state
    entity_id:
      - light.dimmer_light
    attribute: brightness
condition: []
action:
  - service: media_player.volume_set
    metadata: {}
    data:
      volume_level: "{{ state_attr('light.dimmer_light', 'brightness') | float(0.0) / 100 }} "
    target:
      entity_id: media_player.yamaha_rx
mode: single

Best I’ve come up with. Please do shout if you can think of a better way. A template sensor

{
        "entry_id": "40f0997786182bbdddaa94d1b01b6ea2",
        "version": 1,
        "minor_version": 1,
        "domain": "template",
        "title": "dimmer-vol",
        "data": {},
        "options": {
          "template_type": "sensor",
          "name": "dimmer-vol",
          "state": "{{ ((states.light.dimmer_light.attributes.brightness|float(0) /6.375|float(0) +40)/100) | round(2)}}",
          "state_class": "measurement"
        },
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": null,
        "disabled_by": null
      }

And an automation

- id: '1708782470588'
  alias: Update-Yamaha-volume
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.dimmer_vol
    for:
      hours: 0
      minutes: 0
      seconds: 1
  condition: []
  action:
  - service: media_player.volume_set
    metadata: {}
    data:
      volume_level: '{{ trigger.to_state.state }} '
    target:
      entity_id: media_player.yamaha_rx
  mode: single