My Home Control System – Devices, tasks and communication

After talking about the basics of a server-less system, it is time to show the architecture of my system. To see the code used send the  UDP broadcast, read this post. For the code for the TCP communication, read this post.

At the moment I have the following devices in the system:

Some of these device do not only send out frequently their data and status but can control other devices as well.

  • The front yard security system is controlling a CCTV still camera and is sending information about environmental light values to the back security system
  • The back yard security system is controlling a second light in the back yard if a motion was detected

All of the devices send out status messages as JSON objects that are all build with the same structure. Example:

There are three values inside the status messages that are the same for all devices

  • de is the device identifier
  • bo is a flag that is showing if the device has rebooted since the last status message
  • zlight is the device identifier for another light device that would be switched on in case of a motion detection
  • zcam is the device identifier of a camera that should be triggered
  • zsec is the device identifier for another security device that should receive the light automation information
  • zloc is a string that shows where this device is mounted

The code examples how to send and receive UDP broadcasts are in this post.

All device can receive commands over TCP. The commands are all simple text strings. I wrote about the code to send and receive the commands over TCP in my other post.

As each device has different capabilities, they have different commands, but all devices are controllable over the following generic commands:

  • “d” toggles the debug output of the device
  • “r” deletes stored WiFi credentials and reboots the device into Access Point mode with a web interface to setup the network connection
  • “x” restarts the device
  • y=YYYY,MM,DD,HH,mm,ss” sets the date and time of the devices internal clock

The tasks of the different devices and the links between them will be explained on the next pages, starting with the Solar Panel Monitor.

 

Solar panel monitoringArduino Yun

When I got my solar panels, I looked for a possibility to monitor the production of the panels and in addition monitor the electric consumption of my house. Details how the system looks like are in the post Solar Panel Monitoring

The Arduino Yun was my entry into the Arduino world. As the first Arduino with integrated WiFi (and LAN) capabilities it was advanced and quite expensive at the time it appeared on the market.

Basically it is an Arduino Yun with an second on board Linux system (Linino OS) that handles the communication over WiFi or LAN. It gives you the real time processing combined with the connectivity and flexibility of a Linux system. This Arduino Yun is now running since 4 years 24 hours a day with no problems. I am actually surprised about the reliability of the Arduino Yun.

The data collected from both the solar panel and the house consumption are stored on the SD card of the Arduino Yun and sent every minute as an UDP broadcast over the local network.

The data is send as an JSON object and has the following format:

  • “de” is the device identifier. For this device I chose “spm”
  • “s” is the average electric wattage produced by the solar panels in the last minute
  • “c” is the average electric wattage consumption of the whole house.

Any device that needs information from the solar panel monitor can receive this data by listening to the UDP broadcasts. For example I wrote a small Android application for my old tablet to view the stream from my (real) CCTV camera. This Android application is listening as well to the UDP broadcasts and is displaying the current production and consumption values on top of the CCTV view.

The blue field is the house consumption, the yellow field is the solar production and the red field is the amount is how much energy we import. If we produce more energy than we consume, the red field turns green and shows me how much energy I send back into the public electric net.

Another example is my Android application that allows me to control all my devices. It has a widget that shows me the current energy status. The data is coming as well from the UDP broadcasts of the Solar Panel Monitor.

The Solar Panel Monitor has no TCP command interface like the other devices. The reason is that

  • it was the first device I developed for my Home Control Systems and I didn’t know how complex the whole system would be after 3 years
  • it is not an actuator, so there is not really the need for a command interface

Instead there is an web interface (HTTP GET) that allows other devices to read stored data from the device. This interface is a PHP script that is running on the web server of the Arduino Yun. The call looks like:

Example:

queries the data from February 25th, 2018 at 14:54 o’clock. The return value would look like

where

  • id is the database entry index
  • d is the date and time
  • s is the solar panel production in Watt
  • c is the house consumption in Watt
  • l would be the light in Lux, but I never added a light sensor to the device, so this value is always 0

On the next page I will show how the front yard security device talks to the CCTV still camera and the back yard security system.

 

Front yard security device – ESP8266

The front yard security device was the third device I build. As in my remote aircon control device I decided to use the ESP8266 module. And same as in the aircon control device it was the Adafruit HUZZAH ESP8266 Breakout. For the security devices I created a PCB that holds all the parts on it to reduce the wire chaos in the box. But still it looks a little bit unprofessional. To keep the cost low, I used a food box as casing. The PIR sensor is mounted inside a cream cheese box that I painted and sealed with silicon. The front yard light is not shown in this picture. It is located at a different place.

The front yard security device is equipped with

  • PIR motion detector
  • LDR to get the environment light level
  • Relay to switch on the front yard light
  • Siren to give an acoustic alarm if an intruder is detected

I programmed the security device that it will work even if my local WiFi network is down. The device is programmed with the start and end time when the acoustic alarm should be activated, it uses the LDR to decide whether on a motion detection the front yard lights should be switched on.

But if the local WiFi is working (which it is most of the time) then the security device is sending its status as UDP broadcast once a minute. In addition, if the alarm is active and an intruder is detected, it sends an alarm message as UDP broadcast and it sends a command to my “fake” CCTV camera to take a picture.

If the measurement of the LDR value shows that it is night time, this information is sent to the backyard security device (which has no light sensor) to let it know that it should switch on the backyard lights if required.

The status message that is sent out every minute is a JSON object:

where

  • de is the device identifier. Here it is “sf1” for security front #1
  • al is indicating if there is an alarm because the motion detection was triggered
  • ao is indicating if the the alarm is activated
  • au is indicating if the alarm activation is automatic based on the programmed on and off times
  • an is the hour when the alarm is activated
  • af is the hour when the alarm is deactivated
  • lo is indicating if the lights will be switched on if there is a motion detection
  • zlight is the device identifier for another light device that would be switched on in case of a motion detection
  • zcam is the device identifier of a camera that should be triggered
  • zsec is the device identifier for another security device that should receive the light automation information
  • zloc is a string that shows where this device is mounted

In case the alarm is active and a motion detection happened, the same status message is sent out immediately with “al”:1. Then other devices, like my Android tablet, can play an alarm sound as well.

The front security device accepts the following commands over TCP

  • “a=0” ==> Deactivate alarm manually
  • “a=1” ==> Active alarm manually
  • “a=2,aa,dd” ==> Enables automatic alarm activation at aa o’clock and deactivation at dd o’clock.
  • “a=3” ==> Disable automatic alarm activation
  • “a=4” ==> Enable automatic light control
  • “a=5” ==> Disable automatic light control
  • “s” ==> Request a short status message
  • “i” ==> Request a detailed status message
  • “p” ==> PANIC function, switches on all available lights and activates all available alarm buzzers. Sending the command a second time ends the alarms and switches off the lights.
  • “b” ==> Switches on the lights for 5 minutes
  • “d” ==> Toggles the debug output between enabled and disabled
  • “r” ==> Deletes stored WiFi credentials and reboots the device into Access Point mode with a web interface to setup the network connection
  • “y=YYYY,MM,DD,HH,mm,ss” ==> Sets the date and time of the devices internal clock
  • “x” ==> Restarts the device
  • “zloc=xxxxxxx” ==> Set location of the device, max length is 40 letters
  • “zlight=xxxxxxx” ==> Set device identifier for another light device that would be switched on in case of a motion detection, max length is 40 letters
  • “zcam=xxxxxxx” ==> Set device identifier for a camera that should be triggered
  • “zsec=xxxxxxx” ==> Set device identifier for another security device that should receive the light automation information

Next page is simplier, it is about how the CCTV still camera is activated.

 

CCTV still cameraESP8266

The CCTV still camera is a project where I converted a fake CCTV camera housing into a picture taking device based on a simple serial camera and an ESP8266. This device has no detection sensors integrated, instead it is triggered by the front security system. Of course it would have been possible to add a motion detection sensor here as well, but I wanted to keep the cost as low as possible.

