How I Automate My Morning Using Python

Have you ever looked at the ceiling in the morning, terrified of the mountain of upcoming routine? And I did this often. Until one day I snapped. I decided to automate all my morning routines using Python, and the results were truly amazing.

Point of no return

This Wednesday was particularly tense. The alarm clock treacherously did not go off, I spilled coffee on my last clean shirt and missed the bus, which is why I arrived at an important meeting later than expected. The thought flashed through my head: “Will I really have to live like this my whole life?” This was that milestone. The endless chaos of the morning had driven me to the edge, and I decided that I needed to regain control of the situation.

Idea

My idea started as a joke from my friend Sam. We were chatting over coffee, and he casually remarked: “It would be great if you could program the morning so that it goes by itself.” We laughed, but the idea hooked me. Why not? I was pretty good at code. I have performed automation of small tasks more than once. Will it be possible to automate the whole morning?

First steps

The very next day I started brainstorming. What annoys me most in the morning? Making coffee, choosing clothes, checking the weather, making a schedule, and so on. I made a list and realized that with the help of a couple of scripts I could get rid of these annoying misunderstandings.

Shedding light

Next I thought about lighting. I read somewhere that the right light can have a significant impact on your mood and energy levels. So I bought a set of smart light bulbs that could be controlled using Python.

Photo by Mostafa Safadel on Unsplash

I wrote a script that gradually increased the brightness of the lights in the bedroom, simulating a sunrise. Now, even on the gloomiest winter days, it was as if I woke up with the sun.

from phue import Bridge
import time
def gradual_light(bridge_ip, light_id, duration):
   bridge = Bridge(bridge_ip)
   bridge.connect()
   for brightness in range(0, 256, 5):
       bridge.set_light(light_id, 'bri', brightness)
       time.sleep(duration / 51)  # There are 51 steps from 0 to 255 in increments of 5
gradual_light('192.168.1.2', 1, 600)

Synchronizing the schedule

Photo by Behnam Norouzi on Unsplash

Having sorted out the light, I turned my attention to my daily routine. I needed a way to quickly get an overview of my to-do list without having to check multiple apps at once. I wrote a script that took my schedule from Google Calendar and read it out loud using a text-to-speech library.

import os
from google.oauth2 import service_account
from googleapiclient.discovery import build
import pyttsx3

def get_events():
    SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
    SERVICE_ACCOUNT_FILE = 'path/to/your/service-account-file.json'
    credentials = service_account.Credentials.from_service_account_file(
            SERVICE_ACCOUNT_FILE, scopes=SCOPES)
    service = build('calendar', 'v3', credentials=credentials)
    now = datetime.datetime.utcnow().isoformat() + 'Z'
    events_result = service.events().list(calendarId='primary', timeMin=now,
                                        maxResults=10, singleEvents=True,
                                        orderBy='startTime').execute()
    events = events_result.get('items', [])
    return events
def read_schedule():
    events = get_events()
    if not events:
        text="No upcoming events found."
    else:
        text="Your schedule for today:"
        for event in events:
            start = event['start'].get('dateTime', event['start'].get('date'))
            text += f"\n{start}: {event['summary']}"
    engine = pyttsx3.init()
    engine.say(text)
    engine.runAndWait()
read_schedule()

Automating coffee

Photo by Tyler Nix on Unsplash

First of all, I decided to close the issue with making coffee. To do this, I purchased a smart coffee maker that can be controlled using my phone. I then wrote a Python script that used a library that interacted with the coffee maker API. Every night before I went to bed, I set my alarm and ran a script that started brewing coffee ten minutes before I woke up. This seemingly small change allowed me to wake up to the smell of fresh coffee every morning. Small, but a miracle.

import requests
import time

def brew_coffee():
    # Replace with your coffee maker's API endpoint and access token
    api_url = "http://smartcoffeeapi.com/brew"
    access_token = "your_access_token_here"
    
    headers = {
        "Authorization": f"Bearer {access_token}",
        "Content-Type": "application/json"
    }
    
    response = requests.post(api_url, headers=headers)
    if response.status_code == 200:
        print("Coffee is brewing!")
    else:
        print("Failed to start coffee maker.")
