Creating a new Code for keypad every day and send it to mobilphone

Hi,

i have now created a small bash script in my raspberry pi, that creates a new key every day for the nuki - keypad.
After generating the code, the code is send via pushover to my familiy on their mobilphones.

If anyone is interesting in it here is the code:

#!/bin/bash
#Change Code every day

#generate random number
zahl1=$((RANDOM % 9 +1))
zahl2=$((RANDOM % 9 +1))
zahl3=$((RANDOM % 9 +1))
zahl4=$((RANDOM % 9 +1))
zahl5=$((RANDOM % 9 +1))
zahl6=$((RANDOM % 9 +1))

pincode=$zahl1$zahl2$zahl3$zahl4$zahl5$zahl6    
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Bearer TOKEN' -d '{ "name": "NAME", "code": '$pincode' }' 'https://api.nuki.io/smartlock/ID/auth/USERID'

#Send To Pushover
curl -s -F "token=TOKEN" -F "user=USER" -F "title=Nuki Key fĂĽr Heute" -F "message=$pincode" https://api.pushover.net/1/messages.json

I am not a coding genius - so maybe it could be shorter, especially the “random-sequence” :slight_smile:

Regards
Clemens

7 Likes

You can use a for-loop for generating the pincode:

for i in {1…6}; do pincode=$pincode$(($RANDOM % 9 + 1)); done;

I think that should work