Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uvbox

A small python script to control an SSR output device (e.g. an LED) in response to motion from a PIR motion sensor

Setup

Install dependencies

It's best to install python dependencies in a python virtual environment:

# Create virtual env
python3 -m venv venv
# Activate virtual env
. venv/bin/activate
# Install dependencies
pip install -r requirements.txt

To deactivate the virtual env just run:

deactivate

Linting

Flake8 is used for code linting and included in the requirements.txt

Config

The script can be configured using the following environment variables:

  • PIN_PIR
    • GPIO pin for the PIR motion sensor input
    • default: 18
  • PIN_SSR
    • GPIO pin for the SSR output
    • default: 17
  • MIN_ACTIVATION_SECS
    • Minimum time in seconds to keep SSR active after motion is detected
    • default: 10
  • DRY_RUN
    • Dry run mode for testing without actual GPIO hardware. Simulates random motion events.
    • default: 0

Execution

  1. Install dependencies as described in the Setup section
  2. Configure environment variables if required e.g: export DRY_RUN=1
  3. Run script e.g. python uvbox.py

Logic

The script runs in a loop, checking for motion every second.

If motion is detected and the SSR is not currently active, the SSR is turned on and the script blocks for the minimum duration.

After the minmum duration has elapsed, the loop continues to the next iteration.

If motion is still detected on the next iteration of the loop, the SSR will remain on.

If no motion is detected, the SSR is turned off, assuming it's currently active.

This prevents the SSR device turning off and immediately turning back on while continuous motion is detected.

Dry Run Mode

Dry run mode helps with testing when you don't have access to physical GPIO devices. Motion is simulated at random intervals (between 1 and 20 seconds) for random durations (between 1 and 10 seconds).

To run the script in dry run mode:

DRY_RUN=1 python uvbox.py

About

A small python script to control an SSR output device (e.g. an LED) in response to motion from a PIR motion sensor

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages