Is one allowed to be in an apartment with the door unlocked or opened with a maid or cleaning lady when few people walk by but there is a chance someone can walk in and does it make a difference if one is married or not? and does a two year old child help the situation and if not at what age does a child help the situation?
"Pesach Posuach Lireshus Horabim", an open door, is more than just a literal open door. It is the idea that the house is theoretically open to the public, so an uninvited guest/passerby could theoretically walk in. So if the door is open, but no one could possibly get in uninvited (e.g. there is a gate around the house), an open door would not help at all. (see here). That's why the heter only works during the day. And that is why there may be situations where the door does not have to be physically open.
Later on, he writes:
It is disputed among the Poskim as to whether the heter of a Pesach Posuach (an open door) applies in the case of a Libo Gas Boh, i.e. with an individual with whom there is a warm and cordial relationship. In practice, one may be lenient when necessary; however, the door should literally be left open. (some Poskim [hold] that a closed but unlocked door constitutes a Pesach Posuach. One may generally rely on that opinion. However, in this case where the Poskim dispute as to whether a Pesach Posuach works at all to prevent Yichud with a Libo Gas Boh, one should definitely be stringent and leave the door literally open.)
There is an idea in the Laws of Yichud that a persons wife guards him from immoral behavior, provided that she is close by. Therefore, "if a man is at home alone and his wife is at work, and a female housekeeper arrives to clean, then he should leave the door literally open, thereby creating a Pesach Posuach. If his wife is in the vicinity and she is expected home shortly, then if she has the key, the door may be closed. If she doesn't have the key, the door may be closed but left unlocked."
Here he explains that children function as shomrim to permit Yichud from the ages of 6 to 9, when they are old enough to know what's going on, and young enough to be immune from participation.
A little later on he says, "A child is an effective shomer for allowing the Yichud of a man with a prutzah or a non-Jewish woman. Therefore, a man may be alone in the house with a non-Jewish cleaning lady in the presence of a child shomer."
In Footnote 48 he brings opinions who explain that even observant Jews may still be considered Prutzim when it comes to the laws of Yichud, if they meet the criteria:
Toras HaYichud 3:2:4 writes that men who know of the prohibition of arayos and tznius and yet who still watch television, read unsuitable material and visit movie theaters, etc., are considered prutzim. See also Shevet Halevi Vol. 5:202:1. Rabbi Shmuel Neiman in his book 9 to 5 — A Guide to Modest Conduct for Today's Workplace, writes (p. 39), "It cannot be stressed enough that the term prutzim also refers to people who are otherwise shomrei Torah u'mitzvos, but are not careful in matters relating to kraivah l'arayos. They may be regularly exposed to immodesty through the media, or may often be in the presence of immoral individuals through their everyday social interactions....(p.34) meaning that they are exposed to immodesty through television, movies, the Internet, in publications and the like. An individual involved in such activities is labeled a parutz. This is not limited to visual images; someone who is exposed to any form of indecent activity, such as chat rooms on the Internet, is considered a parutz. Such forms of recreation are a breach of morality."
However, it seems that doing what needs to be done to prevent Yichud with a housekeeper is also sufficient if the man is a "Parutz" (I may have missed some aspects though).
Actually you have number of question here. Let's start one by one.
- If someone can enter the apartment without knocking it allows ihud.
- For a married man if his wife with him she saves him from ihud, if she is not - there is no difference between married and non-married.
- A child from 6 years saves from ihud.