# Home Automation System Based on Intelligent Transducer Enablers
## 6 HASITE: API and User Interface  
HASITE implements an API that allows third-party applications to access the main features of the system. For the examples below, it is assumed that the API of HASITE is listening on the IP address 172.16.0.2 and Port 5050. The major API endpoints allow remote users to:  
* List all of the registered ITNs. This is accomplished by issuing a GET request to \"[[http://172.16.0.2](http://172.16.0.2)]([http://172.16.0.2](http://172.16.0.2)): 5050/transducers\" (the response is represented on the left in Figure 4). * Access the basic information of an ITN, like its IP or the associated ITEs. With the \"id\" field obtained from the previous API response (i.e., the light regulator, represented with an \"id\" of 8), all of the ITN information can be obtained by issuing a GET request to \"[[http://172.16.0.2](http://172.16.0.2)]([http://172.16.0.2](http://172.16.0.2)): 5050/transducers/8\" (this information conforms the ITE, as shown on the right of Figure 4). * Execute actions like reading a sensor value or changing the state of an actuator. Again, from the previous response, we can obtain the actual intensity of the light regulator transducer by issuing a GET request to \"[[http://172.16.0.2:5050/transducers/8/actuators/0](http://172.16.0.2:5050/transducers/8/actuators/0)]([http://172.16.0.2:5050/transducers/8/actuators/0](http://172.16.0.2:5050/transducers/8/actuators/0))\", obtaining as a result a JSON response \"[\"ActuatorValue\": 50]\". Note that the \"actuators/0\" part is obtained from the field \"uri\" of the ITE. As is explained in Section 5.1, this transducer values range from zero to 100, so it is easy to understand that the regulator controlled by this ITN is now sending half of the power to any light emitter connected to it. To change the value of the actuator, and using again the information obtained from the ITE, it is only necessary to issue a PUT request to \"[[http://172.16.0.2:5050/transducers/8/actuators/0](http://172.16.0.2:5050/transducers/8/actuators/0)]([http://172.16.0.2:5050/transducers/8/actuators/0](http://172.16.0.2:5050/transducers/8/actuators/0))\" with a JSON message that indicates the new value: \"[ \"ActuatorValue\": 20 ]\". If the request is processed successfully, the response will be \"[\"ActuatorSet\": 1]\". In any other case, the response will be \"[\"ActuatorSet\": 0]\", indicating that it was not possible to change the actuator state. The API and the persistence of the different system elements were built on top of the Django framework [44], which is a free and open source web application framework written in Python. It consists of an Object-Relational Mapper (ORM) (that mediates between data models and a relational database), a system for processing Hypertext Transfer Protocol (HTTP) requests with a web template system and a regular-expression-based Uniform Resource Locator (URL) dispatcher. The whole software solution developed is light enough to run on a Raspberry Pi 2. The ORM is used to persist the ITEs, the user and system configuration and the registered ITNs data. The system also supports logging data samples associated with a particular ITN. The access to the API endpoints is secured with HTTP Basic Authentication, but more complex and secure mechanisms can be used. For instance, the API of the system evaluated in Section 8 is based on Django serialization capabilities, which support advanced authentication protocols like OAuth 2.0. In order to illustrate better the API capability for developing graphic user interfaces, a hybrid smartphone application for Android and iOS was implemented. Using the smartphone Bluetooth interface, an indoor location system was developed. The application, as can be seen in Figure 8, allows us to create relationships between BLE beacons and ITNs. BLE beacons are Bluetooth Low Energy devices that periodically emit a message with some parameters that allow for unique identification. Smartphones can read these messages and use the Received Signal Strength Indicator (RSSI) to estimate the distance from the beacons.