MyAussenlicht is an ESP2866 based remote control for an outdoor light. A simple server running on the ESP2866, that can be accessed via your local network, is utilized. Two use cases are supported:
- Manual Remote Control
- Automated Remote Control with Sunrise and Sunset
Table of Contents
- Arduino IDE
- WROOM-32 ESP2866 Dev kit
- ESP-Arduino Lib
- ESP Board Files
Start the Arduino IDE and make sure you have the latest ESP-Lib installed:
Next, navigate to the board manager in the Arduino IDE and install the esp8266 library:
Open the MyAussenlicht.ino-file in the Embedded directory and replace the SSID and password in the following lines with your SSID and password:
#ifndef STASSID
#define STASSID "YOUR_SSID"
#define STAPSK "YOUR_PW"
#endifChoose the LOLIN(WEMOS) D1 R2 & mini board, connect your board via USB, select the correct COM-port, and press upload to board.
Upon bootup the ESP-module will attempt to connect to the specified WiFi network:
Connecting to
YOUR_WIFI_NAME
Connecting to WiFi
Sent SSID and PW...
................
WiFi connected
Server started
192.168.178.XXGrab a device already connected to your local network and access the IP address from above (192.168.178.XX).
Now you can toggle the Aussenlicht by simply pressing the ON or OFF button.
With the python file MyAussenlichtTimer.py in the Python directory you can automatically switch the Aussenlicht with sunrise and sunset. By default, the outdoor light will be switched on upon sunset and switched off at midnight.
- Machine that is permanently connected to your local Network (e.g. Raspberry Pi, NAS, etc.)
- At least Python 3.6
Before using it with your Aussenlicht you will have to edit the properties of the AussenlichtConfig in the MyAussenlichtTimer.py file.
class AussenlichtConfig():
AUSSENLICHT_URL = "http://192.168.178.XX" # Enter the URL of your ESP server
LATITUDE = 50.0212981 # Enter the latitude of your geo-location
LONGITUDE = 9.2554408 # Enter the longitude of your geo-locationNext, you can execute it.
cd Python
python MyAussenlichtTimer.pyThe plot below shows the output of running MyAussenlichtTimer.py concurrently every 5 minutes.
Log into your qnap2 via a browser of your choice.
Install the Container Station from the AppCenter and setup a Ubuntu 18.0 container according to these instructions. Once the container is setup, launch a shell inside it and set a password for the ubuntu user.
passwd ubuntuNext, install the following packages.
sudo apt update && sudo apt upgrade
sudo apt install wget unzip python3-pip nano python3Pull this repo from GitHub and unzip it.
cd /home/ubuntu
mkdir myapps && cd myapps
wget https://github.com/ModnarUser/MyAussenlicht/archive/refs/heads/master.zip
unzip master.zip
sudo rm -rf master.zip
cd MyAussenlicht-master/PythonInstall the utilized Python libraries and make MyAussenlichtTimer.py executable.
python3 -m pip install -r requirements.txt
chmod +x MyAussenlichtTimer.pyNote: depending on your local setup it might be sufficient to edit the user crontab. If this does not work however, you have to additionally edit the system wide crontab.
A) User Crontab
Write the currently running cronjobs to a file.
sudo crontab -l > cronfileOpen the file with nano cronfile and add the following line:
*/4 * * * * /usr/bin/python3 /home/ubuntu/myapps/MyAussenlicht-master/Python/MyAussenlichtTimer.py >> /home/ubuntu/myapps/MyAussenlicht-master/Python/MyAussenlichtTimer.logPass the edited cronfile to crontab in order to run the MyAussenlichtTimer.py concurrently.
sudo crontab cronfileFinally, you can check if the cronjob was successfully added with sudo cronjob -l.
B) System Wide Crontab
Open the system wide crontab at /etc/crontab
sudo nano /etc/crontabWrite the following line to the end of the file.
*/4 * * * * ubuntu /usr/bin/python3 /home/ubuntu/myapps/MyAussenlicht-master/Python/MyAussenlichtTimer.py >> /home/ubuntu/myapps/MyAussenlicht-master/Python/MyAussenlichtTimer.logA) Logfile
The cronjobs will write logging information to the MyAussenlichtTimer.log file. You can check if the MyAussenlichtTimer is running as intended by printing the content of the file to stdout.
cat /home/ubuntu/myapps/MyAussenlicht-master/Python/MyAussenlichtTimer.logWhich will print something like this:
Connection to http://192.168.178.XX successful!
now: 2021-05-01 10:32:02.210094+00:00 last_midnight: 2021-05-01 00:01:00+00:00 midnight: 2021-05-01 23:59:00+00:00 sunrise: 2021-05-01 04:00:00+00:00 sunset: 2021-05-01 18:41:00+00:00
Außenlicht OFF B) Get System Time
date "+%H:%M:%S %d/%m/%y"C) Print Syslog
sudo grep CRON /var/log/syslogInstall all python requirements via
pip install -r requirements.txtModify the TEST_URL in test_MyAussenlichtTimer.py to fit your server URL.
################################################################
# Test Settings
################################################################
TEST_URL = "http://192.168.178.XX" # Use URL of your AussenlichtNavigate into the toplevel Python directory (*/MyAussenlicht/Python) and run the tests.
pytest test_MyAussenlichtTimer.pyWhen all tests were run successfully you should get the following output:
==================== test session starts =====================
platform linux -- Python 3.8.2, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /data/data/com.termux/files/home/Documents/gitrepos/MyAussenlicht
collected 7 items
test_MyAussenlichtTimer.py ....... [100%]
===================== 7 passed in 46.44s =====================