0
0
Raspberry Piprogramming~30 mins

Why automation runs tasks without human intervention in Raspberry Pi - See It in Action

Choose your learning style9 modes available
Why Automation Runs Tasks Without Human Intervention
📖 Scenario: Imagine you have a Raspberry Pi at home that controls your garden lights. You want the lights to turn on automatically at sunset and turn off at sunrise without you pressing any buttons.
🎯 Goal: Build a simple program that shows how automation can run tasks on a Raspberry Pi without needing a person to do it every time.
📋 What You'll Learn
Create a dictionary with exact times for sunset and sunrise
Add a variable to hold the current time
Use a for loop to check if the current time matches sunset or sunrise
Print the action taken (turning lights on or off)
💡 Why This Matters
🌍 Real World
Automation helps devices like Raspberry Pi run tasks like turning lights on/off without needing you to do it manually every time.
💼 Career
Understanding automation basics is useful for jobs in IoT, home automation, and embedded systems programming.
Progress0 / 4 steps
1
DATA SETUP: Create a dictionary with sunset and sunrise times
Create a dictionary called times with these exact entries: 'sunset': 18 and 'sunrise': 6 representing hours in 24-hour format.
Raspberry Pi
Need a hint?

Use curly braces {} to create a dictionary with keys 'sunset' and 'sunrise'.

2
CONFIGURATION: Add a variable for the current time
Create a variable called current_time and set it to 18 to represent the current hour.
Raspberry Pi
Need a hint?

Just assign the number 18 to the variable current_time.

3
CORE LOGIC: Check if current time matches sunset or sunrise
Use a for loop with variable event to iterate over times. Inside the loop, use an if statement to check if current_time equals times[event]. If yes, create a variable action and set it to 'Turn lights on' if event is 'sunset', else set it to 'Turn lights off'.
Raspberry Pi
Need a hint?

Loop over the keys in times, compare current_time with each value, and set action accordingly.

4
OUTPUT: Print the action taken
Write a print statement to display the value of the variable action.
Raspberry Pi
Need a hint?

Use print(action) to show the result.