mqtt-lol-opener/lol-opener.sh

30 lines
727 B
Bash
Raw Permalink Normal View History

2025-01-07 21:02:33 +01:00
#!/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"
2025-01-07 21:08:16 +01:00
sleep 30
2025-01-07 21:02:33 +01:00
if [[ "$(isClosed)" = "false" ]]; then
systemctl start lol-opening.service
fi
else
echo "Porte fermee, 10 secondes avant la fermeture du local"
2025-01-07 21:08:16 +01:00
sleep 10
2025-01-07 21:02:33 +01:00
if [[ "$(isClosed)" = "true" ]]; then
systemctl stop lol-opening.service
fi
fi
done