Cache Volume level in input number

Hi,

i try to turn down the volume level when I open the window. For this I use a automation, when a window is opened, the volume is turned down but only if it is above a certain threshold. To do this, I need the previously set volume in order to increase it back to the original volume when the window is closed. How can I temporarily store the volume on an input number and then send it back to the receiver from the input number? I use an Onkyo AVR

source_list:
  - PC
  - Bluetooth
  - FM Radio
  - Internet Radio
volume_level: 0.4125
is_volume_muted: false
source: PC
friendly_name: Onkyo
supported_features: 20364

this is from the developer tools you can get the “volume_level” there

You can create an automation that fires whenever the window opens/closes that uses the input_number.set_value command. Then you can use the numeric state of that helper to set the volume back.

When doing the automation you can change it to YAML view and template your push from the Onkyo to the input number helper using code like this:

service: input_number.set_value
target:
  entity_id:
    - input_number.onkyo_receiver
data:
  value: >-
     {{ float(state_attr('media_player.onkyo', 'volume_level'), 0) }}

Obviously change the entity ID’s to be your own, I just made these up.