Skip to content

Script to turn on device running WLED with sunset and turn off with sunrise.

Notifications You must be signed in to change notification settings

benostein/SunsetSunriseWLED

Repository files navigation

Sunset Sunrise WLED

Simple Python scripts to turn a WLED device on/off with sunset/sunrise.

There are two scripts in the project:

  • sunset_sunrise_startup.py
    • Designed to run when you turn your computer on.
    • Uses date, longitude and latitude to calculate sunset and sunrise times (thanks to Suntime).
    • Turns on LEDs when sun has set.
    • Turns off LEDs when sun has risen.
  • sunset_sunrise_shutdown.py
    • Designed to run when you turn your computer off.
    • Turns off LEDs (if already on).

These scripts will ensure that the LEDs will only be on when your computer is turned on and when it is dark outside.

A similar effect can be achieved with Home Assistant and Alexa routines but I prefer this solution as there is no need for another IoT device to be constantly running.

Getting Started

These instructions will get you a copy of the project up and running on your local machine.

Prerequisites

To get the script running, all you will need to have is:

  • Python (3.3+)
  • Windows 10
  • Device running WLED on your network

Installation

  1. Clone the repo and enter the folder

    git clone https://github.com/benostein/SunsetSunriseWLED.git
    cd SunsetSunriseWLED
  2. Create virtual environment

    py -m venv env
  3. Activate virtual environment

    .\env\Scripts\activate

    This can be verified by using the command which python and checking it is using the Python interpreter in the env folder.

  4. Install the Python libraries

    pip install -r requirements.txt
  5. Edit config.py

    # Your latitude here
    LATITUDE = 51.5074
    # Your longitude here
    LONGITUDE = 0.1278
    # Your WLED IP address here
    LED_IP_ADDRESS = "192.168.0.57"
    # Config sleep delay here (optional)
    SLEEP_DELAY = 2
  6. Run generate_bat_files.py

    py generate_bat_files.py

    This will generate two .bat files that will launch the Python scripts.

  7. Run gpedit.msc (Local Policies)

  8. Computer Configuration -> Windows Settings -> Scripts -> Startup -> Properties -> Add -> (select path of led_startup.bat)

  9. Computer Configuration -> Windows Settings -> Scripts -> Shutdown -> Properties -> Add -> (select path of led_shutdown.bat)

These scripts will now run automatically, so you should not have to worry about turning your LEDs on or off again.

Projects Used

  • WLED - ESP8266/ESP32 webserver to control LEDs.
  • Python-WLED - Asynchronous Python client for WLED.
  • Suntime - Used to calculate sunrise/sunset times.

Contributing

Pull requests are more than welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

About

Script to turn on device running WLED with sunset and turn off with sunrise.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages