Math with Denon AVR Volume

action: input_number.set_value
metadata: {}
data:
  value: {{ [state_attr('media_player.denon_avc_x3800h','volume_level') | float(0) -
    'input_number.originalvolume,' 1.0] | min }}
target:
  entity_id: input_number.last_played_vol_adjust

If I press Save, it looks like it works, but on refreshing the page it’s completely deleting the value attribute and setting it back to null.

I want to put this in an automation triggered by media playback ending. I already have something in the automation triggered by the start of playback that sets OriginalVolume. My goal is to be able to look up how much I adjusted the volume of that specific movie once it’s over (the next step in the end-of-playback automation sets the volume to what it was before the movie started, and I can’t see the front of the DVR from my seat).

Not sure but I have a Denon-volume input_number helper using 0-100, I guess it must be an integer (whole number) and not a fraction.

‘input_number.originalvolume,’ 1.0

this is a string and cant be initalised as number

this will work better:

{{ (state_attr('media_player.denon_avc_x3800h', 'volume_level') | float(0) - 
    states('input_number.originalvolume') | float(0)) * 100 }}

The current volume is 0.415.

Is the *100 to avoid it being in the 0-1 range? As I said above the current value is 0.415. OriginalVolume is currently 0.51, because I turned it down by 3.5dB after the movie started.

EDIT: I tried that, both with and without the *100, and it still gets reset to “null” when I save the automation.

The comma should be outside the quotes (to seprate the array) not inside, where it mangles the entity id.

'input_number.originalvolume', 1.0]

The string schould also be in a states function, as stated above.

value: {{ [state_attr('media_player.denon_avc_x3800h','volume_level') | float(0) -
           states('input_number.originalvolume') | float(0), 1.0] | min }}

But to make all this obsolete: look into dynamically created scenes (scenes on the fly) to restore the state of any entity to what is was at some point:

That also returns to null on saving.

I already have it restoring OriginalVolume at the end of the movie. I have a different automation that adjusts the volume on a per-movie basis, and I want to store the adjustment I made so I can plug it into that automation later.

… because the outer quotes are missing too:

value: "{{ [state_attr('media_player.denon_avc_x3800h','volume_level') | float(0) -
            states('input_number.originalvolume') | float(0), 1.0] | min }}"

I’m having what I can only assume is a related issue with a button I’m trying to create on my dashboard:

show_name: true
show_icon: false
type: button
tap_action:
  action: perform-action
  perform_action: input_number.set_value
  target:
    entity_id: input_number.originalvolume
  data:
    value: action: input_number.set_value
target:
  entity_id: input_number.originalvolume
data:
  value: "{{ state_attr('media_player.denon_avc_x3800h','volume_level') | float(0) }}"
entity: input_number.originalvolume
name: Set Original Volume
hold_action:
  action: none

When I press the button, I get an error about it expecting a float. But it’s being defined as a float, so I’m not sure what the issue is. I have a near-identical action as part of an automation, and it works fine:

action: input_number.set_value
target:
  entity_id: input_number.originalvolume
data:
  value: "{{ state_attr('media_player.denon_avc_x3800h','volume_level') | float(0) }}"