RaspAutomator is a Python-based task scheduling system designed for Raspberry Pi and other Linux environments. It provides a simple yet powerful framework for running automated, recurring tasks such as a morning radio alarm or a sleep sounds player.
The core of the automator uses a lightweight, cooperative multitasking approach to manage and run multiple tasks concurrently, with each task's schedule and behavior defined by simple JSON configuration files.
- Flexible Task Scheduling: Configure tasks to run on specific days of the week and at specific times.
- Continuous & Recurring Tasks: Supports tasks that run once per scheduled time or repeat at a defined interval.
- Dynamic Task Loading: Automatically discovers and runs tasks placed in the
tasksdirectory. - Task Termination: Tasks can be stopped immediately by creating
.terminatefiles in thetasks/directory (e.g.,touch tasks/radio_alarm.terminateortouch tasks/all.terminateto stop all tasks) - Bluetooth Speaker Integration: Built-in handler to connect to Bluetooth audio devices before running a task.
- Service-based Installation: Includes an installer to set up the automator as a
systemduser service, ensuring it runs on boot and restarts automatically on failure. - Modular Design: Each task is self-contained in its own directory, making it easy to add, remove, or modify tasks.
Before you begin, ensure your system (e.g., Raspberry Pi OS) has the following dependencies installed.
These packages are required for audio playback, Bluetooth connectivity, GUI, and downloading media.
Note on Raspberry Pi OS Package Management: Raspberry Pi OS uses an externally-managed Python environment (PEP 668) to prevent conflicts between system packages and pip-installed packages. Therefore, Python libraries should be installed using apt with the python3- prefix rather than pip, which ensures compatibility with system tools and prevents breaking your Python installation.
# Install VLC, Bluetooth tools, and other utilities (required for audio playback and Bluetooth connectivity)
sudo apt install -y vlc bluez python3-pip
# Python packages (installed via apt to respect externally-managed environment)
sudo apt install python3-vlc python3-psutil python3-watchdog python3-pyqt6
# yt-dlp (installed through pipx for system-wide access without conflicts)
sudo apt install pipx
pipx ensurepath
pipx install yt-dlp
Note: pyRTOS is not available in apt repositories or pip. You must install it manually from the GitHub repository or use a separate installation script.
The included installer.py script automates the process of setting up RaspAutomator to run as a background service.
-
Clone the Repository, install the scripts
cd /Documents mkdir myservices cd /myservices git clone https://github.com/FraH90/raspautomator cd raspautomator # Make scripts executable and run the installer (WITHOUT SUDO OR IT WILL THROW ERROR!) chmod +x installer.sh automator.sh ./installer.sh
The installation script will:
- Locate the
automator.shscript. - Create a
systemduser service file (~/.config/systemd/user/automator.service). - Enable the service to start on boot (
loginctl enable-linger). - Reload, enable, and start the service.
- Locate the
Once installed, you can manage the RaspAutomator service with standard systemctl commands:
- Check Status:
systemctl --user status automator.service - View Logs:
journalctl --user -u automator.service -f - Stop Service:
systemctl --user stop automator.service - Start Service:
systemctl --user start automator.service - Restart Service:
systemctl --user restart automator.service
Logs are also appended to logs/output.out in the project directory.
Each task is configured through JSON files within its directory (tasks/<task_name>/).
This file controls when and how a task runs.
Available Parameters:
schedule_on: Iftrue, the task runs on the schedule defined bydays_of_weekandtime_of_day. Iffalse, it runs continuously (respectingtimeout_on).timeout_on: Iftrue, the task repeats everytimeout_intervalseconds after its first run. Iffalse, it runs only once per scheduled time.days_of_week: A list of days to run the task (e.g.,"Monday","Tuesday"). Only used whenschedule_onistrue.time_of_day: The time to run the task inHH:MMformat (24-hour). Only used whenschedule_onistrue.timeout_interval: The delay in seconds between repeated executions. Used whentimeout_onistrue.max_duration: Maximum time in seconds the task should run before being automatically stopped (optional).
Execution Scenarios:
Different combinations of schedule_on and timeout_on control how your task behaves:
| schedule_on | timeout_on | Behavior |
|---|---|---|
true |
true |
Task runs at specified days and time, then repeats every timeout_interval seconds |
true |
false |
Task runs once at specified days and time, then waits until next scheduled time |
false |
true |
Task runs continuously, waiting timeout_interval seconds between executions |
false |
false |
Task runs continuously without any delay between executions |
Example:
{
"schedule_on": true,
"timeout_on": false,
"days_of_week": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
"time_of_day": "08:00",
"max_duration": 3600,
"timeout_interval": 3600
}This file contains settings specific to the task's logic, such as API keys or device addresses. For the included tasks, this is where you set your Bluetooth speaker's MAC address.
The following tasks are located in the tasks/ directory and are ready for use.
Directory: tasks/radio_alarm/
This task connects to a specified Bluetooth speaker and plays a random online radio stream for one hour. It's designed to function as a morning alarm clock.
Configuration:
tasks/radio_alarm/config.json: Set themac_addressof your Bluetooth speaker.tasks/radio_alarm/radio_stations.json: Add or remove radio stream URLs.tasks/radio_alarm/trigger.json: Configure the alarm schedule (e.g., weekdays at 08:00).
Directory: tasks/sleep_sounds/
This task connects to a Bluetooth speaker, picks a random YouTube video from a list (e.g., rain sounds, white noise), and loops the audio until a specified stop time. It caches the audio locally to avoid re-downloading.
Configuration:
tasks/sleep_sounds/config.json:- Set the
mac_addressof your Bluetooth speaker. - Set the
stop_timewhen the audio should stop playing (e.g., "23:30").
- Set the
tasks/sleep_sounds/sleep_sounds_sources.json: Add or remove YouTube URLs for the sleep sounds.tasks/sleep_sounds/trigger.json: Configure when the sleep sounds should start.
- Create a new folder inside the
tasks/directory (e.g.,my_new_task). - Inside it, create a
trigger.jsonfile to define its schedule. - Create a Python script that contains the core logic. It must have a
thread_loop()function, which will be called by the scheduler. - If your task requires specific configuration (like API keys or MAC addresses), create a
config.jsonfile. - The automator will automatically detect and run your new task on the next restart.
RaspAutomator includes a file system watcher that monitors trigger.json files for changes. This means you can modify task configurations without restarting the automator service.
- File Monitoring: The system uses the
watchdoglibrary to detect when anytrigger.jsonfile is modified in thetasks/directory. - Automatic Reload: When a change is detected, the configuration is automatically reloaded into memory.
- Safe Updates: Currently running tasks complete with their original configuration. The updated configuration applies to the next task execution.
- No Service Restart Required: Make changes through the GUI or by editing JSON files directly - the automator picks them up automatically.
A PyQt6-based GUI is available at gui/task_config_editor.py for easy configuration editing:
python3 gui/task_config_editor.pyFeatures:
- Dark theme interface with tabbed layout (one tab per task)
- Smart controls: time pickers, day selectors, checkboxes for booleans
- Save button writes changes to
trigger.jsonfiles - Terminate button to immediately stop running tasks
- Changes are automatically detected by the file watcher