This is an unofficial Python library for the Streamlabs Water Monitor.
This library can be used to retrieve water usage and manage the away mode of your location.
The easiest way to install the library is via pip:
$ pip install streamlabswater
Usage is pretty simple but you can check out some sample usage via the examples directory.
The first thing you will need to do is request an API key for your account. Follow the instructions on the Streamlabs Getting Started page to request your API key. The library supports the API key mode of authentication, so make sure you follow the steps to request that (OAUTH2 is not currently supported).
Once you have your API key you are ready to start using the library. The first step is to import the module and pass your API key to the client:
from streamlabswater import streamlabswater
api_key = "YOUR_API_KEY"
client = streamlabswater.StreamlabsClient(api_key)
To retrieve water usage or change the away mode of your location you'll first need to determine its locationId. The get_locations
method is great for determining your available locations and their locationId. The following retrieves the locationId for the first available location:
location_id = client.get_locations()['locations'][0]['locationId']
With this we can now query the current water usage summary:
water_usage = client.get_water_usage_summary(location_id)
gallons_today = water_usage['today']
gallons_this_month = water_usage['thisMonth']
gallons_this_year = water_usage['thisYear']
Or retrieve the current away mode for the location:
location = client.get_location(location_id)
home_or_away = location['homeAway']
if home_or_away == 'home':
print("away mode not activated")
elif home_or_away == 'away':
print("away mode is activated")
Finally we can use the locationId to change the away mode for the location:
client.update_location(location_id, "away")