Automating your home
Now that we have our central server running and you can use it to control & monitor your home from a single interface, we can actually define some behaviors inside the server in order to create some automation within your smart home.
As an example, we are going to automatically switch on the lamp when motion is detected by the sensor. You can imagine the scenario in which the appliance control module is connected to a lamp in your hallway and that you want it to automatically switch on whenever a movement is detected by the motion sensor.
For that, here is the code you need to add into the server code:
setInterval(function() { // Check sensor request("http://" + motionSensorPi + "/digital/" + motionSensorPin, function (error, response, body) { // If motion was detected if (body.return_value == true) { request("http://" + lampPi + "/digital/" + lampPin + '/1'); } else if { request("http://" + lampPi + "/digital/" ...