As all other devices every minute a status message is sent over UDP broadcasting. The JSON object is

  • de is the device identifier. Here it is “cm1” for security camera #1
  • bo is a flag that is showing if the device has rebooted since the last status message
  • tm is the current time
  • pi is an indicator if a picture was taken. If the indicator is 0, then the last picture taken was already acknowledged by the system. If the indicator is 1, then there is a new picture available that was not yet viewed by any device on the system.
  • fi is only added if pi is 1 and contains the filename that was used to save the last picture.

The still camera device accepts the following commands over TCP

  • “t” ==> Triggers taking a picture
  • “d” ==> Toggles the debug output between enabled and disabled
  • “r” ==> Deletes stored WiFi credentials and reboots the device into Access Point mode with a web interface to setup the network connection
  • “y=YYYY,MM,DD,HH,mm,ss” ==> Sets the date and time of the devices internal clock
  • “x” ==> Restarts the device
  • “zloc=xxxxxxx” ==> Set location of the device, max length is 40 letters
  • “zlight=xxxxxxx” ==> Set device identifier for another light device that would be switched on in case of a motion detection, max length is 40 letters
  • “zcam=xxxxxxx” ==> Set device identifier for a camera that should be triggered
  • “zsec=xxxxxxx” ==> Set device identifier for another security device that should receive the light automation information
  • “z” ==> Format the internal file system

For details about this device read my other post.

And on the next page I write about the differences between the front yard security device and the security device in my backyard.

 

Back yard security device – ESP8266

The back yard security device is very similar to the front yard security. But I decided to leave the LDR sensor out, as the light situation in the front yard and in the back yard are very similar, so I could use the measurement from the front yard sensor to activate the automatic light switching. Instead I added a temperature and humidity sensor to the back yard device to get additional environmental information into the system.

The back yard security device is equipped with

  • PIR motion detector
  • DHT11 sensor to measure temperature and humidity
  • Relay to switch on the front yard light
  • Siren to give an acoustic alarm if an intruder is detected

Same as the front security device I programmed this security device that it will work even if my local WiFi network is down. The motion detection, the automation of the light and the alarm is working without any network connection.

If the network is up, then beside of sending out the status message every minute the device is controlling another remote controlled light in my backyard.

The status message that is sent out every minute is a JSON object:

The structure is again the same as it is on all the devices inside my system.

  • de is the device identifier. Here it is “sb1” for security back #1
  • al is indicating if there is an alarm because the motion detection was triggered
  • ao is indicating if the the alarm is activated
  • au is indicating if the alarm activation is automatic based on the programmed on and off times
  • an is the hour when the alarm is activated
  • af is the hour when the alarm is deactivated
  • lo is indicating if the lights will be switched on if there is a motion detection
  • te is the measured temperature
  • he is the measured humidity
  • zlight is the device identifier for another light device that would be switched on in case of a motion detection
  • zcam is the device identifier of a camera that should be triggered
  • zsec is the device identifier for another security device that should receive the light automation information
  • zloc is a string that shows where this device is mounted

In case the automatic light function is active and a motion detection happened, then a simple command is send to another device that is identified as zlight in the status.

The back security device accepts the following commands over TCP

  • “a=0” ==> Deactivate alarm manually
  • “a=1” ==> Active alarm manually
  • “a=2,aa,dd” ==> Enables automatic alarm activation at aa o’clock and deactivation at ddo’clock.
  • “a=3” ==> Disable automatic alarm activation
  • “a=4” ==> Enable automatic light control
  • “a=5” ==> Disable automatic light control
  • “s” ==> Request a short status message
  • “i” ==> Request a detailed status message
  • “p” ==> PANIC function, switches on all available lights and activates all available alarm buzzers. Sending the command a second time ends the alarms and switches off the lights.
  • “b” ==> Switches on the lights for 5 minutes
  • “d” ==> Toggles the debug output between enabled and disabled
  • “r” ==> Deletes stored WiFi credentials and reboots the device into Access Point mode with a web interface to setup the network connection
  • “y=YYYY,MM,DD,HH,mm,ss” ==> Sets the date and time of the devices internal clock
  • “x” ==> Restarts the device
  • “zloc=xxxxxxx” ==> Set location of the device, max length is 40 letters
  • “zlight=xxxxxxx” ==> Set device identifier for another light device that would be switched on in case of a motion detection, max length is 40 letters
  • “zcam=xxxxxxx” ==> Set device identifier for a camera that should be triggered
  • “zsec=xxxxxxx” ==> Set device identifier for another security device that should receive the light automation information

