diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..2fb5155 --- /dev/null +++ b/install.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +rm -rfv /usr/share/zigbee-opener/ + +mkdir -p /usr/share/zigbee-opener/ +mkdir -p /var/run/zigbee-opener/ + +cp -v main.py /usr/share/zigbee-opener/ +cp -v settings.py /usr/share/zigbee-opener/ +chmod +x /usr/share/zigbee-opener/main.py + +cp -f zigbee-opener.service /etc/systemd/system/ + +python -m venv /usr/share/zigbee-opener/.venv/ +source /usr/share/zigbee-opener/.venv/bin/activate +pip install -r requirements.txt + +echo "" +echo "Installed into /usr/share/zigbee-opener/" +echo "with service zigbee-opener" +echo "" +echo "Configure in /usr/share/zigbee-opener/settings.py" \ No newline at end of file diff --git a/main.py b/main.py index aefb04c..3b4fda4 100755 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -#!/bin/env python +#!./.venv/bin/python import zigate from zigate import dispatcher import time @@ -42,10 +42,11 @@ def trigger_closing(): global is_opening global is_closing - if is_opening: + if is_closing: return is_closing = True + is_opening = False for i in range(0, CLOSING_TRIGGER_DELAY): time.sleep(1) diff --git a/settings.py b/settings.py index 3633746..087e684 100644 --- a/settings.py +++ b/settings.py @@ -13,5 +13,5 @@ OPENING_TRIGGER_DELAY = 30 # Delay to wait before marking room as closed CLOSING_TRIGGER_DELAY = 5 -LOL_OPENED_CMD = "ln -f -s a.txt test/status.txt" -LOL_CLOSED_CMD = "ln -f -s b.txt test/status.txt" \ No newline at end of file +LOL_OPENED_CMD = """echo "opened" > /var/run/zigbee-opener/status """ +LOL_CLOSED_CMD = """echo "closed" > /var/run/zigbee-opener/status """ \ No newline at end of file diff --git a/test/status.txt b/test/status.txt index 8d14cbf..19acdd8 120000 --- a/test/status.txt +++ b/test/status.txt @@ -1 +1 @@ -a.txt \ No newline at end of file +b.txt \ No newline at end of file diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000..0189785 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +rm -rfv /usr/share/zigbee-opener/ +rm -rfv /var/run/zigbee-opener/ +rm -fv /etc/systemd/system/zigbee-opener.service + +echo "" +echo "Uninstalled" \ No newline at end of file diff --git a/zigbee-opener.service b/zigbee-opener.service new file mode 100644 index 0000000..fe1ecef --- /dev/null +++ b/zigbee-opener.service @@ -0,0 +1,12 @@ +[Unit] + Description=Zigbee LOL opening detection system + After=network.target + +[Service] + Restart=always + ExecStart=/usr/share/zigbee-opener/main.py + Type=simple + WorkingDirectory=/usr/share/zigbee-opener/ + +[Install] + WantedBy=multi-user.target \ No newline at end of file