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

Ғылым және технология

Let's automate some lights with python?
Kite helps fund the channel, thanks for checking them out and supporting me --
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. www.kite.com/get-kite/?...
Support the Channel on Patreon --
/ derricksherrill
Join The Socials --
Reddit - / codewithderrick
FB - / codewithderrick
Insta - / codewithderrick
Twitter - / codewithderrick
LinkedIn - / derricksherrill
GitHub - github.com/Derrick-Sherrill
*****************************************************************
Full code from the video:
from phue import Bridge
from ip_address import bridge_ip_address
import time
def access_lights(bridge_ip_address):
b = Bridge(bridge_ip_address)
light_names_list = b.get_light_objects('name')
return light_names_list
def film_lights():
lights = access_lights(bridge_ip_address)
for light in lights:
lights[light].on = True
lights[light].hue = 7000
lights[light].saturation = 100
def danger_mode():
lights = access_lights(bridge_ip_address)
while True:
time.sleep(1)
for light in lights:
lights[light].on = True
lights[light].hue = 180
lights[light].saturation = 100
time.sleep(1)
for light in lights:
lights[light].on = True
lights[light].hue = 7000
lights[light].saturation = 100
if _name_ == '__main__':
film_lights()
Thanks so much for all the continued support! You guys are awesome. Super thankful that I get the opportunity to make youtube videos for you all. I hope you enjoy this one - A bit different than what I typically put out, but just testing to see if it's a style that you all like. Let me know!
github.com/Derrick-Sherrill/D...
Packages (& Versions) used in this video:
PHue - github.com/studioimaginaire/phue
Time
*****************************************************************
Code from this tutorial and all my others can be found on my GitHub:
github.com/Derrick-Sherrill/D...
Check out my website:
www.derricksherrill.com/
If you liked the video - please hit the like button. It means more than you know. Thanks for watching and thank you for all your support!!
--- Channel FAQ --
What text editor do you use?
Atom - atom.io/
What Equipment do you use to film videos?
www.amazon.com/shop/derricksh...
What editing software do you use?
Adobe CC - www.adobe.com/creativecloud.html
Premiere Pro for video editing
Photoshop for images
After Effects for animations
Do I have any courses available?
Yes & always working on more!
www.udemy.com/user/derrick-sh...
Where do I get my music?
I get all my music from the copyright free KZread audio library
kzread.info...
Let me know if there's anything else you want answered!
-------------------------
Always looking for suggestions on what video to make next -- leave me a comment with your project! Happy Coding!

