Imaam An-Nawawee said it is preferable:
To say the Tasmiyah, increase in the remembrance of Allah and to greet the people.
1. Remember Allah when entering:
When a man enters his house and mentions the Name of Allah while entering and while eating Shaytan says (to the other Shayaateen), 'There is no abode for you and no food'.
2. Suplicate when entering:
O Allah, I ask You for the best of entering and the best of leaving. In the Name of Allah we enter, and in the Name of Allah we leave, and in our Lord, we place our trust.... and then to greet its inhabitants (i.e. family).
By this, the person is consciously seeking to put his reliance on Allah when entering and leaving the house. This is also means to create a permanent bond with Allah.
3. Use a Siwaak:
When the Prophet (PBUH) entered his home, he began by using Siwaak.
4. Say the Tasleem:
"...When you enter the houses, greet one another with a greeting from Allah, blessed and good..."
'Greeting from Allah' means to say Tasleem.
5. Leave with the following supplication:
In the Name of Allah, I place my trust in Allah, and there is no might or power except with Allah.