Close
0%
0%

Home Automation

with Raspberry PI, Arduino, ESP8266 and a bunch of Sensors

Similar projects worth following
The goal of this project is to automate everything in my apartment.
Since "everything" is a bit vague, I described the features in the details section more precise.

On the hardware side, I use an Raspberry PI 2 as main controller and an ESP8266 with sensors and actors in each room.

The diagram shows what hardware is in which room and how it communicates with the other devices.

The Raspberry PI hosts a webinterface (running on tomcat), which enables me to control the actors and see sensor values. It also acts as an mediator for the communication between the ESPs.


The basic concept is, that each room has a PIR Sensor and can recognize when I enter a room.
Based on this information it should for example turn on the lights in this room, and turn the lights in all other rooms off.

The ceiling lights are controlled via 433Mhz remote outlets, which get their commands from an 433MHz/Wifi repeater, which consists of an Arduino and an ESP8266 (see Update#2 for more details).
The ESPs communicate only over Wifi with the Raspberry PI, which receives the sensor values, decides which action to execute and then sends commands to each involved ESP.

I also plan to add voice control, but I want to realize this with Raspberry PI Zeros, so I will have to wait for them to be available.

The system is currently in an early stage of development, but when it is finished, it should meet the following requirements.

For some parts I already have working simplified prototypes (light control, presence awareness, voice control), but it's still a long way to go.

Room control

  • Lights
    • automatic on when entering the room, off when entering an other room
      • don't switch on when it's already brigth enough
    • voice controlled
    • manual control with wall switches or browser
  • Curtains
    • voice controlled
    • time controlled
    • manual with switch or browser
    • based on other (sensor-) events
  • Sensors
    • record temperature, brightness, presence, ...
    • start predefined actions based on sensor readings
    • visualize data
  • Front door
    • remote controlled via radio remote or smartphone

Infotainment

  • Music Playback
    • music follows me fully automatic from room to room
      • through the presence awareness of the system, it can send the music to the according devices
    • using Spotify
    • voice/browser controlled
  • Voice Control
    • control lights
    • control music playback
    • answer questions (google, wikipedia, wolfram alpha, etc. )
    • control other devices like TV, PC
    • multi language input
    • more to come
  • Alarm clock
    • turn on lights
    • read news and weather
    • play music

Misc

  • Presence awareness
    • System knows whether I'm at home or not
      • To get this knowledge, my smartphone is regularly pinged. When it's not answering, the chance is high that I'm not there
      • trigger actions when I'm not at home (eg. turn off all lights)
    • System knows in which room I am
      • (Voice-) commands can be set into context with the current room
    • As currently planned, the system is limited to one person, so it has to know if more persons are present and deactivate some features if necessary
  • Multi language support
    • The system should be able to understand commands in different languages
    • It should be simple to switch the system language

  • 1 × Raspberry PI 2 Webinterface and main controller
  • 5 × ESP 8266 send the sensor values the the raspi
  • 5 × PIR Sensor hc-sr501
  • 5 × Temperature Sensor DS18B20
  • 5 × Light Sensor Photoresistor
  • 1 × Arduino control the remote outlets
  • 1 × 433MHz Transceiver STX882 and SRX887
  • 3 × 433 MHz Outlet

  • Update#5: Infotainment

    M@lte10/17/2016 at 19:52 0 comments

    My Home Automation is now enriched by an audio setup, capable of streaming a single source of music into all rooms. It is also able to activate the music based on my presence in the room.
    Read more here: https://hackaday.io/project/16411-multiroom-music-streaming

  • Update#4: XML Configuration and progress overview

    M@lte05/29/2016 at 20:22 0 comments

    After the last hardware updates, it is now time to talk about the software again.
    I the first update, I mentioned room handlers, which were individually programmed to fit each room. To make my system more flexible, I dropped this approach and switched to a more versatile solution.

    The new implementation is based on an XML configuration file, in which I can specify actions that are performed based on events (like a detected motion or the press of a button, called "command" in the XML file) and conditions (e.g. brightness or state of the ceiling light). In each request, there can also be a "value" parameter, which can be checked, too.
    I also added the option to define macros for larger actions, which are used by different other actions. The "save" tag directs the server to save the event as specified by the given parameters or without changes, if no parameters were given.

    The current progress of my project is illustrated by the configuration file

    • Bedroom
      • Command for switching the Lights
        • the "get" tag triggers a HTTP GET request to the given URL (the URL of the ESP)
      • Command for moving the curtains
        • This uses a macro to open the curtains when closed and vice versa
      • Motion Detection
        • when a motion is detected, I am not already in this room and the brightness is below a threshold, the light gets turned on and in all other rooms (currently only my office) it gets turned off
        • there is also a "fallback mode", which is used to prevent the system to turn off the lights when only one of multiple persons is entering another room. Thus this mode is only activated if there are more people than me in my apartment
    • Office
      • Command for switching the Lights
      • Motion Detection (same as in bedroom)
    • Corridor
      • If the arduino receives a command from my radio remote, it will open the front door
      • The corridor contains the radio bridge, so it has some special tasks, which are not physically related to the corridor (called "radio data" in the xml file)
        • When the wall switch in the bedroom gets pressed up, the curtains shall be toggled
        • If it gets pressed down, the lights will be toggled, but because I want this to be as fast as possible, this is hardcoded into the software of the corridor arduino

    <?xml version="1.0" encoding="UTF-8"?>
    <hub>
      <commands>
        <!-- living room -->
        <command roomID="3" type="rgb">
          <action>
            <callHandler class="rgbHandler" />
          </action>
        </command>
        <!-- bedroom -->
        <command roomID="2" type="light">
          <action>
            <conditions>
              <value>1</value>
            </conditions>
            <get url="http://192.168.178.47/?c=A" />
            <save />
          </action>
          <action>
            <conditions>
              <value>0</value>
            </conditions>
            <get url="http://192.168.178.47/?c=a" />
            <save />
          </action>
        </command>
        <command roomID="2" type="curtains">
          <action>
            <conditions>
              <value>O</value>
            </conditions>
            <get url="http://192.168.178.50/?c=O" />
            <save />
          </action>
          <action>
            <conditions>
              <value>C</value>
            </conditions>
            <get url="http://192.168.178.50/?c=C" />
            <save />
          </action>
          <action>
            <conditions>
              <value />
            </conditions>
            <callMacro name="toggleCurtainsBedroom" />
          </action>
        </command>
        <command roomID="2" type="MotionDetected">
          <action>
            <conditions>
              <stateNotEquals roomID="0" type="currentRoom" value="2" />
              <state roomID="0" type="fallbackMode" value="0" />
              <stateLessInt roomID="2" type="brightness" value="500" />
            </conditions>
            <callCommand roomID...
    Read more »

  • ​Update#3: Presence Awareness and Sensors

    M@lte03/15/2016 at 20:49 0 comments

    Because my first idea for this project was the presence controlled light, it is time to implement this feature.

    I have several rooms to integrate, so I wanted a cheap solution. Simple PIR Sensors are cheap, but they can't detect the presence of a person, just the movements. This makes it a good choice for hallways, but won't work for other rooms, where you don't move significantly for some time.

    To bypass this problem, I will place one sensor in each room, so that a sensor will trigger, when I enter a room. Consequently, the system will know in which room I am, on the basis of the last triggered sensor. When the current room is changed, events like switching on/off lights are fired.

    Because the sensors need to observe the doors for this, I designed a simple mount for them and screwed them to the door frame. Currently only my office has this mount, but the other rooms will follow.

    I also want to have some other sensors in all rooms (currently light and temperature), so I attached them to the PIR mount.

    As light sensor I use a photoresistor combined with an 1M Ohm resistor, working as a light dependent voltage divider. This voltage is read by the ESP8266, so it needs to be between 0 and 1 Volts, which is the reason for the 1M resistor. The temperature sensor is a ds18b20, which can be addressed via the 1-Wire protocol.

    All data is saved in a central database and be available for me to generate nice diagrams. The values of the light sensors are also used to determine whether it is necessary to turn on the lights.

    This prevents the system from wasting energy.

    Each Sensorboard will get its own ESP8266, which I program with nodemcu.

    I expect that I will have to change the programs on them quite often, so the standard upload method via a USB Serial Adapter would not be very practical.

    To address this discomfort, I made a simple combined http and telnet server, which adds a telnet backdoor to the single nodemcu server. With this, I am able to connect to the nodemcu shell via putty and upload code with the luatool. The code for this server is available on github: https://github.com/Malte-D/nodemcu-http-telnet

    I also integrated my remote controlled curtains in my bedroom (see link on the left), by connecting an ESP to it. The ESP is also connected to the sensors mentioned above.

    As mentioned in the previous update, the ceiling light is controlled by a modified remote controlled outlet. I removed the power plug and attached it directly to the lamp.

    Here is an image of the original outlet:

    The commands are sent by the raspberry pi through the corridor arduino. To replace the wall switch, I used an of the shelve 433Mhz switch, which I attached to the wall where the old switch was.

    It uses a different protocol than the remote outlets, but this is no problem, because the arduino can receive the commands and forward them to the outlet.

  • Update#2: ​Corridor

    M@lte01/17/2016 at 17:55 0 comments

    Before I started this project, I already had an Arduino in my corridor, which controlled some LEDs based on a PIR sensor.

    So the next step was to add features to it and integrate it into my home automation.

    First, here is an image of the current assembly, which is housed in a commode in my corridor.


    The wires go to two PIR sensors, one servo motor and one led strip. With this, the Arduino is able to detect movement and light up the led strip. For the PIR sensors, I made some nice small mounts out of aluminium and placed them on top of the commode.

    The Arduino also sends movement events over serial to the ESP, which logs everything to the central server on the Raspberry PI.

    But the main feature is, that the assembly can receive commands over 433MHz from wall switch remotes and forward them to the remote outlets attached to the ceiling lights in all rooms (currently it's just in my bedroom). So it is acting as a bridge between different 433MHz protocols. The ESP can also receive commands over WiFi and get the Arduino to send 433MHz commands, so I can also control the lights from every device connected to my network. Besides that, the arduino can forward received 433MHz commands to the Raspberry PI, to trigger custom events or commands.

    Another feature is the servo, which can trigger the button for the release buzzer for my front door.


    This enables me to open the front door with my smartphone or a 433MHz remote. When using the remote, the Arduino asks the Raspberry PI, whether it is allowed to open the door before pressing the button. Currently, the Raspberry PI never prohibits the opening, but I can easily add logic to it.
    Because I think I am not allowed to alter the interphone, I had to realise my plans with the servo. I also thought that it would be a good idea, to be able to easily remove my addon, so I made a custom servo mount for it. To match the style of the big white box, I will also paint it white soon.

  • Update#1: Server Application

    M@lte12/28/2015 at 21:22 0 comments

    While waiting for the parts from china to arrive, I started to build the main software for my raspberry pi. I wanted to write it in Java, so I started by using the bundled http server com.sun.net.httpserver.HttpServer. With this, it is really simple to get a simple server up and running, but for my needs it was not stable enough. So I moved on to apache tomcat, combined with an apache derby database. The application is split into four parts. One part are the servlets, which allow the program to answer requests from other devices. These requests can be:

    • data to be stored as an event in the database (e.g. a PIR detected some motion)
    • a command to perform some action (e.g. turn on lights in room X)
    • a request to get some data (current status of the lights in room X)

    Each request contains a room id, a command/event type (e.g. light, motion, ...) and an optional value.

    This leads to the next part, the database. As mentioned above, it is implemented by using apache derby. Each event type is stored in its own table, combined with the room id of the room it occurred in and a timestamp. To deliver the requested data, the newest entry with matching room id in the corresponding table is selected.

    Because the database keeps every event with its timestamp, it is possible to visualize the data over a specific time period (e.g. a diagram of the temperature in a room), but this is not implemented yet.

    The third important part is the logic to perform actions. Because every room has different actors, each gets its own room handler. Each handler implements a common interface, so the parameters from the command request can be passed to the corresponding handler. The actual commands are executed by sending http requests to the corresponding esp. This already works with my servo lightswitch.

    Because there are tasks, which are independent from server requests (e.g. ping my smartphone and trigger events when I leave/arrive), I added a class which runs parallel to the server, but in the same JVM. To achieve this, the class implements the ServletContextListener interface, so it starts and ends with the main app and it can share the same in memory database.

    As interface for me to this system, I made a simple webapp, which is also hosted on tomcat and is served as static content, so it is independent from the main war file.

View all 5 project logs

Enjoy this project?

Share      

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates