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, ...

Get Building Smart Homes with Raspberry Pi Zero now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.