Furthermore, ZiWi makes use of the fog computing paradigm to provide connectivity between the user and the different home appliances, not only allowing the user to control them, but also offering automatisms to simplify tasks. This is achieved thanks to ZiWi's distributed nature: the home controller hardware is kept at the bare minimum for executing real-time tasks, delegating the processing of the data and the decisions on non real-time automated tasks to remote cloud servers. It is important to note that ZiWi proposes a distributed approach instead of a decentralized solution [29]. Both terms have been used as synonyms in some scenarios, so they can be confusing. In the case of decentralized systems, they consist of a network of stars where every central element of each star processes the collected information locally. In contrast, in a distributed system, the different components are located on networked computers that communicate and coordinate to achieve a common goal. This is what is proposed in fog computing: local gateways can communicate with each other and with the cloud to achieve a common goal [4; 30]. What can be confusing is that many decentralized systems are also distributed, since they process some information locally but also cooperate with other systems to perform certain actions (e.g., this is the case of some peer-to-peer or blockchain-based systems [31]), so a distributed system can also be decentralized in some applications. In the case of ZiWi's architecture, the term distributed implies that the computational and storage resources are distributed throughout the network in strategic locations to allow the system to respond faster and also to decrease the computational load of the cloud. This is performed by moving part of the computational power towards the edge by means of fog gateways, which perform certain simple tasks that require a fast response. This architecture also allows ZiWi to remain inexpensive in comparison to many commercial systems, which usually make use of complex and pricey home controllers. The designed architecture, together with the use of an open messaging protocol like Message Queuing Telemetry Transport (MQTT) to communicate nodes, make ZiWi more flexible than traditional home automation solutions, whose manufacturers are often reluctant to offer connectivity with third-party systems. Thus, such an openness and the use of widely known technologies provide robustness and ease of construction and deployment, being straightforward for integrating new elements on the ZiWi IoT ecosystem and allowing the user to make use of a wide range of resources to act on devices to obtain information on them or to automate certain events. This article includes three main contributions aimed at creating a cost-effective and duplicable fog computing-based HAS. First, in order to establish the basics, it presents a detailed review of the state-of-the-art of the main and the latest technologies and services for home automation systems. Second, it thoroughly explains the design, implementation and practical evaluation of a fog computing-based HAS that is accessible, easy to configure, low cost and scalable in terms of protocols and technologies. Third, the article describes in detail an HAS that, thanks to the use of open-source software and Commercial Off-The-Shelf (COTS) parts, is easy to build, so it is straightforward for other researchers to replicate the system and the performance tests presented in Section 5. The rest of this paper is structured as follows. Section 2 describes and analyzes the state-of-the-art of home automation technologies and the latest commercial and academic HAS. Section 3 includes an overview of ZiWi's architecture and its main components. Section 4 details the hardware and software used to implement the different system devices. Section 5 presents the results of different tests that evaluate the performance of ZiWi in real scenarios. Finally, Section 6 is devoted to the conclusions.