In Germany it's literally illegal to sleep with a gun under your pillow as you are violating gun storage laws. This already makes your claim to self defense very murky. Because why are you breaking the law in the first place?
It could be argued you intended in advance to shoot whoever entered your home which would then constitute murder.
§ 34 StGB Justifiable Emergency.
Anyone who, in the face of an imminent and unavoidable danger to life, physical integrity, liberty, honor, property, or another legally protected interest, commits an act to avert the danger from themselves or another person does not act unlawfully if, upon weighing the conflicting interests—namely, the legally protected interests involved and the degree of danger threatening them—the protected interest substantially outweighs the interest that is impaired. This applies, however, only to the extent that the act is a reasonable means of averting the danger.
The right to personal property never substantially outweighs the interest of another person to stay alive. You must be (about to be) attacked to be able to resort to a gun.