Now something which is quite complex from the hardware side, but easy to understand from the coding. My bedroom light switch and dimmer.

 

Bedroom light switch and dimmer – Arduino Uno WiFi

The idea to build a remote controllable and dimmable bed room light came up after several of cheap LED bulbs I used in my house died. Curios as I am, I disassembled the dead bulbs and found out that on all of them just one of the many LEDs mounted in them had died, while all the others were still working. So I decided to reuse the working LED’s and power them with a 12V PSU and some power transistors to make them dimmable. To control the whole thing I used an Arduino Uno WiFi that I won in a contest. The Arduino Uno WiFi is basically an Arduino Uno with an ESP8266 chip on the same board. The communication between the Uno and the ESP8266 is over a simple I2C interface. I still have to prepare a post about this project, it is very interesting what I found out while working on it.

Same as all of my devices a status message is send out over UDP broadcast every minute

where

  • de is the device identifier, here it is lb1 for Light Bedroom #1
  • bo is a flag that is showing if the device has rebooted since the last status message
  • br is the selected brightness for the light
  • di is a pre-defined value that is used to switch the lights to a comfortable dimmed brightness. This value is programmable from my Android application

The bedroom lights can be controlled over the following commands

  • “b=xxx” ==> Sets the brightness to the value xxx
  • “c=nn” ==> Command to set the brightness.
    • nn = 00 ==> Switch on or off the lights
    • nn = 01 ==> Switch lights to stored dim level brightness
    • nn = 02 ==> Brightness level -1
    • nn = 03 ==> Brightness level +1
    • nn = 04 ==> Brightness level -25
    • nn = 05 ==> Brightness level +25
    • nn = 06 ==> Brightness level +10
    • nn = 07 ==> Brightness level -10
    • nn = 08 ==> Set brightness to 226
    • nn = 09 ==> Set brightness to 225
    • nn = 10 ==> Set brightness to 224
    • nn = 11 ==> Set brightness to 223
  • “s” ==> Request a short status message
  • “d=xxx” ==> Sets the default dim level to the value xxx
  • “x” ==> Restart the device

In addition the bedroom light can be controlled by an old IR remote that I had left over from a cable TV receiver. But for all the details you have to wait until I found time to write the post about this project.

And now something many of you might have build already by themself. A ESP8266 and a relay to remote control my other back yard light.

 

Back yard light –  ESP8266

The back yard light control is a rather simple device compared to the others. It is just an ESP8266, a relay and the required power supply put together into a casing. There is no sensor attached, its only function is to receive commands to switch on or off the relay to control the second light in the back yard.

Even it has no sensors attached, it still sends out every minute a status message. This is required so that other devices can see that the back yard light device is online and that they know its IP address.

The simple JSON object status is

where

  • de is the device identifier, here it is ly1 for Light back Yard #1
  • lo is a flag that is showing if the lights are switched on or off

The command that this device accepts

  • “s” ==> Request a short status message
  • “i” ==> Request a detailed status message
  • “l” ==> Switch on or off the lights
  • “p” ==> PANIC function, switches on all available lights and activates all available alarm buzzers. Sending the command a second time ends the alarms and switches off the lights.
  • “b” ==> Switches on the lights for 5 minutes
  • “d” ==> Toggles the debug output between enabled and disabled
  • “r” ==> Deletes stored WiFi credentials and reboots the device into Access Point mode with a web interface to setup the network connection
  • “y=YYYY,MM,DD,HH,mm,ss” ==> Sets the date and time of the devices internal clock
  • “x” ==> Restarts the device
  • “zloc=xxxxxxx” ==> Set location of the device, max length is 40 letters
  • “zlight=xxxxxxx” ==> Set device identifier for another light device that would be switched on in case of a motion detection, max length is 40 letters
  • “zcam=xxxxxxx” ==> Set device identifier for a camera that should be triggered
  • “zsec=xxxxxxx” ==> Set device identifier for another security device that should receive the light automation information

