Could be, but I am just locking for “locked” when I want to lock my nuki and “unlocked” when I want to unlock it.
I missed to show this
kommando=`curl -s "http://$addrNuki:8080/lockAction?nukiId=$id&$aktion&token=$token"`
ergebnis=`echo $kommando | jq -r .success`
This responses true or false and in special cases something else, as I remember, but I catch this by *)
. As long as it is true I am fine with it.
When it is false I try to send the action two more times. If it still not works then I send the message…
EDIT:
Here the whole method to be more clear. Ignore the not nuki related stuff, because I have some additional dependencies for my actions:
schliessen ()
{
hwrTuer=`curl -s -u $user:$pwd $addr:1234/api/variables/kontakt-tuer-hwr-garage | jq -r .variable.value`
if [ $hwrTuer = offen ]
then python /home/ortin/telegram/telegramText.py "Nuki HWR - KEINE AKTION, da die Tür OFFEN steht!" Daniel #alle
exit 0
fi
case $modus in
auf) aktion=action=1 ;;
zu) aktion=action=2 ;;
esac
kommando=`curl -s "http://$addrNuki:8080/lockAction?nukiId=$id$aktion&token=$token"`
ergebnis=`echo $kommando | jq -r .success`
case $ergebnis in
true)
case $modus in
auf) curl -s -X PATCH -H "Content-Type:application/json" -u "$user:$pwd" -d '{"type": "value", "valueOrExpression": "'"offen"'"}' $addr:1234/api/variables/nuki-status-schloss
echo `date +%d.%m.%Y-%H:%M:%S` - Nuki HWR AUFGESCHLOSSEN >>/home/ortin/Homation/log/actionNuki.log
;;
zu) curl -s -X PATCH -H "Content-Type:application/json" -u "$user:$pwd" -d '{"type": "value", "valueOrExpression": "'"verschlossen"'"}' $addr:1234/api/variables/nuki-status-schloss
echo `date +%d.%m.%Y-%H:%M:%S` - Nuki HWR ABGESCHLOSSEN >>/home/ortin/Homation/log/actionNuki.log
;;
esac
# Schließstatus prüfen und Pimatic updaten
schliessStatus
# Rückgabewert ausgeben
echo "\n----------------------"
echo "Rückgabewert: $ergebnis\n"
exit 0
;;
false)
while [ $loop != 3 ]
do
loop=$(( $loop + 1 ))
echo " ∟ API "$loop"x angesprochen (case -> false)" >>/home/ortin/Homation/log/actionNuki.log
sleep 5
schliessen # $modus ist an dieser Stelle schon durch den Methodenaufruf bekannt.
done
case $modus in
auf) python /home/ortin/telegram/telegramText.py "Nuki HWR - Aufschließen hat NICHT geklappt!" Daniel ;;
zu) python /home/ortin/telegram/telegramText.py "Nuki HWR - Abschließen hat NICHT geklappt!" Daniel ;;
esac
# Rückgabewert ausgeben
echo "\n----------------------"
echo "Rückgabewert: $ergebnis\n"
exit 0
;;
*)
while [ $loop != 5 ]
do
loop=$(( $loop + 1 ))
echo Loop = $loop
echo " ∟ API "$loop"x angesprochen (case -> *)" >>/home/ortin/Homation/log/actionNuki.log
sleep 5
schliessen
done
python /home/ortin/telegram/telegramText.py "Nuki HWR - API Rückgabewert ungültig!" Daniel
echo "\nRückgabewert fehlerhaft\n"
;;
esac
}
Remember I am not Dev, I just play around with code