Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

#https://pydigger.com/pypi/pykevoplus
#https://github.com/jsetton/pykevoplus
#https://pypi.org/project/pykevoplus/

Requirements:

Python
PIP Package Manager
Kevo Plus Gateway & Kevo Lock
Username/PWD for mykevo.com
UUID Of Lock (Note, I found the Python Print UUID didn't work and dev mentioned better to use mykevo.com for this, so just login --> settings --> lock_id!

Setup:

apt-get install -y python-pip
pip --version
pip install pykevoplus

Scripts:


cat << 'EOF' >/opt/kevo/kevovars.py
#!/usr/bin/python

lockid="###-###-###-###"
username="username@email.com"
pwd="password"
EOF
chmod +x /opt/kevo/kevovars.py
cat << 'EOF' >/opt/kevo/unlock-front.py
#!/usr/bin/python

from kevovars import lockid, username, pwd
from pykevoplus import KevoLock
lock = KevoLock.FromLockID(lockid, username, pwd)
lock.Unlock()
EOF
chmod +x /opt/kevo/unlock-front.py
#/opt/kevo/unlock-front.py
cat << 'EOF' >/opt/kevo/lock-front.py
#!/usr/bin/python

from kevovars import lockid, username, pwd
from pykevoplus import KevoLock
lock = KevoLock.FromLockID(lockid, username, pwd)
lock.Lock()
EOF
chmod +x /opt/kevo/lock-front.py
#/opt/kevo/lock-front.py

Print to STDOUT:


cat << 'EOF' >/opt/kevo/status-front.py
#!/usr/bin/python

from kevovars import lockid, username, pwd
from pykevoplus import KevoLock
lock = KevoLock.FromLockID(lockid, username, pwd)
print lock.GetBoltState()
EOF
chmod +x /opt/kevo/status-front.py
#/opt/kevo/status-front.py


Print to Log:

cat << 'EOF' >/opt/kevo/status-front.py
#!/usr/bin/python
from __future__ import print_function

from kevovars import lockid, username, pwd
log = open("/tmp/kevostatus", "w")
from pykevoplus import KevoLock
lock = KevoLock.FromLockID(lockid, username, pwd)
print(lock.GetBoltState(), file = log)
EOF
chmod +x /opt/kevo/status-front.py
#/opt/kevo/status-front.py

Automation:

cat << 'EOF' >/opt/ping_check.sh
#!/bin/bash
#Set status before starting loop, or it will trigger repeatedly and/or not work at all
echo "Unlocked" > /tmp/kevostatus
echo "home" > /tmp/geostatus
while :; do
   sleep 5 

       PING=""
       ping -c 1 -w 3 192.168.1.142 > /dev/null    
       PING=$(echo $?)

       if [ $PING -ne 0 ]; then
          #Away
          /opt/kevo/away.sh   
       else
          #Home
          /opt/kevo/home.sh
       fi

#Sometimes kevostatus doesn't report and breaks loop, better safe echo "unlocked"
KEVOSTATUS=$( cat /tmp/kevostatus )
if [ -z "$KEVOSTATUS" ]; then
echo "Unlocked" > /tmp/kevostatus
echo "home" > /tmp/geostatus
fi
       
done
EOF
chmod +x /opt/ping_check.sh
cat << 'EOF' >/etc/cron.d/ping_loop
@reboot root /opt/ping_check.sh
EOF
chmod +x /etc/cron.d/ping_loop
cat << 'EOF' >/opt/kevo/home.sh
#!/bin/bash

username="username@email.com"

GEOSTATUS=$( cat /tmp/geostatus )
if [ $GEOSTATUS == away ]; then          
        KEVOSTATUS=$( cat /tmp/kevostatus )
        if [ $KEVOSTATUS == Locked ]; then
        /opt/kevo/unlock-front.py
        /opt/kevo/status-front.py
        echo "home" > /tmp/geostatus
        GEOSTATUS=$( cat /tmp/geostatus )
        KEVOSTATUS=$( cat /tmp/kevostatus )
        echo "Kevo Notification" | mail -s "Kevo Lock Status:$KEVOSTATUS and GeoStatus:$GEOSTATUS" $username
		sleep 60
        fi
fi   
EOF
chmod +x /opt/kevo/home.sh
cat << 'EOF' >/opt/kevo/away.sh
#!/bin/bash

username="username@email.com"

GEOSTATUS=$( cat /tmp/geostatus )
if [ $GEOSTATUS == home ]; then          
        KEVOSTATUS=$( cat /tmp/kevostatus )
        if [ $KEVOSTATUS == Unlocked ]; then
        /opt/kevo/lock-front.py
        /opt/kevo/status-front.py
        echo "away" > /tmp/geostatus
        GEOSTATUS=$( cat /tmp/geostatus )
        KEVOSTATUS=$( cat /tmp/kevostatus )
        echo "Kevo Notification" | mail -s "Kevo Lock Status:$KEVOSTATUS and GeoStatus:$GEOSTATUS" $username
		sleep 60
        fi  
fi 
EOF
chmod +x /opt/kevo/away.sh
  • No labels