Repository navigation
Expand file tree
/
Copy pathslideroom_on.py
More file actions
128 lines (107 loc) · 4.23 KB
/
Copy pathslideroom_on.py
File metadata and controls
128 lines (107 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import requests
import json
import libdyson
#Act 1: Get Ecobee Access Token
def get_ecobee_access_token(api_key, refresh_token):
url = "https://api.ecobee.com/token"
payload = {
'grant_type': 'refresh_token',
'refresh_token': refresh_token,
'client_id': api_key
}
response = requests.post(url, params=payload)
if response.status_code == 200:
return response.json() # This will return the access token and a new refresh token
else:
return response.json() # This will contain error information
# Replace 'your_api_key' and 'your_refresh_token' with your actual ecobee API key and refresh token
api_key = 'your_api_key'
refresh_token = 'your_refresh_token'
access_token_info = get_ecobee_access_token(api_key, refresh_token)
access_token = access_token_info['access_token']
# Act 2: Get current temp just for fun, then set ecobee to heat at home comfort setting
def get_thermostat_temperature(access_token, thermostat_id):
url = "https://api.ecobee.com/1/thermostat"
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
params = {
'json': '{"selection":{"selectionType":"thermostats","selectionMatch":"' + thermostat_id + '","includeRuntime":true}}'
}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
# Extracting temperature from the response
thermostat_info = data['thermostatList'][0]
current_temperature = thermostat_info['runtime']['actualTemperature'] / 10 # The temperature is reported in tenths of degrees
return current_temperature
else:
return response.json() # This will contain error information
# Replace 'your_thermostat_id' with your actual thermostat ID
thermostat_id = 'your_thermostat_id' # The identifier of your thermostat
temperature = get_thermostat_temperature(access_token, thermostat_id)
print(f"Current temperature: {temperature}°F")
def set_hvac_mode_to_heat(access_token, thermostat_id):
url = "https://api.ecobee.com/1/thermostat?format=json"
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
# Create the JSON payload to update the HVAC mode
payload = {
'selection': {
'selectionType': 'thermostats',
'selectionMatch': thermostat_id
},
'thermostat': {
'settings': {
'hvacMode': 'heat'
}
}
}
response = requests.post(url, headers=headers, json=payload)
if response.status_code == 200:
return "HVAC mode set to heat successfully."
else:
return response.json() # This will contain error information
result = set_hvac_mode_to_heat(access_token, thermostat_id)
print(result)
def set_comfort_setting_to_home(access_token, thermostat_id):
url = "https://api.ecobee.com/1/thermostat?format=json"
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
# Create the JSON payload to set the comfort setting to 'Home'
payload = {
'selection': {
'selectionType': 'thermostats',
'selectionMatch': thermostat_id
},
'functions': [{
'type': 'resumeProgram',
'params': {
'resumeAll': False
}
}]
}
response = requests.post(url, headers=headers, json=payload)
if response.status_code == 200:
return "Comfort setting set to 'Home' successfully."
else:
return response.json() # This will contain error information
result = set_comfort_setting_to_home(access_token, thermostat_id)
print(result)
# Act 3: Turn on the Dyson fan
# Replace these with your actual device's credentials
DEVICE_SERIAL = "your-dyson-serial"
DEVICE_CREDENTIAL = "your-dyson-credential"
DEVICE_IP = "your-dyson-ip"
# Connect to the device
device = libdyson.DysonPureHotCoolLink(serial=DEVICE_SERIAL, credential=DEVICE_CREDENTIAL, device_type=libdyson.DEVICE_TYPE_PURE_HOT_COOL_LINK)
device.connect(DEVICE_IP)
# Turn on the fan
device.turn_on()
device.disconnect()
print('Dyson fan appears to have turned on if no errors present above')