This is the official python client for the StreamLabs Developer API.
See the StreamLabs Developer API docs
Use the package manager pip to install the package
pip3 install streamlabswater-streamlabswater
The package needs to configured with your accounts API Key available when you login into your http://my.streamlabswater.com account.
from streamlabswater import Stream
stream = Stream('YOUR_STREAMLABSWATER_API_KEY')
Start by fetching all your locations
locations = stream.get_locations()
A location_id
is required to fetch details of a location, water usage and for updating homeAway.
location_id = locations[0]['location_id']
my_home = stream.get_location(location_id)
Currently you can only update the homeAway mode of the location When updating a location the response is always the updated location details
# Set to home
my_home = stream.update_location(location_id, 'home')
# Set to away
my_home = stream.update_location(location_id, 'away')
If you choose to recieve notifications when alerts become active or end for a location, you need to provide a valid url endpoint where the StreamLabs service will send the notifications. The following methods wrap the corresponding StreamLabs api endpoints as descriped in the Subscribe to Location Alerts section in the docs
subscription_id = stream.subscribe_to_location_alerts(location_id, 'https://your-endpoint')['subscription_id']
Once you recieve the confirmationToken
via your endpoint, update the subscription to start recieving alerts.
confirmation_token = 'CONFIRMATION_TOKEN'
subscription = stream.confirm_subscription(subscription_id, confirmation_token)
# subscription['status'] should be 'confirmed'
subscriptions = stream.get_location_subscriptions(location_id)
subscription = stream.get_subscription(subscription_id)
all_subscriptions = stream.get_subscriptions()
stream.delete_subscription(subscription_id)
This method will throw an Exception if the delete fails else returns a None
water_usage_summary = stream.get_location_water_usage_summary(location_id)
today = water_usage_summary['today']
this_month = water_usage_summary['thisMonth']
this_year = water_usage_summary['thisYear']
units = water_usage_summary['units']
At the very minimum you need to provide a startTime
for the reading you want to retrive.
from datetime import datetime, timezone, timedelta
yesterday = datetime.now(timezone.utc) - timedelta(days=1)
start_time = yesterday.isoformat(timespec='seconds')
usage = stream.get_location_water_usage(location_id, {'startTime': start_time})
This project was heavily inspired by streamlabswater-python