crystal13
Posts: 67
Joined: Tue Jan 22, 2013 2:13 pm

Home automation with RPI for control wired "things"

Mon Sep 16, 2013 9:54 pm

Hi to all,

I start to build my home next April and I'm very interested to plan the project of electric wires so that I can use Raspberry Pi to control things of my home (lights of rooms, windows, anti-theft, etc...).

My initial idea of the architecture of my Home automation is this:

- I imagine that there is one point in the home where will arrive all electrical wires of the things of home (e.g. electrical wires of lights).

- Here, every electrical wire (and so, every light of the rooms) is controlled (turned on and turned off) by a relay.

- Everey relay is connected to RPI via his GPIO pins; so every relay is controlled by GPIO pins.

- On RPI lives a webserver, where an user can be connected (via mobile device) and so he can control the GPIO (and so every relay) status.

- The RPI is connected to an WI-FI router via LAN cable. So, every mobile device can be connected via wireless.

- A single user can use his smartphone, tablet, iphone, PC for to connect to webserver and so for to control the GPIO (and so every relay).

This is my preliminary idea. I don't know if I forgot to consider something of important, software or hardware. Before to do a schema on paper, I want ask you some question if you can help me. I saw that some one have used also a microcontroller as Arduino with RPI for this scope. So, for clear my ideas I want ask you:

1) what are the advantage to use Arduino in combination with RPI?

2) I saw that there are a lot of open source project for to control home via webserver. Can you suggest me what are the most popular?

If I have not explained well, you can ask me where I can be more clear.

For now, thank you very much.
Gianfranco

jsobota
Posts: 42
Joined: Tue Jul 10, 2012 3:24 pm
Location: Plzen, Czech Republic

Re: Home automation with RPI for control wired "things"

Tue Sep 17, 2013 2:54 pm

How many lights and other devices are you planning? With at least 2 GPIO for every light (1 for the relay, 1 or more for button(s) in the room) you'll run out of GPIOs on the RPi soon. That's why the Arduino comes in handy, especially the MEGA2560 with its 70 GPIOs.

crystal13
Posts: 67
Joined: Tue Jan 22, 2013 2:13 pm

Re: Home automation with RPI for control wired "things"

Wed Sep 18, 2013 8:21 am

Perfect I understood. Ok, I will think it.

Now, another question is in my mind: until now I had always thought for a centralized system for my electric wired plant. But reading on Google, and some international conference documents, the best solution is a decentralized solution, because if I have a problem on my RPI, entire house will be blocked.
But I don't know how can work a decentralized solution. I don't understand how can it be built:

- is there only one wi-fi router where a RPI is connect by LAN cable, and then the RPI is connected with one Arduino microcontroller for every room (for control the devices of that room)? So, every room have his Arduino and the webserver can be installed on the single RPI.

- is there only one wi-fi router and every room have his RPI, where every RPI is connected on a LAN bus that starts from the router? If so, how can be control the system with only one webserver?

Where I can find some schemas and design plant of these solutions?

Excuse me for these trivial questions.
Gianfranco

Thank you very much.

jsobota
Posts: 42
Joined: Tue Jul 10, 2012 3:24 pm
Location: Plzen, Czech Republic

Re: Home automation with RPI for control wired "things"

Wed Sep 18, 2013 9:15 am

Unless you use additional hardware, the Arduino and Raspberry Pi must be relatively close to each other (you can connect them via USB or I2C).
The decentralized system can be built, one RPi will serve as a "master" with a webser running and the other RPis will be "slaves" who will exchange data with the "master".
But this decision should be made AFTER you know exactly what functionality you expect from your system.
I think a separate RPi for each room would be an overkill. I would go for a RPi+Arduino for each individual floor or something like that.

crystal13
Posts: 67
Joined: Tue Jan 22, 2013 2:13 pm

Re: Home automation with RPI for control wired "things"

Thu Sep 19, 2013 10:31 am

jsobota wrote:Unless you use additional hardware, the Arduino and Raspberry Pi must be relatively close to each other (you can connect them via USB or I2C).
The decentralized system can be built, one RPi will serve as a "master" with a webser running and the other RPis will be "slaves" who will exchange data with the "master".
But this decision should be made AFTER you know exactly what functionality you expect from your system.
I think a separate RPi for each room would be an overkill. I would go for a RPi+Arduino for each individual floor or something like that.
Hello,

but as you suggest, my question is: if the RPI "master" will broken, the entire system goes down. So, it is more near a centralized solution or I wrong?