And now it’s getting more complicated again, the AC remote control on the next page.

 

AC remote control – ESP8266

The AC remote control device was the second device I added to my system and the first time I used the ESP8266. On the hardware side it is a rather simple device, just an ESP8266, two IR diodes and the PSU. The challenge here was to learn the different IR commands of the aircons I own. Details can be found in this post.

The status message send over UDP broadcast

where

  • de is the device identifier, fd1 or ca1 or am1, depending on the aircon
  • po is the power status of the AC, on or off
  • mo is the mode of the AC, auto, cool, fan or dry
  • sp is the fan speed
  • te is the selected cooling temperature
  • co is the power consumption, a value read from the solar panel monitor
  • st is the status of the power cycle state machine
  • au indicates if the aircon is automatically controlled by the power consumption of the solar panels
  • ti is indicates if the timer is active or not
  • ot is the time the aircon is on when the timer is started
  • ts is the time when the automatic control of the aircon is switched off
  • bo is a flag if the device rebooted since the last status message
  • dt is a flag if the automatic control is active
  • tm is the current time of the device

The list of control commands is very long

  • “c=00” ==> Switch AC on or off
  • “c=10” ==> Switch AC to Mode Auto
  • “c=11” ==> Switch AC to Mode Cool
  • “c=12” ==> Switch AC to Mode Dry
  • “c=13” ==> Switch AC to Mode Fan
  • “c=20” ==> Switch AC to Fan High
  • “c=21” ==> Switch AC to Fan Medium
  • “c=22” ==> Switch AC to Fan Low
  • “c=23” ==> Switch AC to Fan Speed
  • “c=30” ==> Raise Temperature
  • “c=31” ==> Lower Temperature
  • “c=40” ==> Start Timer
  • “c=41” ==> Start Sweep
  • “c=42” ==> Start Turbo
  • “c=43” ==> Start Ionizer
  • “c=70” ==> Restart device
  • “c=71” ==> Initialize AC settings
  • “c=80” ==> Switch off secondary remote AC
  • “c=81” ==> Switch secondary remote AC into fan mode
  • “c=82” ==>Switch secondary remote AC into cool mode
  • “c=98” ==> Enable power consumption controlled AC on/off
  • “c=99” ==>Disable power consumption controlled AC on/off
  • “t=n” ==> Set timer on time in hours
  • “d” ==> Toggles the debug output between enabled and disabled
  • “i” ==> Request a detailed status message
  • “r” ==> Deletes stored WiFi credentials and reboots the device into Access Point mode with a web interface to setup the network connection
  • “s” ==> Request a short status message
  • “x” ==> Restarts the device
  • “y=YYYY,MM,DD,HH,mm,ss” ==> Sets the date and time of the devices internal clock

Something I wanted to integrate more deeply into my system is a real CCTV camera. Unfortunately the WiFi CCTV camera I bought is not following any standards, but on the next page you see that I could integrate it at least partly.

 

WiFi CCTV camera – only partly integrated

This device is a bought device. It is only partly integrated into the system. I managed to control the camera viewing position through my Android application that displays the camera view. Other than that, I record the streamed video with a Raspberry Pi and save the videos.

Next pages are empty (for now). I am working on a doorbell extension over WiFi based on the ESP8266, basics are working, but I am still not decided if I go for a microphone based solution or if I use a reed relay.

 

Doorbell extension – ESP8266

Coming soon

And sometime this year I hope that I can as well integrate my washing machine into my home control system. If I am successfull, it will be shown on the last page.

 

Washing machine monitor – ESP8266

Coming soon

 

Loading...
Facebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published. Required fields are marked *

Free Link Directory