# Set this script to run 10 minutes before your alarm
brew_coffee()

We automate the wardrobe

Photo by Huy Nguyen, Unsplash

The next step was to sort out the wardrobe. Choosing an outfit was always difficult for me, since half of my clothes were always lying in a heap all over the floor. I installed a camera in my closet and wrote a script that would take a photo of my closet every morning. Then, using basic object recognition, the script would suggest clothing options for me based on the weather and my schedule for the day.

import requests

def get_weather():
    response = requests.get("http://api.weatherapi.com/v1/current.json?key=your_api_key&q=your_location")
    weather = response.json()
    return weather['current']['temp_c'], weather['current']['condition']['text']
def suggest_outfit(temp, condition):
    if temp < 10:
        return "Warm coat and scarf"
    elif 10 <= temp < 20:
        return "Jacket and jeans"
    else:
        return "T-shirt and shorts"
temp, condition = get_weather()
outfit = suggest_outfit(temp, condition)
print(f"Today's weather: {temp}°C and {condition}. Suggested outfit: {outfit}")

To do this, I wrote a script that checked the weather and suggested appropriate clothing. To be sure of the practicality of the proposed options, I even entered data about my wardrobe.

import cv2
import numpy as np
import requests

def capture_wardrobe_image():
    camera = cv2.VideoCapture(0)
    return_value, image = camera.read()
    cv2.imwrite('wardrobe.jpg', image)
    camera.release()
    cv2.destroyAllWindows()
def suggest_outfit():
    # Replace with your image recognition model API
    api_url = "http://outfitsuggestionapi.com/predict"
    image_path = "wardrobe.jpg"
    
    with open(image_path, 'rb') as image_file:
        files = {'file': image_file}
        response = requests.post(api_url, files=files)
    
    if response.status_code == 200:
        outfit_suggestion = response.json()
        print(f"Suggested outfit: {outfit_suggestion}")
    else:
        print("Failed to get outfit suggestion.")
# Capture wardrobe image and suggest outfit
capture_wardrobe_image()
suggest_outfit()

Weather and schedule updates

Photo by Andre Benz on Unsplash

Speaking of weather. I wrote another script that retrieved the latest data from the online API. He then compared the weather forecast with events on the calendar for that day. If it was going to rain and I had an appointment on the other side of town, he would send me a reminder to bring an umbrella. If it was sunny and I didn’t have any meetings, the program suggested choosing a more casual outfit.

import requests
from datetime import datetime

def get_weather():
    api_url = "http://api.weatherapi.com/v1/current.json"
    params = {
        "key": "your_weather_api_key",
        "q": "your_location"
    }
    response = requests.get(api_url, params=params)
    return response.json()
def get_schedule():
    # Replace with your calendar API
    api_url = "http://calendarapi.com/events"
    params = {
        "access_token": "your_calendar_access_token"
    }
    response = requests.get(api_url, params=params)
    return response.json()
def send_reminder(message):
    # Replace with your preferred notification method
    print(f"Reminder: {message}")
# Get weather and schedule
weather = get_weather()
schedule = get_schedule()
# Decision logic based on weather and schedule
if weather['current']['condition']['text'].lower() == 'rain':
    send_reminder("It's going to rain. Don't forget your umbrella!")
else:
    send_reminder("No rain today. Dress comfortably.")
for event in schedule['events']:
    event_time = datetime.fromisoformat(event['start_time'])
    if event_time.hour < 12:
        send_reminder(f"Morning event: {event['title']} at {event_time.strftime('%I:%M %p')}")

Breakfast and other troubles

Photo by Look Studio, Unsplash

Breakfast is another major issue. I often skipped it or snacked on something unhealthy on the way to work. So I developed a script that communicated with a smart refrigerator and pantry inventory system. It kept track of what foods I had on hand and suggested recipes based on my preferences and nutritional needs. I also programmed the blender to start making smoothies as soon as I got out of the shower.