Thanks!

jsobota
Posts: 42
Joined: Tue Jul 10, 2012 3:24 pm
Location: Plzen, Czech Republic

Re: Home automation with RPI for control wired "things"

Thu Sep 19, 2013 10:53 am

No, each RPi is running its own tasks and algorithms so each of them can work standalone. The "master-slave" relationship was meant only for the purposes of the webserver. E.g. the "slave" RPi will control the temperature in one room and it will report the current temperature to the "master" RPi to display it on the webpage. And it will receive the desired room temperature from the "master" (you will be able to set it via edit field in the webpage). If the "master" RPi goes down, the "slave" RPi still controls the temperature, you are just not able to adjust the temperature in the room (since the webserver is down).

Or you could run a webserver on each RPi, collecting data from all the other RPis, so you always have some webserver available. There are many ways to deal with redundancy. But always keep in mind that it is not a nuclear power plant which you want to control ;-)

PiGraham
Posts: 3529
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Home automation with RPI for control wired "things"

Thu Sep 19, 2013 11:51 am

You should be cautious when considering mains switching systems. There are regulations, legal liabilities and insurance clauses to consider if you install unapproved and uncertified devices and wiring in your home or office. Consider the safety of family, guests and property.

There are many certified mains control devices on the market for switching lights and appliances, dimming lights, sensing switches, locking doors etc. Most, if not all, of these devices could be interfaced to a Pi.

crystal13
Posts: 67
Joined: Tue Jan 22, 2013 2:13 pm

Re: Home automation with RPI for control wired "things"

Mon Sep 23, 2013 1:44 pm

Ok! Sorry for my delayed answer but I'm studying and I'm understanding something.... ;)

For a decentralized solution, do you mean a solution where you connect an RPI Master to 2 or more RPI slave using SPI bus? I found this article where is explained how to connect the RPIs via SPI bus.

http://hertaville.com/2013/07/24/interf ... i-using-c/

The SPI bus is the best way for connect RPI slave to an RPI master or are there other ways? I read of che I2C but I don't know if it is better.

Thank you....

jsobota
Posts: 42
Joined: Tue Jul 10, 2012 3:24 pm
Location: Plzen, Czech Republic

Re: Home automation with RPI for control wired "things"

Mon Sep 23, 2013 7:59 pm

SPI is meant for communication between various devices over short distances, it is used mostly on a single PCB.
For communication between 2 or more RPis, I would use the onboard Ethernet.

crystal13
Posts: 67
Joined: Tue Jan 22, 2013 2:13 pm

Re: Home automation with RPI for control wired "things"

Tue Sep 24, 2013 7:05 am

jsobota wrote:SPI is meant for communication between various devices over short distances, it is used mostly on a single PCB.
For communication between 2 or more RPis, I would use the onboard Ethernet.
Hello, I don't understand.
Meaning that you connect a RPi master (with webserver) to a router wifi via LAN cable, and the others RPi slave (with their logic) always via LAN cable to router?

Anyway, I read that the use of Arduino is essential for control devices (instead RPi slave) because Arduino has analog output that RPi doesn't have. So, for reading analog values from analog sensor, should be required an Analog-Digital Converter and it greatly complicate things.

So, a possible solution can be: 1 RPi master (webserver) and others Arduino slave for control devices.

Do you agree?

Thank you very much!

jsobota
Posts: 42
Joined: Tue Jul 10, 2012 3:24 pm
Location: Plzen, Czech Republic

Re: Home automation with RPI for control wired "things"

Tue Sep 24, 2013 9:32 am

You understand it correctly, I meant connecting the RPis via home router (or switch).

The use of Arduinos is always possible. But you did not mention any analog signals in your initial post so we are coming back to my first reply - think about all the measured signals and controlled devices first, THEN search the hardware which will allow you to do what you need.

User avatar
Cancelor
Posts: 756
Joined: Wed Aug 28, 2013 4:09 pm
Location: UK

Re: Home automation with RPI for control wired "things"

Tue Sep 24, 2013 10:31 am

I understand the two I2C buses are the easiest and most expandable on the RPi and are capable of expanding to thousands of ports.

What does the Arduino bring to the party?
Can't find the thread you want? Try googling : YourSearchHere site:raspberrypi.org

jsobota
Posts: 42
Joined: Tue Jul 10, 2012 3:24 pm
Location: Plzen, Czech Republic

Re: Home automation with RPI for control wired "things"

Tue Sep 24, 2013 11:43 am

