-
Notifications
You must be signed in to change notification settings - Fork 0
/
homeassistant.py
39 lines (30 loc) · 1.03 KB
/
homeassistant.py
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
from requests import get
import configparser
import json
class HomeAssistant():
def __init__(self):
config = configparser.ConfigParser()
config.read('wallclock.conf')
self.config = config['HomeAssistant']
self.header = {
"Authorization": "Bearer " + self.config["token"],
"content-type": "application/json"
}
def getState(self,statename):
url = self.config['url'] + "states/" + statename
response = get(url,headers=self.header)
entities = response.json()
return entities
def getStates(self):
response = get(self.config['url'] + "states", headers=self.header)
print(response)
entities = response.json()
print(entities)
if __name__ == "__main__":
m = HomeAssistant()
r = m.getState("binary_sensor.allefenster")
print(r['attributes']['entity_id'])
for window in r['attributes']['entity_id']:
print(window)
w = m.getState(window)
print(w['state'])