Intelligent management of energy consumption is one of the key issues for future energy distribution systems, smart buildings, and consumer appliances. The problem can be tackled both from the point of view of the utility provider, with the intelligence embedded in the smart grid, or from the point of view of the consumer, thanks to suitable local energy management systems (EMS). Conserving energy, however, should respect the user requirements regarding the desired state of the environment, therefore an EMS should constantly and intelligently find the balance between user requirements and energy saving. The paper proposes a solution to this problem, based on explicit high-level modeling of user intentions and automatic control of device states through the solution and optimization of a constrained Boolean satisfiability problem. The proposed approach has been integrated into a smart environment framework, and promising preliminary results are reported.