How to mute an Apple TV

Just a quick one for anyone trying to mute an Apple TV at the set-top box itself rather than at the actual TV or an amp (since the integration doesn’t have a mute function). My use case is that I’m frequently using a set of bluetooth headphones attached to the ATV, and muting the LG doesn’t stop the ads in my ears…
My dashboard mute buttons control the LG which calls an automation that calls this script; the conditions will sync the two mutes if needed. Note that you have to create the input_number in config (min of 0, max of 1).

toggle_atv4_mute:    # called by automation when lg_mute changes
  alias: toggle mute on atv4 when on bluetooth
  mode: single
  sequence:
    - if:
        - condition: state      # the lg wwas muted, mute ATV4
          entity_id: switch.lg_mute
          state: "on"
        - condition: template      # if already muted, don't set the input_numbner to 0
          value_template: >         
            {{ state_attr('media_player.atv4', 'volume_level') | float(default=0.4) != 0 }}
      then:
        - action: input_number.set_value
          target:
            entity_id: input_number.atv4_previous_volume
          data:
            value: "{{ state_attr('media_player.atv4', 'volume_level') | float(default=0.4) }}"
        - action: media_player.volume_set
          target:
            entity_id: media_player.atv4
          data:
            volume_level: 0
      else:       # the LG unmuted, restore vol
        - condition: template      # don't change the vol if not at 0
          value_template: >
            {{ state_attr('media_player.atv4', 'volume_level') | float(default=0.4) == 0 }}
        - action: media_player.volume_set
          target:
            entity_id: media_player.atv4
          data:
            volume_level: "{{ states('input_number.atv4_previous_volume') | float(default=0.4) }}"