From 10c570b552276b5fe96ba7cd9608fd18ac6f38ac Mon Sep 17 00:00:00 2001 From: EpicKiwi Date: Tue, 7 Jan 2025 21:02:33 +0100 Subject: [PATCH] Initial commit --- lol-opener.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 lol-opener.sh diff --git a/lol-opener.sh b/lol-opener.sh new file mode 100755 index 0000000..c0583a5 --- /dev/null +++ b/lol-opener.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +function isClosed { + mosquitto_sub -t zigbee/entree -h mosquitto.labolyon.dn42 -C 1 | jq ".contact" +} + +function waitForEvent { + mosquitto_sub -t zigbee/entree -h mosquitto.labolyon.dn42 -C 2 | tail +2 | jq ".contact" +} + +while $(true); do + state=$(waitForEvent) + if [[ "$state" = "false" ]]; then + + echo "Porte ouverte, 30 secondes avant l'ouverture du local" + sleep 3 + if [[ "$(isClosed)" = "false" ]]; then + systemctl start lol-opening.service + fi + + else + + echo "Porte fermee, 10 secondes avant la fermeture du local" + sleep 1 + if [[ "$(isClosed)" = "true" ]]; then + systemctl stop lol-opening.service + fi + + fi +done \ No newline at end of file