Lightsy is a Python-based project for controlling lights based on motion detection events. It uses a LightControl
class to manage individual lights and a PresenceLighting
class to handle motion detection events and control the
lights accordingly. The EventStream
class is used to listen for motion detection events from the DVR/NVR.
The project is designed to work with Hikvision cameras using the ISAPI event stream for motion detection events. It controls lights using the tinytuya library for Tuya smart devices.
- Turn lights on and off based on motion detection events.
- Configure active times for lights to respond to motion.
- Set duration for lights to stay on after motion is detected.
- Map multiple cameras to multiple lights for presence lighting.
-
Clone the repository:
git clone https://github.com/ayshmnmm/lightsy.git cd lightsy
-
Install the required dependencies:
pip install -r requirements.txt
-
Create a
.env
file in thesrc
directory with the following content:ISAPI_EVENT_URL="http://192.168.x.y/ISAPI/Event/notification/alertStream" ISAPI_USERNAME="username" ISAPI_PASSWORD="password"
-
Create a
config.py
file in thesrc
directory or renameconfig.example.py
toconfig.py
and configure the devices, lights, and presence lighting mappings:DEVICES = { 'device1_name': { 'ip': '192.168.x.y', 'dev_id': 'device1_id', 'local_key': 'device_local_key', 'version': 3.0 } } LIGHTS = { 'light1_name': { 'device': 'device1_name', # device name from DEVICES 'switch': 1 # switch id } } PRESENCE_LIGHTING_MAPPING = [ { "channels": [1], # camera channel ids "lights": [{ "light": "light1_name", # light name from LIGHTS "duration": 45, # duration in seconds for light to stay on after motion is detected "activeTime": [(0, 800), (1600, 2400)] # 24-hour format active times }] } ]
-
Run the main script:
python src/main.py
config.py
: Contains the configuration for devices, lights, and presence lighting mappings..env
: Contains the environment variables for the ISAPI event stream URL, username, and password.
An example of handling a motion detection event:
lc = LightControl(DEVICES, LIGHTS)
pl = PresenceLighting(lc, PRESENCE_LIGHTING_MAPPING)
test_event = {
"eventType": "VMD",
"channelID": 1,
"dateTime": "1970-01-01T12:00:00",
# ...
}
pl.handle_event(test_event)
Distributed under the MIT License. See LICENSE
for more information.
For any questions or feedback, please contact me at mail@ayushmanmuduli.com