Writing a Python Script to Control my Lights | Five Minute Python Scripts

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
lighting for YouTube videos is very important check out the difference in this and this turning on all these lights for YouTube videos is a lot of work so I wanted to build something to automate this I'm working with smart lights specifically the humans and with these lights you can control the hue and the saturation but you have to do this through an app unless you use Python so in this video I wanted to make a Python script to do this automatically so I don't have to turn on all my lights every time I want the film let's start out by seeing if anyone's already had the same problem we'll go Python hue lights into Google let's check this out it looks like someone has already built something that we can use to control our hue lights so we'll just use this pulling up a text editor and installing that package will install it whip it so it's called P you will just pip install that we downloaded it and it looks like we got it so now hold import PU well actually uh well actually take this from P he'll import bridge so we'll put that in and we'll do the connection IP of your bridge put that in here let's go and grab my IP address we'll call this one IP address dot PI and we'll just say bridge IP address the bridge is just what controls the lights so this is how we'll access it by using the IP address of the bridge I got the IP address of this bridge and I'll put this in here I'm gonna blur this out in the video that way you guys can torment me when my own lights so we'll save that we'll import that so from IP address import and then when we call it bridge IP address average IP address okay so now we can use this to access our bridge so we'll pass it in right here IP address all right so this should give us a connection to our lights then we need to actually call this connect function after we hit the button so I'll go hit the button real quick and then all we run connect all right we hit the button then let's run this Hugh live stop hi no IP address okay um wrong variable name here bridge IP address we'll save that and now let's run this again 30 seconds okay I'll be right back okay let's try this again run it no response so that means we're connected so we can get rid of this all right let's create a few functions so we can have some different settings on it light let's call one function film lights and use this we'll probably want to create an access function so let's say access lights will take this and move it in there and now also means we want the argument of the average IP address right here after this we want to be able to access all the lights so let's go see what their method is to access all the lights it looks like this we can get a dictionary of all over lights so we'll take this and put it into our access lights set ID let's work with the names and we'll call this light names list we want this access lights function to return this so let's say return light names light that should be list all right now let's set on left dumb lights we'll do that in this function we need to access those lights so we use the access lights function that we created above will pass in bridge IP address after that we need to change every light so let's say something like for light and lights will CLA access them here so we'll just take this copy it and paste it here won't change all of these to what we're actually using lights instead of light names this will probably be the most used function whenever I want to run this Python script so let's make it that if name is equal to main mortis run this function film lights all right let's execute this XS y is not defined okay Oh spelling here all right let's try this again XS light is not defined to spelling hairs all right all right so now we have access to you changing the light color let's change it to 5,000 and we'll do 100 on the saturation it's changing but it's not what we want 20,000 there we go so now we have access to changing all the lights in my house I don't know the specific colors or hue and saturation but I do know a few colors so let's create a new function we'll call this one danger mode and then this one will use the access line method to so access lights with the verage IP address and then let's say something like for lie in lights we'll copy this and let's say that there's an emergency going on and we want to flash these suckers red pretty sure red if what I'm reading is correct is 180 in 100 and then if we want to flash let's import a module called time so this will give us the ability to wait so we'll say time got sleep and then let's sleep one second this needs to be outside of our for loop and then let's do this again I think why is 7,000 all right let's try this don't change your main function to danger mode and execute that's good but we needed to flash so let's let's say while true and then will indent all of this over and then we want to sleep right here - all right this will give us an infinite loop but for the purposes of this it's okay [Music] yeah there we go and then if we wanted to go back to film lights let's go and say film lights well execute I just found this package and I thought it was cool so maybe you can use it maybe you can't but I hope you enjoyed the video thank you for watching if you have any suggestions for what we should build next please let me know until next time [Music]
Info
Channel: Derrick Sherrill
Views: 109,792
Rating: undefined out of 5
Keywords: Python, Python Automation, Tutorial, How To, Derrick Sherrill, Home automation, Smart lights, python Hue, phue, Smart Device, Smart Device Python, Python Programming, Programming
Id: kSruoqDTYt0
Channel Id: undefined
Length: 8min 15sec (495 seconds)
Published: Fri Feb 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.