 Thank you. Completely unnecessary. All I did was walk from there to there. It's not difficult. So as this part of the slide says, my name is Steve, and as that part of the slide says, I'm a little bit of a geek. This bit is not as simple as you think. Home automation is actually quite simple. You do a thing, a light comes on. Simple. What I'm going to talk about is the bits which are a little more difficult which sit around that. So if anyone wants some pithy thing to tweet, that's your tweetable phrase for the day. Home automation is just something your house does for you, blah, blah, blah. My homes have actually been automated for the last 15 years. It's really interesting and it's really annoying. It's not something you can just do. My home is special to me. It's mine, it's not yours. Even if I give you all the software, and it's available, it's open source, you wouldn't be able to take it and just stick it in your home. We all have different lives, they all handle different ways. So we look at some of the context and the problems that that brings about. Now, this is a basic system. We don't need to read anything. All you need to realize is there are inputs, there is processing things, and there are outputs. So you might have a message that comes in via text that says, I want to record this program later. That was one of the very first things I built. Now, this is 15 years ago, so it was an infrared LED that would actually fire signals to the video recorder via a text message to say, I'm in the pub, someone's told me about this program that's on tonight, I can't get home to record it, I don't have a TV card, there's no drivers for Linux, I'll send a text message and record it. A little bit overkill just to watch TV, but I don't have a life, so it worked. Inputs, process, outputs. This stuff is very easy to build. But that's not the difficult bit. Hardware, also not the difficult bit. We can go away and we can buy plugs and sockets and light bulbs that we can connect that have their own IP. Light bulbs having their own IP address. Who'd have thought that would ever happen? But it's not difficult. We go around, we spend our 30 euros and we buy something. Not difficult. E-mailing a light switch. Also not that difficult. Little prock-mail script. Bang, done. Has anyone emailed their light switch? Yeah, fair enough. But you can do it. It's really quite simple. This is all it takes. You have a little basic script that just says, OK, switch light on, switch light off. But that's not where the difficult bit is. The difficult bit is what comes after. Are you then authenticating this email in some way? Although we probably should all PGP sign our emails, we probably all don't for most of the time. If you are sending it, if I'm sending that email, the server picks it up and goes, oh yeah, this is obviously from Steve. I'm allowed to switch this light on. Well, that can be faked. You can spoof those email headers without too much trouble. What if my partner wants to send an email to the light? Would it work for them? How do I implement that bit of the system? That's another thing to handle. I showed you three different sockets just then. I think I've got three light bulbs coming up on another slide. Well, the thing you need to do to make the Philips light bulb turns on is different to what you need to do the LIFX bulb and so on. So you need to add an extra layer of abstraction in that says, they've said turn the bedroom light on. What type of light is the bedroom? Is that a hue one? Is that a LIFX one? Is that an X10 one? So you need to add an extra layer into there. So it's code. It's a little more work, but you can get there. And then you have the problem. What is turning it off? It seems simple. Turn the light off. But the important thing which is sort of the crux of most of this is what is the context for turning that light off? If I say turn the light off and I do it via my phone, does that take priority over the light switch on the wall? If I say turn the light off, does that have priority over the person that might be in the room? Am I turning it off for my phone just because I happen to have my phone out? Am I doing it because I am in another location and I've forgotten to turn the light off? And I'm using it that. Am I turning the light off because it's the kid's room and the kid should not be up at that time at night and I'm forcing them to turn the light off? Or am I turning it off because I just want the light off? Consider that timeline. Human comes into the room, they turn the light on. They obviously want the light on. They're looking for something. They want to do something. The machine says, oh, right. My schedule says we should put the light on now. We tend to scale off burglars by putting the light on exactly the same time every single day. Fair enough. The machine turns the light on. The machine says, oh, my schedule says turn the light off now. It turns the light off. At that point, should that light be on or off? The machine says, I've been told to do this. The machine has been told by a programmer that is moderately sensible, me, that it should turn the light off at half nine every day. But if a human has turned it on in the interim, should that human have priority? And which human? If it's me, if it's a kid, if it's the partner, which one of us has priority over which lights should be on or off depending on the schedule? And the answer is there isn't an answer. It changes for every single person's house and situation. Sorry about that. No answers. So media playback. This is one of the very first things I did in home automation. It was very simple. I couldn't hear the TV from the kitchen, so I ran some cables. I then started running network cables and AV cables, so the whole house was media rigged. I've got big media server, all the music's on there, play it anywhere. Who needs a sonos? I can do this with a Raspberry Pi and a mini ITX box. But I connected a few things up and the doorbell. When the doorbell goes, the volume goes down on the music just so I can hear the doorbell and work out if I want to answer it. You could also change that so that if the doorbell goes, the volume goes up so you can't hear them so you don't have to talk to your neighbors. But how do you code changing the volume? I'm serious. How would you code changing the volume? Get volume, do something in some way and then set the volume again. But that doesn't work. The volume is always going to be capped. I'm using 0 to 100 just as a simple percentage thing. You start at 95, you add 10. That's 105, but it's capped to 100. And then when you lower the volume again, it goes back down to 90. Two operations that should be reversible are not. The same is true when you underflow. It's quite a low volume, say it's at 5. You subtract 10, it's at 0 now and cropped. And then when you increase it again, it goes to 10. That's not what's expected. You could say, well, let's go above 100. Let's have a temporary store in like VALOG MyMixer. It says, even though the actual mixer itself is capped to 0 to 100, I want it to be whatever you can be. So it's like volume up 10, volume up 20, 30, 40, 50, 60, 100. 110, 120. Now you've got to press down three times before you hear any difference whatsoever. That's also wrong. So there's two possibilities of doing volume and they're both wrong. The answer is there isn't actually a right answer. Volume itself is a logarithmic scale. You've probably heard of decibels being used as just like a thing for loudness. That's logarithmic. So a volume increase of 1 at 80 is not the same as volume increase of 1 at lower numbers or higher numbers. So maybe you write code like this. Depending on how loud it already is, volume up will be a different amount for the actual volume. And that's fine some of the time. Because volume up is not volume down and it's not symmetric. No way near. These are all the problems because there is no context in you pressing volume up or volume down. Why are you turning it down? If it's too loud to the last track, it's just a case of if you've got a lot of music and you're jumping around, they're all mixed differently. All the songs are mixed differently. They've got different loudnesses. So you might just say, well, that one was mixed in a way that is too loud for me right now. I want to turn it down, but the next song you want to turn it back up. But again, because it's not symmetric, you might find the next song ends up being too loud. You're turning it down because there's an advert or the doorbell. All reasons for turning it down are different. But you're certainly not going to make it remote control that says volume down because of doorbell. Volume down because this is a loud song. Volume down because I don't like this advert. They're all different. They technically should have a context, but we don't have a way of getting context into the system. The same is true for turning it up. Again, hiding the noise from the washing machine. That is a real world life case where my washing machine would basically make a racket and trundle on the ground. I wanted to wipe that out with some music. That's the different meanings of turning it up and I really want to rock out to this bit in the middle about who mean rapidly. And again, we still have the problem of what user? Is this me turning it up? I like loud music, so sue me. Actually, technically you can sue someone if they're playing loud music and you live next door, but don't. I like loud music. The other half? Not so keen on loud music. So when I say volume up, I mean volume up, rock on. They mean, can we just have it a bit louder than the washing machine, please? So it's, again, depending on the context. Me wanting it up is different to them wanting it up and so on. And if the computer has been controlled to say you can turn the volume up, the computer has no idea about that context. It doesn't know if you're turning it up for whatever reason. So what about the song itself? I have fairly obvious music tastes. So which of these three options do you think we should use? Got a massive directory full of music. Do I pick a random directory? Go into the subdirectories until I find only songs and then play a song at random from that list. That'll be a nice way of playing a random song for me. Just shuffle play. Do I do the same as before, but if there are songs and subdirectories, I pick one randomly? Or do I just list all the songs throughout the entire hard drive from one to a million say and then pick one number from that and play that song? Which is the best way to do a shuffle? The answer is A, B and C. They're all brilliant and they're all broken. Whichever way you do it, there will be a bias to some way. So I've ordered all my music in alphabetical order. A through to Z, which means there's a 1 in 26 chance of having an artist called A. That's pretty good. A is my toyamos. There's lots of toyamos in there. Happy for that. But there's also a 1 in 26 chance. I'm going to get Z, which is Zuccaro. Happy with Zuccaro, but I only want to listen to that album once every 10 years. But there's a 1 in 26 chance on an equal chance of hearing that and there is toyamos. In my cue directory, I have Queen. I have Queen's wife and quite right. Not a lot else. So I've got 1 in 26 chance of finding something by Queen. That's not a very good shuffle algorithm, particularly when you realize I've got 20 Queen albums. I've got everything they've ever done. So it's not a very random shuffle. But you can't do it any other way because if you say, well, I'll, you know, using example B from there, it's biasing on some minor tracks. Even Queen wrote some absolute rubbish occasionally, which means there's an equal chance of you getting Sweet Lady being played as there is another one by Stardust or something. So if you do that other algorithm, you're going to end up with some complete junk and you're thinking, why on earth am I letting the computer choose my music for me? And the last version, it bars towards artists with a lot of songs, using the Queen example. So we can do that, but we also want to ignore certain songs. Again, I'll use Queen as example. I do like the Hymn Rhapsody. I just don't want to hear it. It's been played so much, it's gone. It's five minutes, 53 seconds, it's great, but don't want to hear it too long, too worn out. I want to ignore that song. But how long is long? How do you specify that? What about the Adagio in, I have a lot of classical stuff, really don't want to hear that most of the time unless it's in the context of the symphony. So how do I say I want to ignore that bit most of the time? Again, this is a context thing. It's about me and my relationship with the machine rather than what the machine thinks it should be automating. Also, if I'm saying, give me a random shuffle playlist, I don't want it to start going, oh, there's a comedy file in here, I'm going to play the comedy. I have lots of recorded comedy, fine. But that's not a music shuffle thing. I don't want to suddenly be rocking away to something or other and then all of a sudden I get, yes, I am El Westi, it was a very, you know, it's just not going to work. Does anyone ever remember Peter Cook and Dudley Moore? Just, just, yeah. I wasn't going to say it. But for the purpose of the recording, he said just old people. So you want to ignore the comedy. You also want to ignore Pink Floyd most of the time. Pink Floyd, no. Careful, I'll tell you when I'm doing the funnies. Pink Floyd, I do have most of their stuff. I like most of their stuff, but it's the sort of music I want to sit down and listen to. It's not something I want to hear in the background. It's something I will make in concertative effort to say, like, no distractions, I am now going to listen to Pink Floyd. I want it on my server. I want it being played to whichever room I happen to be in, but I don't want it to be randomly picked in the middle of a Queen thing, a Torrie Amos thing and a Pet Shop Boys thing. It's a particular thing. But that's my taste, which means I have to program very specific things to a very specific system to ignore particular songs in particular circumstances. There might be a reason home automation is not as popular as perhaps it should be. Too much right. So you also should rant this stuff. One thing that you think random is random. It's not, we've seen in the previous talk, using the audio to do a proper randomness. Randomness is pseudo-random. And I've accidentally stumbled on the fact that the Linux random number generator is awful, and I ended up getting the same four or five songs in the same order despite the fact I was using random to try and pick random songs. So you've got to add extra randomness in there. You've got to seed it so that you actually get a nice shuffle. Oh, and also skip the songs that have been played recently. You don't want the same thing played four times and the random number generator happened to do that. So all these things have to be added in to something as simple as pick a random song. It shouldn't be that difficult. The code isn't difficult. It's the using it, which is difficult. So I also need to think of mood changes. Again, this is another real world case because for some reason, my random number generator and my system thought that eight o'clock in the morning was a really good time to play skinny puppy, which some people who are laughing will know is industrial music with lots of clanking and ranging guitars and lots of other stuff. It's not an eight o'clock in the morning thing. So you have to program this sort of understanding into the machine. And as we're saying, the distribution of artists and letters, lots of people sort of queen. So when I say ignore song because it's too long of that, again, you need the context. A simple interface that says, don't play me that song for a while. It has to be based on who is doing it. Am I saying don't play the song? Am I saying don't play the song? Why am I saying don't play this song? Time of year. Yeah, fine. If it's Christmas time, let's hear Naughty Holder scream, it's Christmas. But not February. Not July. But it's something else you got to code into the system, which you probably won't code into the system when you're writing it. It's something that comes afterwards, you know, situation. Yeah, I certainly don't want to go home or something and it suddenly starts playing break up songs. I need some way of tagging this stuff. And similarly location. So, you know, yeah, no loud, crunchy stuff eight o'clock in the morning. So, yeah, we can't, the problem is we can't get context easily. We can try and we can try and infer it, but it is still a hard problem. In home automation, the biggest problem in my humble view is the multiple occupancy problem. If there are two people in a room, how do you determine who those two people are and which of them is in control? Who there is actually trying to do the thing? You know, you can do motion sensor. You walk into the room, motion sensor puts on lights. Fine. But when that person walks out but another person walks in, how do you keep the lights on? You know, the clues in the title, motion sensor. I walk into the room, I sit down. It spots my motion, it puts the light on. I sit down for long enough, it turns the light off. It has to wait for someone else to walk into them before that comes on again. That doesn't work. You can use Bluetooth to detect users. One thing I tried a while back was having the Bluetooth on my phone on the whole time and it could work out where I was and it would control the music according to where the Bluetooth signature was. Fine, but it wears your battery down. There's no good solution. And the ignore list that I had earlier, you know, do I ignore this song because of who I am, where I am, what time of day it is, is it a Christmas song or not? Is this an all or an and relationship? And how complex is that and an all relationship? It could be don't do it if it's Steve and it's Christmas or don't do it if it's that or don't do it if it's eight o'clock. That logic is very specific to each person and each home. So it would have been nice to have some answers. It would have been nice to end on a nice positive note saying home automation is great and we should all be doing this and this is the future because we have these computers. We might as well do something useful with them but there are no rules. There are no solutions to this. We were talking earlier and I call it the configuration calibration problem. At one end, you've got things like the Mac. You press one button and it does everything for you and it's great if everything it does is the thing you want it to do. On the other end is the Linux side. If it doesn't do what you want to do, there's a million and one configuration options and if you still don't like it, you can recompile the code and put the configuration options you want in. Somewhere in the middle is your life. Your life is complex. Everybody's life is complex. It's quite astounding how complex and different everybody's life is but when you're building these home automation systems you end up having to build it for yourself and even if you give people the code it's going to be very difficult for them to configure it in the way that is suitable for them. I really haven't finished on a positive note. To be on a positive note, but with open source we can because with open source we can make it do what we want. We are in the technical elite. The very fact that you're here means you're in that group. Whether you like what I'm talking about or not, it doesn't matter. We're all in a position where we can recode these things. We can make our houses do what we want even if it takes us 27 lines of code to ignore the right song at the right time when we don't want to hear it. I've probably got five minutes for 51 seconds for questions but before I do I'll update this scorecard. There we go, done. Time for questions? Yes, absolutely. That's one at the back. Okay, so the question is how much effort is required to keep up with changing external APIs? And the answer is not a lot. I've got a number of APIs. I've got weather ones. I've got train timetables and that sort of thing. But there are comparatively few of them. There are a number of APIs. I've got weather ones. I've got train timetables and that sort of thing. But there are comparatively few of them. When you start home automation stuff you think I'm going to do all of this thing. And after a while suddenly realize actually I only use about four features. Yes, I'll use the train timetable. I will use the weather thing occasionally. I don't really notice it. I have something in my house called a window. And if I look out the window I can see what the weather is like. I've got the weather API. It does its thing but I generally don't notice it. If it broke and it just put the default sunshine picture up, actually I live in London so the default picture is rain. So if it just put the default picture up I probably wouldn't notice for a year. So I wouldn't have to update it. But it's a comparatively small amount of work. By the way, the books up there, they do have my name on it but I get so little involved I don't bother buying them. Buy me a beer and I will tell you everything that's in the book. It'll be cheaper for you and I'll get something good out of it. So I just do them to prove that I have done something in my life. By the way, I hope the publisher is not watching this. They'll hate me for it. It's recorded now. Right, what are they going to do? So we have... No, that wasn't a question. Yep, we've still got a couple of minutes for questions. Because if not, I just start talking. Yes? Did you try to automate the part of the groceries ordering so that you can come on the list when you ultimately are supposed to do the grocery order So the question is have I automated grocery ordering? And the answer is I actually did that as a day job a while back. So if you see on BBC Good Food, you sort of see a recipe you like, you click buy and it puts all those things into your shopping cart. Yeah, I ended up part of the team that built that. So there's no way I was going to do it in HA. It's actually quite a complex problem, not because of the technicalities of doing that API. It's the fact that it isn't an API. So you end up screen scraping and having to force stuff in. The better way I found of doing that is to not worry about the shopping part of it, worry about the procurement of the list. So you have a thing which says this is my shopping list and you have... I use slack of it, I also use Trello. So I'm able to send a message to a Trello card which is called shopping list and every time I send a text message to my special number it adds it onto the Trello card. So at the supermarket I bring up the card and it's there. Something I did a while back which is not in the current implementation is with barcodes. Everything now has got a camera in it. It's very simple to have a tablet on your fridge. You scan the barcode and because you generally only buy a set number of things, you know the type of milk you buy, you know the type of bread, you can program these things in quite simply. You scan the barcode, it says, all right, they've taken this out of the fridge, they haven't put it back, therefore need more milk. And that barcode goes to the same Trello card. It's a very simple thing to do and it gets you a lot more home automation for a comparatively short amount of time. Yeah, you could spend months and months and months working with the external API, waiting for the external API to change at your grocery store. But all you actually need is just to know what those things are. So the question, what are my plans when I'm on vacation? Oh, I don't have plants. The reason I don't have plants is because they all died when I was on vacation and I forgot to water them and I didn't build an Arduino to water them for me. But if you invite me back next year, maybe I'll build a plant watering system instead. I also don't have any cats. But that's because they all died because I didn't feed them when I was on vacation. Question, Deb. So you mentioned all these problems trying to pick up the perfect song which I made with my friends. There's no solution to them. How far did you manage to take it? So how was your automation for picking the best songs when they were daylight? So the question, how far did I go with the algorithm for picking the best song? And I stopped when I got board coding. As you might have noticed, I could probably spend the next few years trying to build the perfect algorithm to find the perfect song for the right situation given time, time of day, time of year, people in the house and everything else. I ended up doing a basic randomization. I put in an extra couple of rules just saying don't do too many things in the queue directory and ignore Zocero and everything will be fine. I could have spent a lot more time at the end of the day I have a button that says skip. It was easier to implement a button called skip than it has been to try and better that algorithm. So my time is up. Thank you for your attention and good night.