In addition to providing for a more reliable distribution infrastructure, the smart grid promises to give the end users better pricing and usage information. It is thus interesting for them to be ready to take advantage of features such as dynamic energy pricing and real-time choice of operators. In this work, we propose a system to monitor and control an office environment and to couple it with the smart grid. The idea is to schedule the operation of devices according to policies defined by the users, in order to minimize the cost of operation while leaving unaffected user comfort and productivity. The implementation of the system and its testing in a living lab environment show interesting economic savings of an average of about 35% and in some cases even overall energy savings in the order of 10% for a building equipped with renewable generation plants, and economic and energy savings of 20% and 10%, respectively, for a building without local renewable installations.