In this paper we propose a unified utility deviation-risk model which covers both utility maximization and mean-variance analysis as special cases. We derive the time-consistent Hamilton--Jacobi--Bellman (HJB) equation for the equilibrium value function and significantly reduce the number of state variables, which makes the HJB equation derived in this paper much easier to solve than the extended HJB equation in the literature. We illustrate the usefulness of the time-consistent HJB equation with several examples which recover the known results in the literature and go beyond, including a mean-variance model with stochastic volatility dependent risk aversion, a utility deviation-risk model with state dependent risk aversion and control constraint, and a constrained portfolio selection model. The numerical and statistical tests show that the utility and deviation-risk have a significant impact on the equilibrium control strategy and the distribution of the terminal wealth.