import requests

def get_pantry_inventory():
    # Replace with your smart pantry API
    api_url = "http://smartpantryapi.com/inventory"
    response = requests.get(api_url)
    return response.json()
def suggest_recipe(inventory):
    # Replace with your recipe suggestion API
    api_url = "http://recipesuggestionapi.com/suggest"
    response = requests.post(api_url, json=inventory)
    return response.json()
def start_smoothie_blender(recipe):
    # Replace with your smart blender API
    api_url = "http://smartblenderapi.com/start"
    response = requests.post(api_url, json=recipe)
    if response.status_code == 200:
        print("Smoothie is being made!")
    else:
        print("Failed to start smoothie blender.")
# Get pantry inventory and suggest recipe
inventory = get_pantry_inventory()
recipe = suggest_recipe(inventory)
print(f"Suggested recipe: {recipe}")
# Start smoothie blender with the suggested recipe
start_smoothie_blender(recipe)

Workout Reminders

Lastly, I set myself workout reminders. I wrote a script that uses the Twilio API to send text messages to remind me to exercise at 8am.

from twilio.rest import Client

account_sid = 'your_account_sid'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)
message = client.messages.create(
    body="Time to work out!",
    from_='+1234567890',
    to='+0987654321'
)
print(message.sid)

Implementation

When the scripts were ready, it was time to test them in practice. I combined them into a single, holistic morning program. I created a master script that controlled all processes – from ringing the alarm to brewing coffee and choosing a suit.

import threading

def morning_routine():
    alarm_thread = threading.Thread(target=play_alarm)
    coffee_thread = threading.Thread(target=brew_coffee)
    weather_thread = threading.Thread(target=get_weather_and_suggest_outfit)
    alarm_thread.start()
    coffee_thread.start()
    weather_thread.start()
    alarm_thread.join()
    coffee_thread.join()
    weather_thread.join()
def get_weather_and_suggest_outfit():
    temp, condition = get_weather()
    outfit = suggest_outfit(temp, condition)
    print(f"Today's weather: {temp}°C and {condition}. Suggested outfit: {outfit}")
morning_routine()

Result

The first morning I tested the system was nerve-wracking. What if something goes wrong? But everything worked like clockwork. The alarm clock turned on my favorite song at 7 am. I rolled out of bed, and five minutes later the apartment was filled with the smell of freshly brewed coffee. I sat with a mug and listened to the computer read out the latest letters to me. By the time I finished my coffee, I knew exactly what my day would look like, and at 8 am I received a text reminding me to exercise.

I was delighted. This not only made it easier for me to wake up, but also made me more productive. I had more energy and focus because I didn't have to waste energy on routine tasks.

A spoon of tar

However, not everyone was happy with my new lifestyle. Some friends thought I was crazy. “You let machines control your life,” they said. “What if something goes wrong?”

One morning a girl made a real scene for me. “Look, I know you love your technique,” ​​she began, “but don’t you think you’re taking it too far? What happens if your internet goes out or your scripts break? You will disappear!

She was right. I became very dependent on the system. The point is that system failure is not a matter of “if”, but a matter of “when”. To reduce risks, I have provided backup options. If the coffee maker did not turn on, I received a notification and could start it manually. If the wardrobe camera failed, I had a list of ready-made outfits from which I could choose the one I needed. Weather forecast script? Well, if necessary, I could always manually check the forecast on my phone.

Conclusion

Automating my morning routine with Python was more than just a fun experiment—it changed the course of my life. She showed me the value of automation and how technology can improve our lives in unexpected ways. Of course, this may seem like overkill, but for a person like me, this is just the perfect option.

To be honest, I'm not going to change anything. Every morning, with a few lines of code, I can start my day calmly and stress-free.

So if you're tired of your morning routine, why don't you give it a try too? Grab a laptop, write a few scripts, and let Python do the rest. You might find that a little automation is great.

I hope you found this article helpful. Thank you for taking the time to read it.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *