Using the CP login session expiration for the frontend
What you want is this:

// Returns how many seconds are left in the current user session.
// (int) The seconds left in the session, or -1 if their session
// will expire when their HTTP session ends.
craft()-&gt;userSession-&gt;getAuthTimeout()


You can then combine this with a Javascript setTimeout when the page loads so you can trigger whatever messages you need.

Edit: You can use this in your template files:

{% set authTimeout = craft.session.getAuthTimeout() %}