Home and building automation system is proposed not only for improving user comfort and safety but also for energy management of a house and building. However, conventional home and building automation system may not know detailed information of appliances and appliance states in a house and building so that some advanced services might not be able to provide. In this study, we integrate nonintrusive load monitoring (NILM) meters with a gateway so that the gateway can understand the power consumptions of appliances in a house and building and provide detailed information of appliances and their states. We design and implement the proposed gateway based on Open Service Gateway Initiative (OSGi) framework with the integration of NILM smart meters, sensors and actuators. Based on this infrastructure, we then present a data mining and event association algorithm to establish the relationships between appliances, sensors and actuators. The association and relationship information can be used to identify appropriate smart home and building services to specific houses and buildings, to locate appliances in a particular room and area, and to help an NILM system to collect the signatures of unknown appliances. Our prototype system demonstrates that the functionalities of a gateway and its services for a smart home and building can be significantly improved by integrating NILM meters.