You can use I2C analog-to-digital converters to read e.g. light intensity, you can use I2C 1-wire gateway to read e.g. temperatures from DS18B20 thermometers, etc. Or you can use one Arduino to read all these sensors and let it report the data to the RPi.

crystal13
Posts: 67
Joined: Tue Jan 22, 2013 2:13 pm

Re: Home automation with RPI for control wired "things"

Tue Sep 24, 2013 12:09 pm

jsobota wrote:You understand it correctly, I meant connecting the RPis via home router (or switch).

The use of Arduinos is always possible. But you did not mention any analog signals in your initial post so we are coming back to my first reply - think about all the measured signals and controlled devices first, THEN search the hardware which will allow you to do what you need.
Hello jsobota,

ok, the only thing of I'm not sure is that the communication via LAN of the "slave" is the best way: reading some article and other document, people speak that the SPI/I2C communication bus is for Master<->Slave purpose. For example:

http://hertaville.com/2013/07/24/interf ... i-using-c/

I'm asking this only because I can't imagine how the slaves send data to the master via LAN cable, and because the LAN cable is more bigger of the dimension of four cables for the SPI connection.

Another question: using SPI bus, for read analog data that can take an Arduino Slave from the RPi master is always need of a ADC?

Thank you!

jsobota
Posts: 42
Joined: Tue Jul 10, 2012 3:24 pm
Location: Plzen, Czech Republic

Re: Home automation with RPI for control wired "things"

Tue Sep 24, 2013 12:40 pm

OK, to clarify things: I2C and SPI are meant for master/slave connection, no discussion about it.

What I meant with "master" and "slave" in the webserver context was that the RPi1 running the webserver can not only display all the data it reads from its own SPI or I2C slaves but it can also poll data from RPi2 over the Ethernet. The RPi2 has its own I2C slaves or maybe an Arduino connected via USB.
Because RPi1 polls data from RPi2, it is possible to display all the data in one webpage, which is available from RPi1.

AFAIK, the I2C and SPI buses are used mainly for short-range communication. On the contrary, the Ethernet cable can be up to 100 metres long.

crystal13
Posts: 67
Joined: Tue Jan 22, 2013 2:13 pm

Re: Home automation with RPI for control wired "things"

Tue Sep 24, 2013 1:02 pm

jsobota wrote:OK, to clarify things: I2C and SPI are meant for master/slave connection, no discussion about it.

What I meant with "master" and "slave" in the webserver context was that the RPi1 running the webserver can not only display all the data it reads from its own SPI or I2C slaves but it can also poll data from RPi2 over the Ethernet. The RPi2 has its own I2C slaves or maybe an Arduino connected via USB.
Because RPi1 polls data from RPi2, it is possible to display all the data in one webpage, which is available from RPi1.

AFAIK, the I2C and SPI buses are used mainly for short-range communication. On the contrary, the Ethernet cable can be up to 100 metres long.
Ok I'm understanding. For RPi2 you mean a RPi slave displaced in a room, that can be an Arduino also? Or what?

Thank you for patience...

DrFatalis
Posts: 24
Joined: Sat Sep 07, 2013 8:47 pm

Re: Home automation with RPI for control wired "things"

Tue Sep 24, 2013 2:43 pm

One solution for home automation is using X10 protocol to send information through electrical wire in your house.
You can place some X10 module in switch light hole and use a CM15 pro to send X10 order in your house electric wires.
Security system and others functionnalities exist on this protocol.

You connect your raspberry pi to CM15 Pro thanks to an USB cable and send order. I've got a tutorial on a french blog that explain how to proceed but it's in french. This will send information to the desired module like dimmer, touch screen, or others devices and will control all your house.

gl & hf

User avatar
richiepp
Posts: 129
Joined: Wed Dec 19, 2012 4:56 pm

Re: Home automation with RPI for control wired "things"

Tue Sep 24, 2013 2:57 pm

This is an awesome thread! I'm putting together something similar but as a retrofit. I'm about to be really busy for the next 3 weeks and don't have time to give the details but here is a photo of my prototype. I decided to go with a Pi and Arduino Mega2560.

Image

Ride On!
Rich

jsobota
Posts: 42
Joined: Tue Jul 10, 2012 3:24 pm
Location: Plzen, Czech Republic

Re: Home automation with RPI for control wired "things"

Tue Sep 24, 2013 3:08 pm

One diagram might be worth 1000 words, see the rough sketch of the topology I'm talking about. Hope it helps.
Attachments
HomeAutomation.png
Rough sketch of home automation topology
HomeAutomation.png (31.95 KiB) Viewed 15366 times

