Rotary encoder bidirectional control

Hi folks, I am hoping if someone could help me with the esphome code to mimic rotary encoder in ESPhome. I can successfully read the orientation rotary encoder turned in esphome via the following code.

sensor:
  - platform: rotary_encoder
    name: "Rotary Encoder"
    id: thermo_encoder
    pin_a: D5
    pin_b: D7
    on_clockwise:
      - logger.log: "Turned Clockwise"
      - homeassistant.service:
          service: input_number.set_value
          data_template:
            entity_id: input_number.volume
            value: !lambda "return id(volumeselect).state + 0.1;"
    on_anticlockwise:
      - logger.log: "Turned Anticlockwise"
      - homeassistant.service:
          service: input_number.set_value
          data_template:
            entity_id: input_number.volume
            value: !lambda "return id(volumeselect).state - 0.1;"


# HEATING TARGET TEMP FROM HASSIO
  - platform: homeassistant
    entity_id: input_number.volume
    name: "volume state"
    id: volumeselect
    internal: true
    on_value:
    - sensor.rotary_encoder.set_value:
       id: thermo_encoder
       value: 

.

`
I am able to increase/decrease volume I turn the knob in either direction but getting incorrect value.

  1. My amplifier shows 45 as max volume. I like this to align this with 100% in HA. Right now it only shows volume increased or decrease. how to update correct value in HA.
  2. I like to mimic rotarty encoder. When I increase or decrease volume in HA, I like to adjust volume accordingly. I created helper input_number.volume for this purpose. How can I achieve this? I have encoder pin a connected to GPIO14 and pin b is connected to GPIO4. how to adjust code to mimic rotary encoder when I increase or decrease volume in HA?

Appreciate if someone can advise and help me on the code side?
Thank you.