After execution the investment and configuring the automation we control energy sources in buildings or within microgrids and manage energy consumption. We constantly analyze data on electricity and heat generation by energy sources installed in buildings or within microgrid as well as data on energy consumption for heating, preparation of domestic hot water and cooling. Ongoing data analysis enables balancing the demand for energy in buildings with its supply as well as optimization of its consumption. The optimization criterion is to reduce the cost of energy supply while maintaining the thermal comfort of the building’s users. For this purpose we also propose the use of dynamic electricity tariffs which enable the use of low electricity prices during off-peak hours.