3 releases
0.1.2 | Dec 31, 2024 |
---|---|
0.1.1 | Dec 31, 2024 |
0.1.0 | Dec 31, 2024 |
#188 in Command line utilities
313 downloads per month
21KB
229 lines
Healthy Monitor
A Rust application that automatically adjusts your monitor's brightness and color temperature based on:
- Webcam light sensor (primary method)
- Weather data and time of day (fallback method)
Features
- Automatic brightness adjustment based on ambient light
- Color temperature adjustment based on time of day
- Configurable monitor settings
- Fallback to weather-based brightness when webcam is unavailable
- Customizable minimum brightness and color temperature settings
Prerequisites
- Linux system with X11
xrandr
command-line tool- Webcam (optional)
- Rust and Cargo
Installation
Install directly from crates.io:
cargo install healthy-monitor
Usage
Basic usage (using webcam):
healthy-monitor
If webcam is not available, provide OpenWeather API key:
healthy-monitor --api-key YOUR_API_KEY
Command Line Options
healthy-monitor [OPTIONS]
Options:
--api-key <API_KEY> OpenWeather API key (required only if webcam is not available)
--min-brightness <FLOAT> Minimum brightness level (0.0 to 1.0) [default: 0.6]
--day-temp <FLOAT> Color temperature during day in Kelvin [default: 6500]
--night-temp <FLOAT> Color temperature during night in Kelvin [default: 3500]
--transition-hours <FLOAT> Hours before sunset to start transitioning [default: 2.0]
--monitors <MONITORS> Comma-separated list of monitor names [default: autodetect]
-h, --help Print help
-V, --version Print version
Examples
- Basic usage with webcam:
healthy-monitor
- Custom brightness and monitors (with webcam):
healthy-monitor \
--min-brightness 0.4 \
--monitors "HDMI-1,DP-1"
- Using weather API (when webcam is unavailable):
healthy-monitor \
--api-key YOUR_API_KEY \
--min-brightness 0.4
Automatic Execution with Crontab
To run healthy-monitor automatically at regular intervals:
- Find the path to the installed binary:
which healthy-monitor
- Open your crontab configuration:
crontab -e
- Add one of these example configurations:
# Run every 5 minutes (with webcam)
*/5 * * * * DISPLAY=:0 /path/to/healthy-monitor
# Run every 5 minutes (with weather API fallback)
*/5 * * * * DISPLAY=:0 /path/to/healthy-monitor --api-key YOUR_API_KEY
# Run every 10 minutes during daytime with custom settings
*/10 7-22 * * * DISPLAY=:0 /path/to/healthy-monitor --min-brightness 0.4 --monitors "HDMI-1,DP-1"
Note:
- Replace
/path/to/healthy-monitor
with the actual path from step 1 - Replace
YOUR_API_KEY
with your OpenWeather API key - The
DISPLAY=:0
is required for X11 access - Adjust the timing pattern (the five fields at the start) as needed:
*/5
means "every 5 minutes"7-22
means "from 7 AM to 10 PM"- See
man 5 crontab
for more timing patterns
Monitor Configuration
To find your monitor names, run:
xrandr --listmonitors
Then use these names in the --monitors
option.
How It Works
- The application first attempts to use your webcam to measure ambient light.
- If the webcam is unavailable, it falls back to using weather data:
- Fetches your location using IP geolocation
- Gets weather data from OpenWeather API
- Calculates brightness based on time of day and cloud coverage
- Adjusts monitor brightness and color temperature using
xrandr
- Color temperature transitions gradually from day to night
License
MIT License
Dependencies
~10–22MB
~306K SLoC