Avoid the time when the Edinburgh festival is taking place.
During university holidays, halls of residence are usually vacated and the rooms rented out at prices comparable to youth hostels. You do have to provide your own meals though, and there is not usually access to kitchen facilities.
Holyrood House cannot be visited, if the royal family is in residence. I do not know if or when King Charles will be there, his mother used to come in July.
A visit to Glasgow would be a good idea too. Fans of Harry Potter will be interested to know that St Mungo is the patron saint of Glasgow and it is his mitre, crozier and a fish and a ring that feature in one of his miracles that can be seen on the city's coat of arms.
A trip to Loch Lomond is probably on the agenda, and the border towns of Melrose, Jedburgh etc. might be of interest too, or Ayrshire, birthplace of Rabbie Burns.