crystal13
Posts: 67
Joined: Tue Jan 22, 2013 2:13 pm

Re: Home automation with RPI for control wired "things"

Wed Sep 25, 2013 8:57 am

@DrFatalis: can you link me your blog? I can use google translator. :mrgreen:

@richiepp: wainting for your development! ;)

@jsobota: thank you for your schema!
I will study it. So with this schema I can command the RP2 and Arduino+Eth_Shield via webserver (that is on RP1), right?
What I should understand is how the RPi2 and Arduino+Eth_Shield can respond to the webserver of RPi1. Is there a database where the RPi and Arduino will insert their datas? Do you have some tutorial on how to do this?

For now, thank you very much!

DrFatalis
Posts: 24
Joined: Sat Sep 07, 2013 8:47 pm

Re: Home automation with RPI for control wired "things"

Wed Sep 25, 2013 9:26 am

I've seen it on another site but this one seems to follow the same tutorial:
It allows you to send command from your raspberry to module on your electric wires.
Got the link on my Home computer if i retreive it of course XD

https://sites.google.com/site/321domoti ... spberry-pi


jsobota
Posts: 42
Joined: Tue Jul 10, 2012 3:24 pm
Location: Plzen, Czech Republic

Re: Home automation with RPI for control wired "things"

Fri Sep 27, 2013 2:21 pm

@crystal13:
I will study it. So with this schema I can command the RP2 and Arduino+Eth_Shield via webserver (that is on RP1), right?
What I should understand is how the RPi2 and Arduino+Eth_Shield can respond to the webserver of RPi1. Is there a database where the RPi and Arduino will insert their datas? Do you have some tutorial on how to do this?
I have experience only with RPi+Arduino. For connecting these two together, I have developed "REXduino", see it in action:
http://www.youtube.com/watch?v=65jkw4tQJTc
I use it to control the heating at my house and summer house.

If you are interested in details, see http://control.zcu.cz/~jsobota/REXduino.pdf
The code is available at https://github.com/jaroslavs/REXduino

For data sharing, you can
1) mount the filesystem of RPi1 on RPi2
e.g. http://www.debianadmin.com/mount-a-remo ... sshfs.html
2) or you can write your own programs for data exchange between the RPis
3) or you can use third-party software, e.g. the REX Control System which I use is capable of data exchange between individual RPis without much effort.

I never came across the Ethernet shield, I just know it's out there, sorry.

halhertani
Posts: 40
Joined: Sun Aug 19, 2012 5:02 am
Location: Ottawa, ON Canada
Contact: Website

Re: Home automation with RPI for control wired "things"

Mon Sep 30, 2013 4:24 pm

crystal13,
Have you considered using socket programming to make the RPi's talk? Just put every RPi on the network with a wireless USB WiFi dongle and run two servers on the central RPI, The webserver (Apache/Lighttpd/Nginx e.t.c) that displays data on a website as well as another server..that listens to say on port 12345 that facilitates communications between itself and the other RPis (clients). This way you can use the network to have the RPis communicate as well as to access sensor data. To learn more about socket programming in C on Linux check out this tutorial http://beej.us/guide/bgnet/.

Socket programming APIs for Python and other languages should also be available.

crystal13
Posts: 67
Joined: Tue Jan 22, 2013 2:13 pm

Re: Home automation with RPI for control wired "things"

Mon Sep 30, 2013 11:26 pm

@DrFatalis: thank you, I will study your solutions, too.

@jsobota: I'm following your idea. You can see my plan in the picture attached. What do you think?
I saw your video: you have used RPi+Arduino on same ethernet port for controlling them by tablet. But where I can find tutorial on how to control the RPi1, RPi2, Arduino, .... on the same webserver installed on RPi1? How can I discriminate sending remote commands to an RPi2, instead that the RPi1?

@halhertani: my first analysis was based on "wifi solution" using the wireless transceiver of Nordic, NRF24L01+. Do you know this method of communication? Do you know the difference with your proposal? For now, I'm studying the "wired solution" because I read that it is free from interference, is more secure and is more reliable that the "wifi solution".

Thank you to all!
Attachments
arch_rpiforum_wifi.jpg
wifi solution
arch_rpiforum_wifi.jpg (39.32 KiB) Viewed 14669 times
arch_rpiforum.jpg
wired solution
arch_rpiforum.jpg (33.85 KiB) Viewed 14669 times

Return to “Automation, sensing and robotics”