Ishto Bair-Permitting Yichud on the grounds that one’s wife is in the city:
Some Poskim rule that having one’s wife in the same city never permits a state of Yichud irrelevant of circumstance, and only when one’s wife is in the room does it permit Yichud with another woman. Other Poskim, however, rule that a husband may be in a state of Yichud with a woman, even if his wife is not in the room, so long as she is in the same city. This, however, only applies if he is in his house, or office which his wife often visits, and one’s wife is able to arrive home at any moment, even if she does not have a key. If, however, one’s wife is away at work, or is far away from home, or one is not at home or a known area, then Yichud if forbidden even if his wife in the same city, even according to the lenient opinion. Practically, one may be lenient like the second opinion in a case of Rabbinical Yichud, such as one who is alone with two women.
Wife has a key and may arrive at any moment: If one’s wife has a key to one’s house or office [or the door is unlocked] and is liable to arrive at any moment, it is permitted according to all for the husband to be in Yichud with a woman. If she does not have a key, then it falls under the dispute mentioned above.
If one’s wife is in the city and can arrive home, or to one’s work, at any moment, then if she has a key to the house or the door is left unlocked, it is permitted for the husband to be in a state of Yichud with another woman. If the wife does not have a key to the house, and the door is locked, then if one’s wife can arrive home, or to one’s work, at any moment, the husband can be lenient regarding Rabbinical Yichud in the home or workplace. If one’s wife is not expected to arrive in the near future, all forms of Yichud are forbidden.
One’s wife left the house momentarily [i.e. went to the neighbors; throw garbage] and there is a woman at home [i.e. maid, baby sitter, relative, friend] may the husband remain home with the woman?
If she is expected to come home at any moment, it is permitted to do so if the wife has a key or the door is left unlocked.
One’s wife left the home and will be gone for quite some time [i.e. went to work; shopping; school] and there is a woman at home [i.e. maid, baby sitter, relative, friend] may the husband remain home with the woman?
One’s wife left the home for work; shopping; school and is expected to return home at any moment and there is a woman at home [i.e. maid, baby sitter, relative, friend] may the husband remain home with the woman?
If one’s wife has a key, or the door is left unlocked, then it is permitted to do so according to all opinions. One is not to leave the door locked if one’s wife does not have a key, as according to some Poskim, Yichud is forbidden in this situation.
 See Dvar Halacha 6:2-3
 Bnei Chayil [of Kneses Hagedola]; Maaseh Rokeiach on Rambam 2:4; Implication of Meiri Kiddushin 80b; Ezer Mekodesh 22:5 “She must be actually with him, and being in same city does not suffice”; Maharshan 4:148; Eretz Tzevi 22:29; Igros Moshe E.H. 4:65-6
 Beis Shmuel 22:22 based on Michaber 22:20 and Kesef Mishneh Talmud Torah 2:4 [however see Chelkas Mechokeik 22:21 who learns the Michaber to be referring to Giruiy and not Yichud]; Perisha Y.D. 245:20; Aruch Hashulchan 22:25; Imrei Yosher 2:9
 The reason: As his wife guards him from sin, as he fears that his wife may walk in on him at any moment. [Beis Shmuel ibid; Perisha ibid]
 See Dvar Halacha 6:4 footnote 4 for the proofs behind these conditions even according to the Beis Shmuel; Nitei Gavriel 41:2-3 based on Imrei Yosher ibid
 Doveiv Meishatim 5; Dvar Halacha 6:3; Nitei Gavriel 41:1
 Dvar Halacha 6:4 footnote 4
 Nitei Gavriel 41:1; Minchas Ish 9:3
 Even if she does not have a key, it helps according to the lenient opinion, as he will need to open the door for her as soon as she knocks. [Dvar Halacha 6 footnote 4]