When should you capitalize them, and when are they supposed to be written with a lower case letter? Before you can understand the rule, you need to understand the difference between a nickname and a term of endearment. Names don’t usually give the writer any trouble.
Let’s say your husband’s name is James, but you call him “Jim.” Jim is a nickname. It is a shortened form of James, and others besides you might call him Jim, as well. Maybe his mom calls him Jimmy. Jim, as a nickname, is always capitalized. But sometimes you might call your husband darling, honey, sweetheart, sugar lips, or some other word or phrase. These are terms of endearment, NOT nick names.
If your sister called, you might tell her that Jim brought you a bouquet of roses, but you wouldn’t tell her that “honey” brought them. No one else (you hope) calls your husband honey. Terms of endearment are NOT capitalized, unless of course, they are at the beginning of a sentence.
Titles are another issue.
Titles are caplitalized with put with a name. So you would write Judge Judy, or Rev. Martin Luther King, Jr., or Dr. Marcus Welby. But the words judge, reverend and doctor are not capitalized when they are not part of the name. Then they are just common, lower-case nouns.
Sir, madam and miss are not capitalized, unless they are with a name. It is Sir Walter Raleigh, but just plain yes, sir.
Hope that clears it up for you!