Wir wollen unseren Office Raum Stündlich ausmieten.
Wir brauchen 1x Opener für die Eingangs/Außertür (müssten in Verbindung mit der bestehenden Hausanlage funktionieren) und 1x Keylock für die Innentür zum Officeraum.
Wir möchten das Kunden über unsere Website sich einbuchen und dann per unserem Dashboard auf unserer Website dann die beiden Türen zur gegeben Zeit öffnen können.
Könnte man mit der Nuki API, ohne die Nuki App, den „Keylock-Öffnen-Knopf“ direkt auf unser Dashboard einbauen? (Also ohne, dass die User die Nuki App downloaden müssen?
Hi, we are doing the same with our business for multiple locations. Here are some lessons learned:
connection to internet / bridge / smartlock should be very good, if not, it leads to some codes not being transferred to the smartlock
the smartlock only can handle 100 codes for the keypad. When renting 12h a day and more than a week in advancem you need a script which deletes expired codes and fetches and assignes codes for only the near future. So another database is required to store the code.
Be sure to check if the times you set for the code expiry are with correct time zone and also consider daylight saving time!
when you allow spontaneous bookings, make sure, the codes are updated immediately or regularly.
I’m adding an example code (I know it’s not the best, but as an orientation) we use right now. It’s a shell script running every 15 minutes via crontab on our own server. Updating all codes for “today and tomorrow” and deletes everything older or equal “yesterday”:
#!/bin/bash
# get a simple list of all existing codes
echo updating nuki_codes_existing.lsv
curl "https://api.nuki.io/smartlock/auth?types=13" -H "Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXX-YOUR-API-KEY-HERE-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -H "Content-Type: application/json" | jq -r '.[].name' > nuki_codes_existing.lsv
# get all codes with expiry date
echo updating nuki_codes_expiry.lsj
curl "https://api.nuki.io/smartlock/auth?types=13" -H "Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXX-YOUR-API-KEY-HERE-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -H "Content-Type: application/json" | jq -r -c '.[] | {id: .id,
expiry: .allowedUntilDate, name: .name}' > nuki_codes_expiry.lsj
# remove all expired (yesterday or older) codes
while IFS=$'\t' read -r code;
do
if [ $(echo "$code" | jq -e '.expiry') == "null" ]; then
continue
fi
EXPIRY_DATE=$(echo "$code" | jq -e '.expiry' | cut -c2-11)
EXPIRY=$(date -d $EXPIRY_DATE +%s)
TODAY=$(date -d $(date "+"%Y-%m-%d"") +%s)
if (( EXPIRY < TODAY )); then
echo deleting expired code $(echo "$code" | jq -e '.name')
DELETE_ID=$(echo "$code" | jq -e '.id')
curl -X DELETE -d "[${DELETE_ID}]" -H "Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXX-YOUR-API-KEY-HERE-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -H "Content-Type: application/json" "https://api.nuki.io/smartlock/auth"
fi
done < "nuki_codes_expiry.lsj"
echo removed all expired codes
# fetch the stored codes
echo updating nuki_codes.tsv
mysql -B -h your.mysqldatabase.here -D yourDatabaseHere -u yourDatabaseUserHere -pYourPasswordHere -e "SELECT keyname , smartlockId, code, allowedFromDate, allowedUntilDate FROM nuki_codes WHERE k.allowedFromDate BETWEEN DATE(NOW()) AND NOW() + INTERVAL 1 DAY;" > nuki_codes.tsv
#add only not yet existing codes (to avoid error messages in nuki web)
echo reading nuki_codes.tsv
sed 1d "nuki_codes.tsv" | while IFS=$'\t' read -r keyname , smartlockId, code, allowedFromDate, allowedUntilDate
do
if [[ "$keyname" =~ $(echo ^\($(paste -sd'|' nuki_codes_existing.lsv)\)$) ]]; then
echo "$keyname already exists"
elif [ $code == "NULL" ]; then
echo "Code for ${keyname} is NULL and won't be inserted!"
else
echo "$keyname needs to be created"
echo adding code $code to lock $smartlockId named $keyname
curl -X PUT -d "{'smartlockIds':[${smartlockId}],'code':'${code}','type':13,'name':'${keyname}','allowedFromDate':'${allowedFromDate}','allowedUntilDate':'${allowedUntilDate}','allowedWeekDays':0,'allowedFromTime':0,'allowedUntilTime':0}" -H "Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXX-YOUR-API-KEY-HERE-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -H "Content-Type: application/json" "https://api.nuki.io/smartlock/auth"
fi
done
echo finished adding codes
exit 0