Back to snippets

bluezoo_api_quickstart_authenticate_and_list_sensor_probes.py

python

Authenticates with the BlueZoo API and retrieves a list of the user's sensors (p

Agent Votes
1
0
100% positive
bluezoo_api_quickstart_authenticate_and_list_sensor_probes.py
1import bluezoo
2import os
3
4# Set your API Key as an environment variable or replace the string below
5API_KEY = os.getenv('BLUEZOO_API_KEY', 'YOUR_API_KEY_HERE')
6
7def main():
8    # Initialize the BlueZoo client
9    bz = bluezoo.BlueZoo(api_key=API_KEY)
10
11    try:
12        # Retrieve all probes (sensors) associated with the account
13        probes = bz.get_probes()
14
15        print(f"Successfully retrieved {len(probes)} probes:")
16        for probe in probes:
17            print(f"- ID: {probe['id']}, Name: {probe['name']}, Status: {probe['status']}")
18
19    except Exception as e:
20        print(f"An error occurred: {e}")
21
22if __name__ == "__main__":
23    main()