30 lines
727 B
Bash
Executable File
30 lines
727 B
Bash
Executable File
#!/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 30
|
|
if [[ "$(isClosed)" = "false" ]]; then
|
|
systemctl start lol-opening.service
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Porte fermee, 10 secondes avant la fermeture du local"
|
|
sleep 10
|
|
if [[ "$(isClosed)" = "true" ]]; then
|
|
systemctl stop lol-opening.service
|
|
fi
|
|
|
|
fi
|
|
done |