But why was real automatically assigned in group H and not in D when both were available? There were no other spanish teams drown at that moment.
That was a very interesting question and i had to analyze the draw very precisely, not knowing what caused that felt pretty uncomfortable.
So basically this was the table before Real got picked:
Now we have to place Real somewhere, it seems pretty obvious that both groups should be avaiable, but let's look at pot 2:
And here is the important part: seems that UEFA's regulations state that 2 best teams from same country must play on different days (so one must be in A-D and one in E-H) and the other rule is that teams from same country must be evenly distributed over days (so if there are 4, 2 in A-D and 2 in E-H).
Now let's assume Real gets assigned to group D. Let's see where this takes us:
-Barca must be assigned to groups E-H since Real is in A-D
-Dortmund also E-H, because of Bayern
-City also E-H, because of Chelsea
-Porto also E-H, because of Benfica
so now we see that E-H groups are full, so the rest must go to A-D and we have PSG, United, Atleti and Sevilla = 2 Spanish teams while Real is already there. This makes 3 out of 4 Spanish teams competing in CL in A-D. That's why Real had to go to H, so there would be 2 Spanish teams in A-D and 2 in E-H.