The smart home contains a network that connects home elements like sensors, HVAC (heating, ventilation, and air conditioning), appliances and thermostat. In our previous work, we proposed an approach that used web services to remotely interact with smart home elements in a smart grid environment. These interactions include adjusting the temperature or reading energy consumption. We assumed a smart home with a wireless sensor network based on Zigbee. There was a central computer that could access all home elements. Business Process Execution Language (BPEL) was used to implement the web service on central computer. In this paper, we enhance the system by including new features. The algorithm to sell energy back to the grid has been further developed. Furthermore, a function to optimize energy using dynamic programming is added to the system. The performance and advantage of the communications between user and home elements via web services are demonstrated.