Last active
July 31, 2023 15:20
-
-
Save plopp/d16615deea55e8500dab4ca76349e9f3 to your computer and use it in GitHub Desktop.
Revisions
-
plopp revised this gist
Apr 1, 2021 . 1 changed file with 22 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,26 +34,31 @@ def set_room_target_temperature(roomId, temperature, token): def get_homes_info(token): headers = {"Authorization": "Bearer " + token} response = requests.get(API_URL + "/rest/v1/content/", headers=headers) if response.status_code == 200: json = response.json() for room in json["rooms"]: roomName = room["name"] targetTemperature = room["targetTemperature"] / 100.0 currentTemperature = 0 if "temperature" in room: currentTemperature = room["temperature"] / 100.0 print( "Room: %15s, Target: %5.2fC, Temperature: %5.2fC, id: %5d" % (roomName, targetTemperature, currentTemperature, room["id"]) ) elif response.status_code == 429: print("Error: Too many requests to API. Wait before making a new query.") else: print("Unknown response code", response.status_code) token = get_token() if token: # Change the temperature to 24 C in the room with an Id of 196342 # Replace the 196342 with the room id from the get_homes_info output set_room_target_temperature(196342, 2400, token) get_homes_info(token) -
plopp revised this gist
Apr 1, 2021 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,11 +17,11 @@ def get_token(): # Authenticate and obtain JWT token oauthClient = sanction.Client(token_endpoint=API_URL + "/auth/token") oauthClient.request_token( grant_type="password", username=CLIENT_ID, password=CLIENT_SECRET ) return oauthClient.access_token def set_room_target_temperature(roomId, temperature, token): -
plopp revised this gist
Apr 1, 2021 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # install dependencies with: pip install requests sanction import requests import sanction -
plopp created this gist
Apr 1, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ # install dependencies with: pip install requests sanction import requests import sanction CLIENT_ID = "112395" # replace with your client ID (see Adax WiFi app,Account Section) CLIENT_SECRET = "6imtpX63D5WoRyKh" # replace with your client ID (see Adax WiFi app,Account Section) API_URL = "https://api-1.adax.no/client-api" def get_token(): # Authenticate and obtain JWT token oauthClinet = sanction.Client(token_endpoint=API_URL + "/auth/token") oauthClinet.request_token( grant_type="password", username=CLIENT_ID, password=CLIENT_SECRET ) return oauthClinet.access_token def set_room_target_temperature(roomId, temperature, token): # Sets target temperature of the room headers = {"Authorization": "Bearer " + token} json = {"rooms": [{"id": roomId, "targetTemperature": str(temperature)}]} requests.post(API_URL + "/rest/v1/control/", json=json, headers=headers) def get_homes_info(token): headers = {"Authorization": "Bearer " + token} response = requests.get(API_URL + "/rest/v1/content/", headers=headers) json = response.json() for room in json["rooms"]: roomName = room["name"] targetTemperature = room["targetTemperature"] / 100.0 currentTemperature = 0 if "temperature" in room: currentTemperature = room["temperature"] / 100.0 print( "Room: %15s, Target: %5.2fC, Temperature: %5.2fC, id: %5d" % (roomName, targetTemperature, currentTemperature, room["id"]) ) token = get_token() # Change the temperature to 24 C in the room with an Id of 196342 set_room_target_temperature(196342, 2400, token) # Replace the 196342 with the room id from the get_homes_info output get_homes_info(token)