Litter Robot Connect

Nice, I guess since someone else posted information, no reason in holding back now.

edit: currently this will only function if you have onboarded your litter robot on the iphone app, I need to look back over my mitm logs and see what was done to onboard the robot at first. This will also not properly work with multiple litter robots on 1 account, but I’ll make adjustments to fix that in the future.

Currently, I have a python script running to fit my purposes on my multi-purpose linux box. All you have to do is edit the email/password lines and fill in your litter robot account information. You can create an account on their website, no need to use the app.

Basically, this script will check if it has the authentication token first, grab it if needed, then check the current status of the robot. I currently have it setup to activate webcore pistons if certain statuses are seen, such as any error code or if the device is full.

I run the script every minute via cron, using this line:

* * * * * /usr/bin/python3 /opt/cat.py

Edit /opt/cat.py to wherever you put it.

import logging
import requests
import json
import linecache

email = 'youremail@address.com'
password = 'yourpassword'
logs_enabled = True
log_location = '/opt/cat.log'

auth_token = None
userid = None

auth_token = linecache.getline('litter_robot_auth.txt',1).rstrip()
user_id = linecache.getline('litter_robot_auth.txt',2).rstrip()
if auth_token is '' or user_id is '':
    r = requests.post('https://muvnkjeut7.execute-api.us-east-1.amazonaws.com/staging/login', json={'email':email,"oneSignalPlayerId":"0","password":password}, headers={'x-api-key':'Gmdfw5Cq3F3Mk6xvvO0inHATJeoDv6C3KfwfOuh0'})
    response_native = json.loads(r.text)

    if 'token' in response_native:
        token = response_native['token']
    if 'user' in response_native:
        userid = response_native['user']['userId']

    if token is not None and userid is not None:
        file = open('litter_robot_auth.txt','w')
        file.write( token + '\n' )
        file.write( userid )
        file.close()

auth_token = linecache.getline('litter_robot_auth.txt',1).rstrip()
user_id = linecache.getline('litter_robot_auth.txt',2).rstrip()

r = requests.get('https://muvnkjeut7.execute-api.us-east-1.amazonaws.com/staging/users/' + user_id + '/litter-robots', headers={'x-api-key':'Gmdfw5Cq3F3Mk6xvvO0inHATJeoDv6C3KfwfOuh0','Authorization':auth_token})

response_native = json.loads(r.text)

if logs_enabled is True:
    logging.basicConfig(format='%(asctime)s %(message)s',filename=log_location,level=logging.WARNING)
if 'unitStatus' in response_native[0]:
    status = response_native[0]['unitStatus']
    if logs_enabled is True:
        logging.warning('%s' % status )
    if status == 'DF1' or status == 'DFS' or status == 'DF2':
        new = requests.get('%WEBCORE PISTON TO TURN ON RED LIGHT%')
    elif status == 'RDY':
        new = requests.get('%WEBCORE PISTON TO SET LIGHT TO DEFAULT%')
    elif status == 'BR' or status == 'CSF' or status == 'PDF' or status == 'OTF' or status == 'PF':
        new = requests.get('%WEBCORE PISTON TO TURN ON RED LIGHTS + FLASH%')

The webcore pistons are just pistons that I execute via http requests.

I haven’t had time to put together a device handler, which would allow for more flexibility as the only thing I cared about was if the litterbox needed to be emptied. I’ll post all the http endpoints sometime this week, and someone else should be able to create a device handler/smartapp if they so wish.

4 Likes