A dog wagging it's tell does usually mean the dog is happy and especially if you just come home to the dog and the dog wags it's tail when it sees you then it's likely the dog is happy and happy to see you.
Dogs also use their tails to communicate with humans and other pets so the dog wagging it's tail could be that the dog is trying to get your attention.
So the dog could be communicating with you or with another animal while wagging it's tail or the wagging could mean the dog is happy.
Or the dog could also be wagging it's tail to keep flies, gnats, mosquitoes etc away from it's backside.
But yes dogs wagging their tails can mean they're happy but it doesn't always mean they're happy when they're wagging their tail.