Absolutely, they always know. :-)
One of my friends dogs had an ear infection and of course as you all know you have to do the mandatory ear drops, well my friend could not get her dog to keep still she had trouble holding him, he would move his head all the time and he would run away the moment he saw the ear drops come out of the cupboard. She was stressing on the phone to me that she could not do it alone, she said more of the ear drop was on the floor than in her dog. :-D So I told her I would come over to assist and see how she was doing it.
Unfortunately, she slipped on ice and broke her arm that night, I turned up in the morning for tea and sympathy and of course to help with her dog and something unbelievable happened........ She went to get the ear drops and instead of running away her dog went to the rug and lay down on his side whilst she put the ear drops in, neither of us said a word, gave a command or anything, we could not believe it!

That dog just knew that she was incapacitated, she thought it might have just been me being there, but I told her I wasn't
that good! :-D
In the evening he did the same and continued all the way through the treatment, I've never seen a dog do that ever!