What Symfony Has To Do With My Garage - Home Automation With PHP
CC Attribution - NonCommercial 2.0 Germany:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Unger, Jan
What Symfony Has To Do With My Garage - Home Automation With PHP Raspberry Pi is a perfect mini computer to experiment with, small, inexpensive, low energy consumption and easy to expand. This talk, using the example of a Symfony app as a remote control for a garage door drive, shows that it's possible to write hardware drivers in PHP and how to easily use the Raspberry Pi along with the PiFace Digital Expansion Board for home automation. ······························ Speaker: Jan Unger Event: FrOSCon 2014 by the Free and Open Source Software Conference (FrOSCon) e.V.
 So, good morning everybody. I hope you all slept well. I wasn't here at the social event yesterday but I saw photos of the PHP table outside in the social area and I guess there were some hard stuff going on as far as the photos told me. Okay, what Symphony has to do with my garage, I'm going to tell you a little story of what I did in the last month. The big headline is home automation with PHP. A few words about me, my name is Jan Ummer. I'm a freelancer living in the Rhein-Main area near Frankfurt. I'm doing web applications mostly with PHP and JavaScript. PHP, since 14 years now, back in 2000 I was young and needed the money. Nowadays I'm old and still need the money. If you have any questions don't hesitate, just shout out. Try to answer them instantly. The object, what I'm going to talk about is this garage, my garage at home. It's a sectional door, electric drive is already in place. The view from inside is like this. You see up here we have a box with a motor in it and the metal beam, inside this metal beam there's a chain, quite similar to a bicycle chain you might know. Attached to this chain at the front is another metal beam and this metal beam that heads to the door and the motor drives this chain and thereby pulls the door back and forth. This was already in place and my intention was to get this thing accessible via anything like HTTP. There already was a radio remote control, this thingy here attached to my car key and this remote control was one of the main reasons why I started all this because I used to have this remote control in my pocket and from time to time without noticing I accidentally pushed the button, the door goes open and I didn't notice and the problem is as you see on the photo, this here is the door where you can go upstairs to our flat and there's a hole in the wall between the garage and the stairs and when the door is open you can go straight away up to the flat which is obviously not what I want. This was motivation number one, the other thing I had from time to time I drove away in the morning, deep in thoughts and two corners later I thought have I closed the fucking door? I don't remember. Yeah and this is the motivation for all. You have another thing in place, this is a button at the wall which you can just press, it's wired up to the motor, press the button and the motor goes up and yeah. The hardware, you might all know Raspberry Pi which is the base for my little thing, who knows Raspberry Pi? Okay for the others it's a micro computer, approximately the size of a bank card, it's a platform based on an ARM processor, quite similar to what you might have in your pocket as a smartphone. The big thing about this is it's quite cheap, about 30 euros and it's easy to expand. This here is the Raspberry and it has an expansion board GPIO, general purpose input output and five of these pins implement something that is called SPI, a serial peripheral interface bus, it's a de facto standard invented by Motorola for a synchronous serial in and out. And to make this GPIO port accessible for me, I'm not that deep in electronics, I used another thing, this expansion board, it's called PiFace, costs another 30 euros and it utilizes this SPI bus that comes out here and brings us eight input ports and eight output ports where you just can plug in two wires and if the wires are connected the electronics can tell okay the input port is connected, if they are apart the input port is open. The other way around is just the same, if you tell the software close this port then those two pins get connected, if you tell the software to open the port the two pins get apart. Okay, another nice thing which I didn't use but which makes it quite usable for home automation, you can stack up to four of these expansion boards onto one Raspberry Pi, so you have 32 inputs and 32 outputs with quite affordable amount of money. Software base is on the Raspberry, the operating system is called Raspbian, it's an ARM version of Debian Easy, so if you know Debian you're good to go, it's a fully operatable computer which you have, it has HDMI output, it has two USB ports, it has a network interface, audio in and outputs and the persistence is done by an SD card plugged to the port. And this is how it looks when it's assembled, this Pi phase is just stacked upon the Raspberry and it's quite as big as a cigarette box approximately. If you want to have a look on it, I have one with me, I have it here. If you're interested just come to me after the talk and take a look at it. Stealing it has no point, it's broken, I somehow managed to break it. Okay, the sensors, I want to tell if the door is open or closed or anything in between and to reach this I have two things that are called read contacts. Read contact is basically a small capsule, inside this capsule there are two metal plates and if they get in the range of a magnetic field they close to each other and provide an electrical contact. Which means we have a magnet which I'm going to attach to the door, this magnet is going to move back and forth with the door and somewhere we have those sensors and if the magnet approaches these sensors I get a contact at these two wires and just plug them into my Raspberry and so I can tell where the door actually is. Okay, so far. As I said, any questions just shout out. Okay, this is the installation, still looking a bit like a prototype which it is actually. The Raspberry mounted in some common installation box, we have an ebony uplink here and we have power voltage and we have some wires to the sensors and the actor. Oh, I forgot the actor is the thing mounted on the wall, you know, you remember the switch, I just attached to additional wires to the switch coming out of the relays here. Which means I can tell the software close the relay, it's as if I push the button and open the relay releasing the button. This is the situation in front at the door where the drive approaches the door and here is where I mounted this one read contact. You get a bit closer, it looks like this. This is the capture with this read contact. This is the magnet attached to this metal beam moving back and forth to the door. And on the other side, backwards, there's the same, this is the read contact and the magnet comes up here and stops right in front of this sensor. Another thing I have in place because I'm a control freak is a webcam which was in fact the first step in this little project where I could tell if the door is open or not. But the thing is the camera won't tell me, hey, the door is going up, have a look what's happening here. This is the view down from the camera and as you can see, we have a direct link here from the garage up to the stairway, stairway up to a flat. The software is a small single page application which can easily be accessed via a smartphone. It has a status indicator which tells me the door is closed, the door is open or the door is somewhere in between and is supposedly moving at the moment. We have a live photo from the garage and we have a button where we can tell the drive go. This is the basic structure of the application. The container is a symphony app, mostly overkill, but another intention which I had in mind was to tell if a Raspberry is suitable for running symphony applications. In fact, it is a bit slow but still usable as long as you don't have too many users at the same time and the only user and it's quite okay. We have four functional components. We have a door state indicator which we saw here which is able to tell whether the contacts are closed or open. We have a motor trigger which takes post requests from the single page app and tells the motor go ahead. We have the camera proxy delivering the photo from the webcam. Another thing in place is a watchdog which is a console command running endlessly which reads the contacts every second and if the state changes which means the door is up to move, it's going to send me an email. This was another point, another solution I would like to have to be informed when the door opens without me doing anything about it. The camera proxy was necessary because the camera itself has an HTTP interface but no SSL in place and sending credentials over the internet is probably not the best idea at least in plain HTTP and this is what this camera proxy is for. I pulse in photo and send it out via another channel. I didn't invent the wheel myself as you might guess. There were two main components in place which helped me to solve my problems. The first one is this component PHP SPI. It is a PHP module implemented in C. Some guy much smarter than me did this. It makes it possible to access the hardware via PHP and this is where the magic happens. It provides a PHP interface, a class called SPI which models this hardware access. The second thing that made it much easier to access the hardware is this project from a guy from Norway. It's an abstraction layer above this SPI module where you can simply access a method that reads and writes values to the single pins on the Raspberry. This is actually a PHP part of the original library from the window pyphase. It's that one here and this one is done in Python. You might say you could also have used the original Python library but this is not what I wanted to do. My point was to get to know if it works with PHP and it worked out quite well as we're going to see. Okay let's have a look at the code that we have here. First and foremost there is this driver class and as you can see there's many stuff going on here with hexadecimal addresses. I didn't dig in that deep I must admit. I just was happy that all of that works. If you like it's all on GitHub and you can read afterwards what's happening here. The thing is we have an API that allows us to read bits from the SPI bus and to write values to other bits at this SPI bus. And my hardware uses this. Just a second way have I. There it is. This is the topmost abstraction layer of the pyphase board which I've built. When it creates an instance it gets itself eight representations of the input pins and eight representations of the output pins. And all of what these pins do they know I'm attached to this board and to this pin number and they can tell the value of the actual pin and they can write the value in case of an output pin to the appropriate memory address. The application itself is rather simple. Do you all know symphony? At least at a basic level who knows symphony? Okay. The basic thing is you have a front controller. This patching request to specialized controllers in the application. And in my application we have four of these controllers. We have an index action, index controller which delivers the static HTML for the single page application. We have another controller in place for the door state action which gets a service from the service container and is able to tell whether the door is open, the door is closed or the door is moving. And it sends back a JSON response which the single page application is able to process. The next controller is this trigger action which gets a post request and tells the door, the motor, go ahead, move. The last controller we have in place is the snapshot action for the webcam which pulls an actual image from the camera and sends it out to the requesting application. And as you remember we had another thing in place, this watchdog. It's this one here. It's a console command. Symphony provides console commands which you can run on the server. And this one here is simply running a while loop endlessly where it executes a so-called watchdog component. The watchdog component reads the sensors, tells the state and if the state changes it sends out a mail. This mail is queued up. Symphony has a mail queue and after executing the watchdog this mail queue is flushed and the mail actually is sent out. And from time to time because PHP and long running process is not that good idea, this thing terminates itself every 24 hours and gets restarted by supervisor daemon which takes care of that this process is started if it terminates for whatever reason. Okay. I originally intended to do a live demonstration with this thing here but as you know it's broken and obviously I can't bring my garage here and I can't take you to my garage to show you how this works in real life and so I did a little video where you can see what happens. This is the garage. When I go downstairs in the garage I open my smartphone, push the button, the relay triggers, the motor starts moving. You see the magnet leaving the read sensor, the door opens. The read sensor on the other end, the magnet reaches the other end and the sensor at the other end, push in the button again, the relay triggers, the motor starts moving, the magnet reaches the sensor and my application tells me the door is closed. Everything is fine. Okay. This is the current state as it's currently running in my garage. I have some things in mind I want to try out with this. First of all some performance tuning. As I said before Raspberry is not the real performance hardware. Running full lamp stick on it with a symphony application is okay. It's not perfect. I'm going to try out a few alternatives. Throwing out the symphony stuff and using plain PHP, using Nginx and Light HTTP as a web server which might help a little. Let's see. I'm just trying out a few things. The other thing I have in mind is a feature, automatic closing, which allows me to go to the garage, open the door, drive the car out and don't care how the door closes, it would close by itself. I could do this just by telling okay. The door is open for 15 seconds now. The car should be out. Let's close the door. Might work. Might be too fast. Who knows. I already have some hardware in place to solve this. I have a photo sensor at the height approximately of the car bumper. If this photo sensor, if the light beam gets disconnected, we have two wires coming out of this. If the light beam is connected, the sensor is closed. If the light beam is disconnected, which means the car goes through, the sensor is disconnected. Thereby, I can tell, okay, the light beam has been disconnected for five seconds. It has been connected again. Okay. I think the car is out. We can close the door. It depends. I'm going to do a little research on that. How long it's disconnected when the car goes through compared to how long it's disconnected when the person walks through. I'm not quite sure about that. I haven't tried it out yet, but I'm going to. It's a point I had in mind, and I'm not sure if it works. Let's see. Another thing I have in mind is trying out web sockets. Currently, my single page application pulls every two seconds. This data is indicator. The image gets updated every 10 seconds, which causes quite a bit load on the respiration. By having web sockets, I would be, this problem would be solved. I would have an open connection to the server and the server would be able to push a notification as soon as something happens, which might be faster than the actual polling solution. Another thing I'm going to try out is an Android widget instead of the web application. I've never done Android development before. That might be a good point to start. Native application that talks to my door. Let's see how it works. Voice control is a point. I've seen a video of a guy in the US who has done quite a similar thing. The main difference is he hasn't built an application, but he talks to Siri. It tells Siri open the door. Magically, the garage door starts moving. I'm going to try this also. The last thing I'd like to try out is Ipeacon, which means having a Bluetooth first transponder in the range of the garage. If the smartphone comes in range of this Bluetooth transponder, the Android app might fire up and say, hey, we're in the garage. Shall I open the door? You see, it's a nice playground for big boys. Okay. I collected some links if you want to dig in deeper. First of all, this is my application, which I built. This garage door control is the Symphony application. It's on GitHub. There's also the library which abstracts the SPI bus. The PHP module for accessing the SPI bus and some materials for further reading. This is the documentation of the vendor of this PyFace board and some more stuff if you want to dig in deeper in Raspberry Pi and this GPIO port. I put up the slides. At slideshow, I'm going to tweet the link afterwards if you would like to read. Go ahead and grab it. There are quite some alternatives out there. Raspberry Pi is not the only thing to use. If you want to do a home automation, there is stuff called ZWAVE and a related project, Raspberry. I don't know how to pronounce it correctly. It's similar, but it's wireless, which means you have an expansion board on the Raspberry with some kind of wireless controller talking to hardware over the air. One wire, as far as I know, is something similar. Don't know much about that. ZWAVE, a friend of mine, played around with ZWAVE and he did a garage drive lately, which seems to work quite well. Another alternative might be Arduino. I don't know much about Arduino, but we have a talk today as far as I remember in the evening to Thomas Weynert. That was yesterday. Oh, it was yesterday, sorry. But you may be still around if you like to have some words about Arduino talk to him. Of course, we have a big variety of commercial products for home automation. I don't know much about them, but I would guess there might be more expensive than this DIY solution. Short recap. The electric door drive was already present, a common one, like you can buy it at the hardware store. Things I bought myself were these two read switches for about 12 Euro each. Some cables. The Raspberry, which is about 30 Euros. The expansion board, 30 Euros. With 90 Euros, I have my own home automation project, which I can play around with. Home automation can be easily done as a beauty self project, at least for me. This was proof enough. The Raspberry Pi works well as a platform for that. It's compact. It's inexpensive. It has a small energy footprint, and it's easy to extend. Okay. And now I'm happy to take your questions, if there are any left. Question was, if I considered to use an expansion camera for the Raspberry Pi, attached directly at the Raspberry Pi. In fact, yes, I did. But in my case, the camera was in place long before the Raspberry, because as a first quick solution to tell whether the door is open or not, I just wanted to have access to a photo. So I had this web camera already and just put it up there. And the Raspberry is mounted at the wall, but not at a place where it can look at the door. This is the point why I didn't consider, but this might be a point also, yes, using a camera attached to the Raspberry. Yes, please. I have a question with hardware configuration. If you could talk correctly, the standard of the Raspberry is open or closed, more or less vibrate. You can only say open or closed. Yes. Open or closed is impossible. Yes, question. So for other applications that in particular might, traditions, so the kids put something in the garage and they put it not far enough in the garage, then the door comes closed and then there's an internal mechanism which is stopping. And then it's half closed or big closed. Yes. So this is, from my perspective, a very critical situation. So you have to see the door closing down, but then there's a space in between and everybody has to be through. And maybe in winter with snow and ice, other situations, have you thought about something to solve this problem? I just repeat the question for the stream. The question was the sensors. If they are able to tell whether, if they currently put the answer right into it, currently the sensors are just able to tell whether the door is closed, completely closed, or completely opened. As we have a punctual sensor which can tell the magnet is in range or it is not. I cannot tell where the door is when it's moving in between. I might get into the same situation as you described it, that something is in the way of the door. The door crashes into some kind of, yeah, and it stops right. Because the electrical drive is to design to stop if it reaches something in its way. In my case, it's not that big problem as I get an email as soon as the door opens. And I get another email as soon as the door closes. And closing means closing completely. If it stops under ways, the state of the door is currently moving. The sensors can't tell if it's actually moving, but they know it's not completely opened and it's not completely closed. And that's enough for me in that case. About 15 centimeters, 10 centimeters. Yeah, it might be enough to leave some centimeters of the door open at the bottom in edge cases, yes. I haven't had that case yet, but would be not that much of a problem as those 5, 10 centimeters won't be enough for someone to break into my house. And this was my main point. And the, which we didn't see here, the kinematic of the door is so that the door reaches the bottom of the garage long before this metal beam arrives here. It's hard to describe. It's a sectional door and the top most section gets tilted. Yes, thank you. On the last, say, 20 centimeters of this way. On the last 20 centimeters of this way, the bottom most section is already on the ground of the garage. So all what could happen if it stopped here, say, that the top of this door stays open for, say, 10, 20 meters. Could be a problem if you have a neighborhood who is willing to throw something in, but in my case it's not the point. Okay, some more questions. Three, two, one. Thank you.
 So, good morning everybody. I hope you all slept well. I wasn't here at the social event  yesterday but I saw photos of the PHP table outside in the social area and I guess there  were some hard stuff going on as far as the photos told me.  Okay, what Symphony has to do with my garage, I'm going to tell you a little story of what  I did in the last month. The big headline is home automation with PHP. A few words about  me, my name is Jan Ummer. I'm a freelancer living in the Rhein-Main area near Frankfurt.  I'm doing web applications mostly with PHP and JavaScript. PHP, since 14 years now, back  in 2000 I was young and needed the money. Nowadays I'm old and still need the money.  If you have any questions don't hesitate, just shout out. Try to answer them instantly.  The object, what I'm going to talk about is this garage, my garage at home. It's a sectional  door, electric drive is already in place. The view from inside is like this. You see up  here we have a box with a motor in it and the metal beam, inside this metal beam there's  a chain, quite similar to a bicycle chain you might know. Attached to this chain at the  front is another metal beam and this metal beam that heads to the door and the motor  drives this chain and thereby pulls the door back and forth. This was already in place  and my intention was to get this thing accessible via anything like HTTP. There already was  a radio remote control, this thingy here attached to my car key and this remote control was  one of the main reasons why I started all this because I used to have this remote control  in my pocket and from time to time without noticing I accidentally pushed the button,  the door goes open and I didn't notice and the problem is as you see on the photo, this  here is the door where you can go upstairs to our flat and there's a hole in the wall  between the garage and the stairs and when the door is open you can go straight away  up to the flat which is obviously not what I want. This was motivation number one, the  other thing I had from time to time I drove away in the morning, deep in thoughts and  two corners later I thought have I closed the fucking door? I don't remember. Yeah and  this is the motivation for all. You have another thing in place, this is a button at the wall  which you can just press, it's wired up to the motor, press the button and the motor  goes up and yeah. The hardware, you might all know Raspberry Pi which is the base for  my little thing, who knows Raspberry Pi? Okay for the others it's a micro computer, approximately  the size of a bank card, it's a platform based on an ARM processor, quite similar to what  you might have in your pocket as a smartphone. The big thing about this is it's quite cheap,  about 30 euros and it's easy to expand. This here is the Raspberry and it has an expansion  board GPIO, general purpose input output and five of these pins implement something that  is called SPI, a serial peripheral interface bus, it's a de facto standard invented by  Motorola for a synchronous serial in and out. And to make this GPIO port accessible for  me, I'm not that deep in electronics, I used another thing, this expansion board, it's  called PiFace, costs another 30 euros and it utilizes this SPI bus that comes out here  and brings us eight input ports and eight output ports where you just can plug in two  wires and if the wires are connected the electronics can tell okay the input port is connected,  if they are apart the input port is open. The other way around is just the same, if you  tell the software close this port then those two pins get connected, if you tell the software  to open the port the two pins get apart. Okay, another nice thing which I didn't use but  which makes it quite usable for home automation, you can stack up to four of these expansion  boards onto one Raspberry Pi, so you have 32 inputs and 32 outputs with quite affordable  amount of money. Software base is on the Raspberry, the operating system is called Raspbian,  it's an ARM version of Debian Easy, so if you know Debian you're good to go, it's a  fully operatable computer which you have, it has HDMI output, it has two USB ports,  it has a network interface, audio in and outputs and the persistence is done by an SD card  plugged to the port. And this is how it looks when it's assembled, this Pi phase is just  stacked upon the Raspberry and it's quite as big as a cigarette box approximately.  If you want to have a look on it, I have one with me, I have it here. If you're interested  just come to me after the talk and take a look at it. Stealing it has no point, it's  broken, I somehow managed to break it. Okay, the sensors, I want to tell if the door is  open or closed or anything in between and to reach this I have two things that are called  read contacts. Read contact is basically a small capsule, inside this capsule there  are two metal plates and if they get in the range of a magnetic field they close to each  other and provide an electrical contact. Which means we have a magnet which I'm going to  attach to the door, this magnet is going to move back and forth with the door and somewhere  we have those sensors and if the magnet approaches these sensors I get a contact at these two  wires and just plug them into my Raspberry and so I can tell where the door actually  is. Okay, so far. As I said, any questions just shout out. Okay, this is the installation,  still looking a bit like a prototype which it is actually. The Raspberry mounted in  some common installation box, we have an ebony uplink here and we have power voltage and  we have some wires to the sensors and the actor. Oh, I forgot the actor is the thing  mounted on the wall, you know, you remember the switch, I just attached to additional  wires to the switch coming out of the relays here. Which means I can tell the software  close the relay, it's as if I push the button and open the relay releasing the button. This  is the situation in front at the door where the drive approaches the door and here is  where I mounted this one read contact. You get a bit closer, it looks like this. This  is the capture with this read contact. This is the magnet attached to this metal beam  moving back and forth to the door. And on the other side, backwards, there's the same,  this is the read contact and the magnet comes up here and stops right in front of this sensor.  Another thing I have in place because I'm a control freak is a webcam which was in fact  the first step in this little project where I could tell if the door is open or not. But  the thing is the camera won't tell me, hey, the door is going up, have a look what's happening  here. This is the view down from the camera and as you can see, we have a direct link  here from the garage up to the stairway, stairway up to a flat. The software is a small single  page application which can easily be accessed via a smartphone. It has a status indicator  which tells me the door is closed, the door is open or the door is somewhere in between  and is supposedly moving at the moment. We have a live photo from the garage and we have  a button where we can tell the drive go. This is the basic structure of the application.  The container is a symphony app, mostly overkill, but another intention which I had in mind  was to tell if a Raspberry is suitable for running symphony applications. In fact, it  is a bit slow but still usable as long as you don't have too many users at the same  time and the only user and it's quite okay. We have four functional components. We have  a door state indicator which we saw here which is able to tell whether the contacts  are closed or open. We have a motor trigger which takes post requests from the single  page app and tells the motor go ahead. We have the camera proxy delivering the photo  from the webcam. Another thing in place is a watchdog which is a console command running  endlessly which reads the contacts every second and if the state changes which means the door  is up to move, it's going to send me an email. This was another point, another solution I  would like to have to be informed when the door opens without me doing anything about  it. The camera proxy was necessary because the camera itself has an HTTP interface but  no SSL in place and sending credentials over the internet is probably not the best idea  at least in plain HTTP and this is what this camera proxy is for. I pulse in photo and  send it out via another channel. I didn't invent the wheel myself as you might guess.  There were two main components in place which helped me to solve my problems. The first  one is this component PHP SPI. It is a PHP module implemented in C. Some guy much smarter  than me did this. It makes it possible to access the hardware via PHP and this is where  the magic happens. It provides a PHP interface, a class called SPI which models this hardware  access. The second thing that made it much easier to access the hardware is this project  from a guy from Norway. It's an abstraction layer above this SPI module where you can  simply access a method that reads and writes values to the single pins on the Raspberry.  This is actually a PHP part of the original library from the window pyphase. It's that  one here and this one is done in Python. You might say you could also have used the original  Python library but this is not what I wanted to do. My point was to get to know if it works  with PHP and it worked out quite well as we're going to see.  Okay let's have a look at the code that we have here. First and foremost there is this  driver class and as you can see there's many stuff going on here with hexadecimal addresses.  I didn't dig in that deep I must admit. I just was happy that all of that works. If  you like it's all on GitHub and you can read afterwards what's happening here. The thing  is we have an API that allows us to read bits from the SPI bus and to write values to other  bits at this SPI bus. And my hardware uses this. Just a second way have I. There it is.  This is the topmost abstraction layer of the pyphase board which I've built. When it  creates an instance it gets itself eight representations of the input pins and eight  representations of the output pins. And all of what these pins do they know I'm attached  to this board and to this pin number and they can tell the value of the actual pin and they  can write the value in case of an output pin to the appropriate memory address. The application  itself is rather simple. Do you all know symphony? At least at a basic level who knows symphony?  Okay. The basic thing is you have a front controller. This patching request to specialized  controllers in the application. And in my application we have four of these controllers.  We have an index action, index controller which delivers the static HTML for the single  page application. We have another controller in place for the door state action which gets  a service from the service container and is able to tell whether the door is open, the  door is closed or the door is moving. And it sends back a JSON response which the single  page application is able to process. The next controller is this trigger action which gets  a post request and tells the door, the motor, go ahead, move. The last controller we have  in place is the snapshot action for the webcam which pulls an actual image from the camera  and sends it out to the requesting application. And as you remember we had another thing in  place, this watchdog. It's this one here. It's a console command. Symphony provides console  commands which you can run on the server. And this one here is simply running a while  loop endlessly where it executes a so-called watchdog component. The watchdog component  reads the sensors, tells the state and if the state changes it sends out a mail. This  mail is queued up. Symphony has a mail queue and after executing the watchdog this mail  queue is flushed and the mail actually is sent out. And from time to time because PHP  and long running process is not that good idea, this thing terminates itself every 24 hours  and gets restarted by supervisor daemon which takes care of that this process is started  if it terminates for whatever reason. Okay. I originally intended to do a live demonstration  with this thing here but as you know it's broken and obviously I can't bring my garage  here and I can't take you to my garage to show you how this works in real life and  so I did a little video where you can see what happens. This is the garage. When I go  downstairs in the garage I open my smartphone, push the button, the relay triggers, the motor  starts moving. You see the magnet leaving the read sensor, the door opens. The read  sensor on the other end, the magnet reaches the other end and the sensor at the other  end, push in the button again, the relay triggers, the motor starts moving, the magnet reaches  the sensor and my application tells me the door is closed. Everything is fine. Okay.  This is the current state as it's currently running in my garage. I have some things in  mind I want to try out with this. First of all some performance tuning. As I said before  Raspberry is not the real performance hardware. Running full lamp stick on it with a symphony  application is okay. It's not perfect. I'm going to try out a few alternatives. Throwing  out the symphony stuff and using plain PHP, using Nginx and Light HTTP as a web server  which might help a little. Let's see. I'm just trying out a few things. The other thing  I have in mind is a feature, automatic closing, which allows me to go to the garage, open  the door, drive the car out and don't care how the door closes, it would close by itself.  I could do this just by telling okay. The door is open for 15 seconds now. The car should  be out. Let's close the door. Might work. Might be too fast. Who knows. I already have  some hardware in place to solve this. I have a photo sensor at the height approximately  of the car bumper. If this photo sensor, if the light beam gets disconnected, we have  two wires coming out of this. If the light beam is connected, the sensor is closed. If  the light beam is disconnected, which means the car goes through, the sensor is disconnected.  Thereby, I can tell, okay, the light beam has been disconnected for five seconds. It  has been connected again. Okay. I think the car is out. We can close the door. It depends.  I'm going to do a little research on that. How long it's disconnected when the car goes  through compared to how long it's disconnected when the person walks through. I'm not quite  sure about that. I haven't tried it out yet, but I'm going to. It's a point I had in mind,  and I'm not sure if it works. Let's see. Another thing I have in mind is trying out  web sockets. Currently, my single page application pulls every two seconds. This data is indicator.  The image gets updated every 10 seconds, which causes quite a bit load on the respiration.  By having web sockets, I would be, this problem would be solved. I would have an open connection  to the server and the server would be able to push a notification as soon as something  happens, which might be faster than the actual polling solution. Another thing I'm going  to try out is an Android widget instead of the web application. I've never done Android  development before. That might be a good point to start. Native application that talks to  my door. Let's see how it works. Voice control is a point. I've seen a video of a guy in  the US who has done quite a similar thing. The main difference is he hasn't built an  application, but he talks to Siri. It tells Siri open the door. Magically, the garage  door starts moving. I'm going to try this also. The last thing I'd like to try out is  Ipeacon, which means having a Bluetooth first transponder in the range of the garage. If  the smartphone comes in range of this Bluetooth transponder, the Android app might fire up  and say, hey, we're in the garage. Shall I open the door? You see, it's a nice playground  for big boys. Okay. I collected some links if you want to dig in deeper. First of all,  this is my application, which I built. This garage door control is the Symphony application.  It's on GitHub. There's also the library which abstracts the SPI bus. The PHP module for  accessing the SPI bus and some materials for further reading. This is the documentation  of the vendor of this PyFace board and some more stuff if you want to dig in deeper in  Raspberry Pi and this GPIO port. I put up the slides. At slideshow, I'm going to tweet  the link afterwards if you would like to read. Go ahead and grab it. There are quite some  alternatives out there. Raspberry Pi is not the only thing to use. If you want to do a  home automation, there is stuff called ZWAVE and a related project, Raspberry. I don't  know how to pronounce it correctly. It's similar, but it's wireless, which means you have an  expansion board on the Raspberry with some kind of wireless controller talking to hardware  over the air. One wire, as far as I know, is something similar. Don't know much about  that. ZWAVE, a friend of mine, played around with ZWAVE and he did a garage drive lately,  which seems to work quite well. Another alternative might be Arduino. I don't know much about  Arduino, but we have a talk today as far as I remember in the evening to Thomas Weynert.  That was yesterday. Oh, it was yesterday, sorry. But you may be still around if you like to  have some words about Arduino talk to him. Of course, we have a big variety of commercial  products for home automation. I don't know much about them, but I would guess there might  be more expensive than this DIY solution. Short recap. The electric door drive was already  present, a common one, like you can buy it at the hardware store. Things I bought myself  were these two read switches for about 12 Euro each. Some cables. The Raspberry, which  is about 30 Euros. The expansion board, 30 Euros. With 90 Euros, I have my own home  automation project, which I can play around with. Home automation can be easily done as  a beauty self project, at least for me. This was proof enough. The Raspberry Pi works well  as a platform for that. It's compact. It's inexpensive. It has a small energy footprint,  and it's easy to extend. Okay. And now I'm happy to take your questions, if there are  any left.  Question was, if I considered to use an expansion camera for the Raspberry Pi, attached directly  at the Raspberry Pi. In fact, yes, I did. But in my case, the camera was in place long before  the Raspberry, because as a first quick solution to tell whether the door is open or not, I  just wanted to have access to a photo. So I had this web camera already and just put  it up there. And the Raspberry is mounted at the wall, but not at a place where it can  look at the door. This is the point why I didn't consider, but this might be a point  also, yes, using a camera attached to the Raspberry. Yes, please.  I have a question with hardware configuration. If you could talk correctly, the standard  of the Raspberry is open or closed, more or less vibrate. You can only say open or closed.  Yes.  Open or closed is impossible. Yes, question.  So for other applications that in particular might, traditions, so the kids put something  in the garage and they put it not far enough in the garage, then the door comes closed and  then there's an internal mechanism which is stopping. And then it's half closed or big  closed. Yes.  So this is, from my perspective, a very critical situation. So you have to see the door closing  down, but then there's a space in between and everybody has to be through. And maybe  in winter with snow and ice, other situations, have you thought about something to solve  this problem?  I just repeat the question for the stream. The question was the sensors. If they are  able to tell whether, if they currently put the answer right into it, currently the sensors  are just able to tell whether the door is closed, completely closed, or completely opened.  As we have a punctual sensor which can tell the magnet is in range or it is not. I cannot  tell where the door is when it's moving in between. I might get into the same situation  as you described it, that something is in the way of the door. The door crashes into  some kind of, yeah, and it stops right. Because the electrical drive is to design to stop  if it reaches something in its way. In my case, it's not that big problem as I get  an email as soon as the door opens. And I get another email as soon as the door closes.  And closing means closing completely. If it stops under ways, the state of the door is  currently moving. The sensors can't tell if it's actually moving, but they know it's  not completely opened and it's not completely closed. And that's enough for me in that case.  About 15 centimeters, 10 centimeters. Yeah, it might be enough to leave some centimeters  of the door open at the bottom in edge cases, yes. I haven't had that case yet, but would  be not that much of a problem as those 5, 10 centimeters won't be enough for someone  to break into my house. And this was my main point. And the, which we didn't see here,  the kinematic of the door is so that the door reaches the bottom of the garage long before  this metal beam arrives here. It's hard to describe. It's a sectional door and the top  most section gets tilted. Yes, thank you. On the last, say, 20 centimeters of this way.  On the last 20 centimeters of this way, the bottom most section is already on the ground  of the garage. So all what could happen if it stopped here, say, that the top of this  door stays open for, say, 10, 20 meters. Could be a problem if you have a neighborhood  who is willing to throw something in, but in my case it's not the point. Okay, some  more questions. Three, two, one. Thank you.
What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__0_47.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__48_107.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__108_179.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__180_647.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__648_1031.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__1032_1823.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__1824_2171.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__2172_3167.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__3168_3791.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__3792_4199.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__4200_6587.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__6588_9407.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__9408_13091.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__13092_13727.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__13728_14087.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__14088_14579.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__14580_14939.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__14940_20903.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__20904_27311.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__27312_27863.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__27864_27995.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__27996_28331.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__28332_28499.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__28500_28583.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__28584_28643.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__28644_29123.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__29124_29183.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__29184_29243.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__29244_29339.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__29340_29387.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__29388_29711.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__29712_30059.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__30060_32087.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__32088_33743.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__33744_47735.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__47736_47795.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__47796_49091.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__49092_49907.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__49908_49955.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__49956_50003.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__50004_50099.png What_Symfony_Has_To_Do_With_My_Garage_-_Home_Automation_With_PHP__FrOSCon14__50100_50146.png