Пікірлер: 156

  • @matt-mx3ym
    @matt-mx3ym3 жыл бұрын

    My brain goes into danger mode whenever I don't see a semi-colon at the end of a line lmao

  • @iteratedofficial

    @iteratedofficial

    3 жыл бұрын

    I want to hurt people whenever I see no semi-colon.

  • @nomtijorti

    @nomtijorti

    3 жыл бұрын

    @pinto beans you don't need the semicolon with javascript. it's just best practice

  • @RobertRoman

    @RobertRoman

    3 жыл бұрын

    @@nomtijorti glad semi colons are slowly fading away

  • @nomtijorti

    @nomtijorti

    3 жыл бұрын

    @@RobertRoman if you say so. 🤷🏾‍♂️

  • @debasishkhan2165

    @debasishkhan2165

    Жыл бұрын

    True😂

  • @ashishsharma-pu6cx
    @ashishsharma-pu6cx4 жыл бұрын

    Hey Derrick, I just started my journey of learning python. After I came across your videos it has increased the enthusiasm in me. Now, I am highly enthusiastic to learn it. Thank you so much for your videos.

  • @gavnot6913

    @gavnot6913

    3 жыл бұрын

    how are u doing now with python?

  • @Dragon-Slay3r

    @Dragon-Slay3r

    Жыл бұрын

    Nice thanks

  • @josephlangford2912
    @josephlangford29123 жыл бұрын

    This video has aged well. It's super cool watching someone take an item in their house and showing the world how code can make even an easy-to-use product easier. I would love to see a "one year later" video where you take your original code and refactor/optimize it cheers!

  • @glorysonhorace3265
    @glorysonhorace32652 жыл бұрын

    Derrick thanks for these informative videos. Who else finds the way Derrick says the statement 'that way you guys can't torment me with my own lights' very funny. Especially the facial expression.😂😂

  • @CrispinValdezOfficial
    @CrispinValdezOfficial4 жыл бұрын

    Keep it up Derrick!! Thank you for the videos!

  • @Jmo-tj4fc
    @Jmo-tj4fc4 жыл бұрын

    Great video. Been watching quite a bit of your videos. Quick and concise.

  • @jarradt1185
    @jarradt11854 жыл бұрын

    Hey Derrick just wanted to say thank you, you've helped me so much in my coding journey so far. Loving the content, keep it coming!

  • @GovindSingh-vw8yx

    @GovindSingh-vw8yx

    3 жыл бұрын

    My big query plss solve how do i connect bulb to computer ✋✋✋

  • @brawlerwiki745

    @brawlerwiki745

    3 жыл бұрын

    @@GovindSingh-vw8yx yes my question too

  • @maserati4000
    @maserati40004 жыл бұрын

    this channel is like a little goldmine. easy to follow along scripts that you can write that you can post to github to show that you actually understand the python language and how it works.

  • @breadenthusiast
    @breadenthusiast4 жыл бұрын

    Great video Derrick! I found out what computer programming really was recently and decided to learn Python first. As I've learned more about the community and resources, I just keep getting more and more excited about the possibilities! Thanks for sharing! I think I'll scare my brothers with my own smart lights now, lol. I've always dreamed of having my own cool laboratory, where if there is an unauthorized breach danger lights will go off along with some kind of loud alarm sound. Maybe this combined with a Raspberry Pi might help accomplish that dream, haha.

  • @ramonmf4358
    @ramonmf43583 жыл бұрын

    Pretty cool, Derrick! Keep coding, bro... Regards from Brazil

  • @RonKirchner
    @RonKirchner4 жыл бұрын

    Helpful. Useful. Fun to watch. Thank you!

  • @shindersamra4020
    @shindersamra40203 жыл бұрын

    Sir you're inspiration to all programmers in my eyes thanks.

  • @nowyouknow2249
    @nowyouknow22494 жыл бұрын

    I enjoyed it Derrick 💪✌️

  • @pfuhad3760
    @pfuhad37602 жыл бұрын

    Your Videos are Awesome . I learned to move files using python yesterday from one of your video

  • @CurrentElectrical
    @CurrentElectrical3 жыл бұрын

    @0:22 the key to the world! This coming from your biggest electrician fan. :D

  • @Danny-qh4su
    @Danny-qh4su4 жыл бұрын

    👋 Hi Derrick, you have an excellent python channel, one of the best, in my opinion. For a future project, can you please show how to link this script with the Twilio package so we can control the lights from our phone? Thanks!

  • @trungduhuynh2154
    @trungduhuynh21544 жыл бұрын

    Open mind with your code... many thanks

  • @josephthecreator
    @josephthecreator2 жыл бұрын

    Awesome vid!

  • @primedynamixx
    @primedynamixx Жыл бұрын

    Great video!

  • @Android4LP
    @Android4LP4 жыл бұрын

    Good Video dude i like the Style

  • @sweetGemini31
    @sweetGemini314 жыл бұрын

    Hi Derrick, would you mind share the brand of your smart light?

  • @davetaylor7664
    @davetaylor76642 жыл бұрын

    This is exactly the stuff I want to be able to do, not to get a job, but just create cool stuff and be able to say aahh I programmed the lights to work that way :D

  • @brpawankumariyengar4227
    @brpawankumariyengar42279 ай бұрын

    Great Video ... Thanks

  • @NolanGerald
    @NolanGerald2 жыл бұрын

    Great tutorial! This code could easily be integrated into a desktop gui to control everything at the click of a button! Or even trigger this with a macro pad.

  • @Dragon-Slay3r

    @Dragon-Slay3r

    Жыл бұрын

    Thanks he's wealthy and healthy don't worry

  • @farhanahmed9032
    @farhanahmed90323 жыл бұрын

    Thanks bro it worked!!!!

  • @alpha_q5398
    @alpha_q53984 жыл бұрын

    bro you are the best plz keep it up🥺💞

  • @ElliyahuRosha
    @ElliyahuRosha4 жыл бұрын

    We miss u, dude

  • @smiths129
    @smiths1293 жыл бұрын

    Hey Derrick, this is really genius. Could you please let me know which light have you used in this video? I hv Wipro WiFi Smart LED. Can I simply use the IP address of the same smart device and use this code to control it?

  • @predutu
    @predutu3 жыл бұрын

    @Derrick, can you tell me some brands of smart bulbs I can buy so I can connect to them? I've seen from comments not all can be accessed. Thanks for the video

  • @absolut.0818
    @absolut.08184 жыл бұрын

    Thanks a lot for your content, Derrick. I really enjoy your videos. Perhaps this could be a dumb questing but how did you link your lights to the PC?

  • @UnbiasedYT

    @UnbiasedYT

    3 жыл бұрын

    using the ip address of the lights. He wrote that in a separate file.

  • @aryapraneil59

    @aryapraneil59

    2 жыл бұрын

    @@UnbiasedYT do lights have ip addressed? how?

  • @musicmelody3083
    @musicmelody30832 жыл бұрын

    Hi Derrick, I would like to write python script encouraged by your video to control smart bulb. I have a quick question: do I need to use mandatorily "Philips Hue Light" or can any other smart bulb like "Philips Wiz Smart WI-Fi LED Bulb E27 9-Watt, 16 Million colors , Compatible with Amazon Alexa and Google Assistant" be used instead? I believe this particular smart bulb does not fall in the category of "hue bulb".

  • @chronosoutoftime6685
    @chronosoutoftime66852 жыл бұрын

    Nice video, i have a few questions for you :) - do you have a green screen like elgato that you roll out or not depending on the occasion ? - can this work also for ring light that have a wireless remote like RGB Ring Light from 2LNF ? thanks

  • @MARTIN-101
    @MARTIN-1013 жыл бұрын

    coolll video mate. thanks.

  • @cybersoul_
    @cybersoul_2 жыл бұрын

    Hi Derrick, I'd like to know if I need a philips bridge to control my lights, actually I have a philips hue bulb in my house but I don't know if this script works for me. I'm making a virtual assistant with python here and I wanna put this feature in my assistant.

  • @nagapunitha3843
    @nagapunitha38434 жыл бұрын

    Cool video,Derrick! I just bought some xiaomi smart lights, and I'm gonna check out if I can apply this to them. On a side note, any tips on how you can share your computer screen as you as you are doing so on a video conference call?:)

  • @ayan5387

    @ayan5387

    3 жыл бұрын

    Did it work with Xiaomi smart lights?

  • @siddhantdeshmukh5595
    @siddhantdeshmukh55953 жыл бұрын

    How do we connect light to python can we connect any smart bulb to it like just a ordinary philips smart wifi led bulb.?

  • @joshuaperry7529
    @joshuaperry7529 Жыл бұрын

    "Let's go and grab my IP address. We'll call this one IP... address." 😂 Great video, thanks.

  • @bakarytrawally3630
    @bakarytrawally36302 жыл бұрын

    great guy i liked your lectures in python

  • @therabidpancake1
    @therabidpancake13 жыл бұрын

    It looks like you have a good idea of what you are doing . So my question is could you write like a structure for a python program. I mean I get that there are different programs that you can writ but is there possibly a general guidline ? I mean say like 5 basic steps for writing a particular typ of program .

  • @twiggygarcia5096
    @twiggygarcia50964 жыл бұрын

    Hey Derrick, I have been trawling the pandas documentation, stack overflow and the web to find out how to append a pandas data frame to excel. I have a function making an API call to get a bitcoin price, I grab the price and time and write it to the excel sheet but the next time my function loops it rewrites over the last price. any chance you know how this is done? the git hub says the documentation is going to be updated with examples but that was a while ago. Thanks in advance

  • @deepakdakhore
    @deepakdakhore4 жыл бұрын

    Very nice 👍 thanks

  • @NatureSymphonyTV
    @NatureSymphonyTV4 жыл бұрын

    That's totally Greek to me, wish i had your skills thou 🤗

  • @loli-chan7146
    @loli-chan71462 жыл бұрын

    How do I change a specific light only? Or how do I choose 2 or 3 lights only so that I could seperate my room color?

  • @meticulousmax8273
    @meticulousmax82733 жыл бұрын

    Derrick How to we find our bridge address ???

  • @kingsleyomon3158
    @kingsleyomon31582 жыл бұрын

    I could not find a python library for my smart light bulb. I have the boxlood smart light bulb. Please can you help with this? Or can you work me through a gain slowly?

  • @akashchugh7821
    @akashchugh78214 жыл бұрын

    Hey Derrick! Great one! Thanks for the video! :D Quick question, can I use the same for the normal lights in my room rather than only smart lights?

  • @CodeWithDerrick

    @CodeWithDerrick

    4 жыл бұрын

    Thanks! This works for smart lights because you're able to connect to them with their I.P. address, so over the internet. With regular lights you would need some way to "communicate" with them, so like a pi or something connected to the internet.

  • @CatStudios-qh3em

    @CatStudios-qh3em

    4 жыл бұрын

    @@CodeWithDerrick how did you do this? My lights is on the celling. Can I just put the code on a usb drive and then put it into the usb port on the lights? Thank you.

  • @MuhammadWaseem-mj3ge
    @MuhammadWaseem-mj3ge3 жыл бұрын

    If i can controll any light with this? Or some special computerized lights could me automated only?

  • @hadish9126
    @hadish91264 жыл бұрын

    Can someone help me ? I have install phue, but when i run my .py to connect the bridge the shell tell me "No module named 'phue'

  • @gajendrasonare
    @gajendrasonare3 жыл бұрын

    Can mobile's notification Led light be controlled by python?

  • @torque6389
    @torque63894 жыл бұрын

    Awesome!

  • @SimonSeabridgeSnookerCoaching
    @SimonSeabridgeSnookerCoaching9 күн бұрын

    Hi. I have OBS and would like a script that creates a text file from data received from a device via serial to usb. It is a scoreboard.

  • @vicamasteronweb2159
    @vicamasteronweb2159 Жыл бұрын

    Is it possible to turn on or off tuya light bulb by POST url from my Amazfit smartband?

  • @gbeck1065
    @gbeck10654 жыл бұрын

    So how is doing the algo trading? does it works for you?

  • @salikmalik7631
    @salikmalik76313 жыл бұрын

    great dude

  • @sonuaryan5813
    @sonuaryan5813Ай бұрын

    Is that work for Wipro smart bulb which is operated by alexa. Can I do with the same script ?

  • @farhatali2221
    @farhatali22214 жыл бұрын

    Awesome video..

  • @hannahvaverka6468
    @hannahvaverka64682 жыл бұрын

    This is awesome! I'm just starting coding, how do you start doing projects like this?

  • @ysrikar3625
    @ysrikar36254 жыл бұрын

    how does the light get on or off ?the light should be smart light?

  • @prith1990
    @prith19904 жыл бұрын

    Can you please make a video on how to convert a flat file without any delimiters into a pandas dataframe. You may know the position of each fields in thr dataframe.

  • @yaseenimuhammadraja9461
    @yaseenimuhammadraja94613 жыл бұрын

    Hai bro, Good and awesome video but one doubt that is, For light automation, some code you show only enough? No need any other equipment?

  • @brendanguhle5761
    @brendanguhle5761 Жыл бұрын

    Great video! Is there any way to integrate speech with this type of program?

  • @goktugerol1127
    @goktugerol1127 Жыл бұрын

    I got everything but how did you connect the light bulbs to your home network? 🤔

  • @MR0605
    @MR06053 жыл бұрын

    hi can i create an app for this code need in my phone that doesnt work on internet but as its own network

  • @noorieg3598
    @noorieg359811 ай бұрын

    How did you go about getting the bridge IP address? Got lost on that part

  • @werecow68
    @werecow684 жыл бұрын

    Where did you go? Looking for my Python Excel fix!!!

  • @sushmameena1748
    @sushmameena17483 жыл бұрын

    But how do you connect your lights with your pc or laptop???? Plz tell🙏🙏🙏🙏🙏

  • @abhishekghosh100
    @abhishekghosh1004 жыл бұрын

    Hi just wanted to know how you have connected the lights with your computer

  • @AntiRacistWarrior

    @AntiRacistWarrior

    3 жыл бұрын

    You are Indian man, we should be asking that question to you

  • @_qry

    @_qry

    3 жыл бұрын

    @@AntiRacistWarrior how does it have anything to do with where he‘s from, mr „anti racist“?

  • @joshalvarez298
    @joshalvarez2984 жыл бұрын

    Hello, Derrick I have a question I would love some help with. I have two documents one is a template and one is data from our system that prints out like "Student Info" "Course Info" etc. I need to take the data from the system and plug it into the template. The template has 10 sheets and the data from the system is only one sheet. Do you have some suggestions on how I can automate this process of copying the data from the system into the template using python? I'm butting my head against a wall. Thanks!

  • @CodeWithDerrick

    @CodeWithDerrick

    4 жыл бұрын

    Hey Deasvail 144, Tough challenge! Hard to say too much without knowing specifics. So the challenge is you have one sheet that has all the information and you need to use that information to fill out a larger document of 10 sheets? I'm guessing you're using word for this right now. I think python-docx & docx-template might be able to help with what you're doing. I'm honestly probably not the best reference for it, but did some searching to try to answer your question and landed on this blog post - blog.formpl.us/how-to-generate-word-documents-from-templates-using-python-cb039ea2c890

  • @joshalvarez298

    @joshalvarez298

    4 жыл бұрын

    @@CodeWithDerrick Sorry it is not a docx. The single sheet is a CSV. I then need to move the data to a 10 sheet excel file (.xlsx).

  • @shashanksingh5192
    @shashanksingh51923 жыл бұрын

    Hey Derrick, can you please tell me how you connect the lights with your code. Do we need some chip to install there or what. Can you explain little bit more?

  • @ambareen2368

    @ambareen2368

    2 жыл бұрын

    it only works with a smart light. You take the IP address from the smart light and put it in your code. Hope this helps

  • @relaxingwithmidfulmoment1177
    @relaxingwithmidfulmoment11772 жыл бұрын

    Hey Bro are you using the actual IP of the machine or different IP ? Pls help😐

  • @TheAnees35
    @TheAnees352 жыл бұрын

    Can you tell me name of bulb you have used in your video

  • @MR0605
    @MR06053 жыл бұрын

    How have you connected these lights are these smart lights

  • @andrewheckman2959
    @andrewheckman29593 жыл бұрын

    What light were you using?

  • @MakkerHeineken
    @MakkerHeineken3 жыл бұрын

    One for Dyson fan would be cool

  • @jaypatel2436
    @jaypatel24363 жыл бұрын

    Can you tell me how to find that ip of light source

  • @sudiptosadhukhan1580
    @sudiptosadhukhan15803 жыл бұрын

    Hey, Could you please help me out to get the ip address to control the lights.

  • @dhruvbhanushali9602
    @dhruvbhanushali96023 жыл бұрын

    Hee is your lights are the simple one just led bulb or your light are special one that come with option for it to get control with computers. ?????

  • @yaseenimuhammadraja9461
    @yaseenimuhammadraja94613 жыл бұрын

    You use any meterial like Arduino etc...???

  • @badkarma2175
    @badkarma21753 жыл бұрын

    im brand new to coding could somone please explain what he paste @ 0:45 and why? because i pull up my text editor and try to import pip phue and it will not let me...

  • @shubhamhajare1064

    @shubhamhajare1064

    3 жыл бұрын

    You will have to install pip for python first

  • @dinonwolf
    @dinonwolf3 жыл бұрын

    after finishing the coding, what should we do to the light/lamp itself?

  • @justins7796

    @justins7796

    3 жыл бұрын

    kinda depends on the light but generally want it physically switched on first, either in flashing mode or already paired with the app. After that you should have free rein to power it off remotely from that point on

  • @robetkeren5390
    @robetkeren53903 жыл бұрын

    derrick what tools do you use to connect from the computer to an object that can light up?

  • @joegibes

    @joegibes

    3 жыл бұрын

    Not OP and this is old, but he has Philips Hue lights which can be controlled on the network or over the internet. The lights wirelessly connect to the "Hue Bridge" box which is connected to the network.

  • @naveedkhan-wu3eq
    @naveedkhan-wu3eq4 жыл бұрын

    Hi bro can you teach how to plot bayesian statistical model in python

  • @mohammed_Ansar
    @mohammed_Ansar3 жыл бұрын

    How coding in python can make changes in lights? How is connected to each other

  • @rajusurya39
    @rajusurya393 жыл бұрын

    I have tried connecting my Wipro Smart LED bulb, unable to access it - ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it. Can you please help..

  • @AnuragVarmaP

    @AnuragVarmaP

    3 жыл бұрын

    did you find any alternative for wipro bulbs ? same issue !

  • @sayandas179
    @sayandas1793 жыл бұрын

    How do u connect with the light

  • @kalyanirajalingham1286
    @kalyanirajalingham12863 жыл бұрын

    def Superb(): print("wowie. You're good.) Superb()

  • @Lonetraderr
    @Lonetraderr4 жыл бұрын

    I suggest to create a script that will be clicking your ads to generate money for you :)

  • @Xlarge_t-shirt
    @Xlarge_t-shirt3 жыл бұрын

    Good shit

  • @FluffyMikan
    @FluffyMikan3 жыл бұрын

    How to get the bridge ip address?

  • @jameskwok339
    @jameskwok3393 жыл бұрын

    Can I use this :www.amazon.com/dp/B07QV9XB87/ref=cm_sw_r_cp_apa_i_rsCwFb6XSCXQT Just the light bulb to play with? Or do I need a hub in order to play with ip address?

  • @robertcliffort2354
    @robertcliffort23542 жыл бұрын

    great.

  • @TMLA001
    @TMLA0012 жыл бұрын

    what is a bridge ip address and please give me an example

  • @krishnasowjanyapallem5862
    @krishnasowjanyapallem58623 жыл бұрын

    Can any one tell me how to link this program to lights?

  • @ujjwalraj5367
    @ujjwalraj53673 жыл бұрын

    Which streaming app is he using?

  • @aloismusiiwa3042
    @aloismusiiwa304210 ай бұрын

    whats the name of your light i want to purchase mine

  • @ravikawalkar934
    @ravikawalkar9343 жыл бұрын

    How do I learn python so fast plz reply and which laptop should I buy plz suggest from India

  • @TheTony0h
    @TheTony0h3 жыл бұрын

    I have the same lights and bulb

  • @mbogitechconpts
    @mbogitechconpts3 жыл бұрын

    Great

  • @thisarajayanath4442
    @thisarajayanath44424 жыл бұрын

    How to subboting with python ? Plz explain

  • @shubhamchoudhary5461
    @shubhamchoudhary54613 жыл бұрын

    Are you using rasaberry pi..?

Келесі