30 lines
725 B
Bash
30 lines
725 B
Bash
|
#!/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
|