In general, this is best achieved by using the Presence add-on.