Raspberry Pi Automation #2: Energenie Wireless Sockets

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome to another video from explaining computers dot-com and to the second episode of my series about Raspberry Pi home automation specifically in this video I'm going to be using the Raspberry Pi to control these wireless sockets so let's go and open up this rather exciting box so here we have our wireless sockets which as you can see if moçambique order and a genie and specifically this is the energy D PI motor control starter kit which cost me 21 pounds 99 and I say it's the apply motor control starter kit because when I first got this and put it out there packaging from Amazon I went no I've been sent the wrong products because here on the front you we can see a remote control socket but a handheld remote control and in fact down here it says this box contains a handheld remote control and two sockets there's no mention of a Raspberry Pi at all is there but there was a label on what that side I'm a label does make it clear but this contains a two sockets and a Raspberry Pi controller board so let's get this thing opened up should be nice and straightforward there we are that's that wasn't nice and straightforward very very simple and here we are although we are that's the bits we have a inside so let's give you a closer shot of those and as you can see what we have here get it out of a little packet is the Raspberry Pi control the board come out come out the come out of this little packet there we are there's the Raspberry Pi controller board and these clear off sockets have to get them apart to get rid of the thing there so you've got two sockets like like that will they sit there sitting there somewhere like that and then we've got the control board and I should point out this is not Network hardware these are not Wi-Fi devices these are straightforward wireless sockets which don't go on to a computer network I think they're for 33 megahertz but don't quote me on that and so these basically these basically just allow us to control things from a PI but not up not over a network so if I bring in a Raspberry Pi his arrest Pi 3 model b+ and this board will simply go on the top while the GPIO pins up like that I think we'll just get that in there and I'd point out this will on any pie so from the first Raspberry Pi model onwards you can put it onto any Raspberry Pi you like which is clearly very good and on the sockets and ourselves I've only got one control which as you can see is a here with a button nice little button and that that button can be used as a manual on/off and it's also used to pair the sockets with the control board that's on time so talking of doing that I think it's now high time to get this all connected up and go and look at some code right Here I am back again and as you can see I've got the Raspberry Pi all connected up and running in a nice little mount and next to it I've got one of our wireless and a genie sockets and the socket is plugged into an extension lead to give it power down there and then plugged into the unit itself we've got a plug for this angle poison lamp if I just bring that him there and eat something you can see when it turns on and indeed if I press the green button on the unit I can turn the light on and off kind of a overexposed it's a shot but we can see something is going on there that's what we want to be able to do but rather than pressing the button using the PI so the first thing we'll do is to put this unit into pairing mode so I'm going to press and hold the green button and if I do that for about five or six seconds I think it is and there we are now hopefully you can see where's now a little red LED which is a flashing on the top of the unit so we now go to with a raspberry pi desktop or more specifically on running the browser on the Raspberry Pi desktop right now and I'm here on the energy nee website where I was showing you all the different things you can buy for an and genie for the Raspberry Pi I just want to point out with lots of different things in this range and it's all based upon the range of products that energy Nia have for controlling whether hand controllers and it's also worth pointing out there are different versions of controllers for the PI you can get versions like this one at the top here where you've actually got two-way communication so it can turn something on and know it's been turned on but the units we're using here are our cheaper units and these you know simply send a code to turn something on and they assume it's happened so let's open up that products go to the product page and the reason for that is because down here is some useful if I just scroll down and there we are you see we've got product instructions and product software if we open up the instructions like that loke them up in a new tab and obviously go across to the tab Christopher there we are and these are quite nice PDF instructions as to assume them in a bit and they tell you about the board itself there's an original Raspberry Pi one with a board attached and they give you various wiring diagrams GPIO diagrams and those that are also a table here what they call code pairs and the way this basically works there's one GPIO pin which is used to put the board into what's called a sk mode which is amplitude shift keying and there was another GPIO pin which is used to turn on off the board modulator it's transmitter so basically you turn on the transmitter you send code pair to tell some sockets to do something and when you turn off the transmitter and you keep doing that to control things if I just zoom in on this table which shows us the code pairs you'll see basically for GPIO pins labeled here D 0 to D 3 I'll use to send the signals and you can control up to four sockets but you don't just have one GPIO pin the socket they all work together to send the particular code so as you can see this code here is for turning all the sockets on that's for turning them all off one one one one term socket one on zero one one one term socket one off etc so we just get rid of that and we go back to the owner over here is not forgetting where I am doing me we want to go back to the product page and we go to the product software and if we just save the link there you'll find there's some software I've already downloaded it so I won't save it again we'll go and load that in Python so we go to a Python here under programming and python 3 into the idle development environment and there we are and if I load in the code I've actually taken from the website which is this code here this code is fine but it was written for Python 2 and a few things have changed in Python between 2 and 3 that make this incompatible and specifically if we go down here you'll see with some print statements there they were print statements in Python to printed a function in Python 3 which means these brackets around the arguments here which aren't on there and also this code uses a raw input function which doesn't exist in Python 3 it's just now input so what I've done you could probably guess is to rewrite the code and so if a load in my altered version and here it is and I'd point out that for this video series there is a webpage which has got all the code I'm using and every was saying you can download code there so this is the same code but with things like the print functions actually are altered to functions so what does this code do well basically it's got some very very nice commenting which is always great to see and it imports the a GPIO module and the time module and when it sets a board numbering it sets up a load of GPIO pins to control the actual code pairs to be sent and then it also sets that one to control this thing called a SK another one to control the modulator and an initially in terms of modulator off and it also sub submit a sk thing and it also turns all the gpo code pairs to false then various the instructions which will print on the stream so we'll read those later and then down here we then go into a try finally thing which will loop around forever as the end of it there it is down there and it basically operates this wild loop while true so it'll loop forever and it basically gets you to press a key and then sends different code pairs so it can turn socket on and off etc so that's the basic code and so if I run this code which I'm going to do like that and we're on module and that'll hopefully come up I'll scroll back to see all the instructions it basically tells you we're going to set things up and if we go down here what we get down the bottom here it's saying let's just bring that up a little bit so you can all see it on on the screen properly it says a hit return T key to send socket one and on code so if we look back to the socket which is still got its little flashing light hoping to pair up with something it'll basically pair with the first code it gets sent so if I actually hit return key if color be paired up with that and of course the light has gone on that's rather good isn't it and so by now sender and off by pressing the enter key again it'll turn it off that's good isn't it will now send the socket to on code haven't got sake - not connected at the moment anyway person and off code will Latin at all on code and an all off code it clearly working isn't it so our first socket is set up and once it's been set up it'll keep it setting unless you go in a repair it so let's go back to err on and off and now it's going to send this socket to cotellic trying to set up socket - so to do that what I'm going to do is to take out the light and to take out this socket you can't haven't both connected up where you're doing this stuff and we'll now connected the other socket here and put that into there like that and put the light in there we are and we'll put this into pairing mode by pressing that down it's exciting today isn't it that's now but it's little flashing light and I'll now press the Enter key again and we'll have a socket - on code on and off all aren't you turn it on of course it's socket - and off we're now going to send the sake one on code doesn't turn it on turn it off socket - we'll turn it on and turn it off so there we are we've managed to get this thing working so we can control two paired sockets socket 1 and socket 2 so here I am back again and I thought I'd do a test controlling both of the sockets using timers and I've still got one of the sockets connected up to this Antipodes light and I've got the other socket across the room and it's connected to this small movie light and I'd point out you have to have some reasonable separation between these a and a genie wireless sockets they have to be at least two meters apart individual units that's what about six six and a half feet apart and in case you're wondering the range of these at about thirty meters between the socket and the PI it's only a few inches here that's about what sir all about ninety eight ish feet anyway we go back to the PI desktop here you'll see I put my clock up I was using in a last prior automation video and many of you asked about that clock and the clock is actually called the Mac slows Kairo clock which you could install on the PI anyway that's so the clock I'm using and the code is going to be based on the code we were just looking at someone we've got familiar and a genie website a nought a little bit this for example is the block of code here that will turn on a socket one so what I've done is to take the code I had in my last pipe automation video which was basically designed to turn things on and off based upon the tick of the times and I'd use that block of code to show you to turn things on inside this code so we have a look at this basically it loads in GPIO and time and date time all this stuff here sets up all the ward numbering and all the gpo's and things and this is exactly what we've had in the previous code we had a few minutes ago and then down here we've got a try under finally loop they're getting a bit longer here and basically it's going to say at 17 33 which is a couple of minutes away it's going to turn on socket one there's the code we just saw in the code we were just looking at from and a genie that'll turn it on and then it'll turn on the second socket at five thirty four and it'll turn them both off at a 535 so it's basically what it's going to do I should just point out I slightly misled you in the previous section the way this board works is you set up the code pair and then you turn on the module later to ascend the signal and when you turn the modulator off again after a short period of time you don't turn on the modulator first you might not care about that you might care that we'll make sure I've got this right anyway that's what it's going to do so I will now scroll up and down aimlessly and run this code so we'll run the code and there we are which is going to be a running we won't be able to see the clock christopher's have the clock over there and we now need to wait for the first time to come up so I'll speed forward in time and there we are the movie light has turned on I do find this stuff magical I know it's not magical but it just seems a it seems slightly magic I was a bit of Harry Potter going on here and here we are coming up to the next minute is it going to illuminate are you going to work yes it's come on oh it's amazing stuff isn't it and now here we are coming up to our end time we'll both of the things be turned off let's see yes everything has been turned off and I'm I'm quite impressed with this I think there's really a great opportunities to use these er and a genie modules in in PI home automation that's just a control C to come out of the code there I'm sure some of you will say this code could be it cleaned up a lot it could be a a bit more concise I'm sure it could but it proves a principle I think we've moved forward with another piece of hardware in our armory for a Raspberry Pi home automation in my first two raspberry-pi home automation videos I focused on different ways to turn mains appliances on and off and so in the next episode in this series I'm going to move on to look at the use of motion sensors and light sensors as GPIO triggers but now that's it for this video have enjoyed what you see there please beste title like button if you haven't subscribed please subscribe and I hope to talk to you again very soon [Music] you
Info
Channel: ExplainingComputers
Views: 82,175
Rating: undefined out of 5
Keywords: Raspberry Pi home automation, Raspberry Pi automation, Raspberry Pi, automation, Energenie, Energenie Pi-Mote, Pi-Mote, Energenie sockets, Energenie wireless sockets, Raspberry Pi wireless sockets, wireless sockets, Python 3, Energenie Python 3, Energenie sockets Python 3, Python 3.5, Pi-Mote Python 3, Christopher Barnatt, Barnatt, timer, time control, wireless socket timer, Pi automation, Pi wireless control
Id: UOmRuRywSY0
Channel Id: undefined
Length: 15min 17sec (917 seconds)
Published: Sun May 26 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.