Save Volume Level

Recently I’ve been saving light states creating scenes on the fly which has been working great.

Is it possible to save the volume level of a media player using the same method? I’ve given it a go but may be missing something as I can’t get it to work.

I’ve saved the media volume with an automation and an input_number.

  - id: mln011
    alias: 'Cast Media Volume'
    trigger:
      platform: state
      entity_id: media_player.cast_media
    condition:
      condition: state
      entity_id: media_player.cast_media
      state: playing
    action:
      - service: input_number.set_value
        data_template:
          entity_id: input_number.cast_media_volume
          value: "{{ state_attr('media_player.cast_media', 'volume_level')
            | round(2) }}"

Basically it saves the volume every time the media_player state changes in the playing mode. Then when you turn your media_player on set the volume to the input_number value. Haven’t tried scenes but this way is pretty easy and works well.

Thank you, i’ll give this a go.