This repository has been archived by the owner on May 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
r3temp.py
55 lines (43 loc) · 1.64 KB
/
r3temp.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import requests
import json
class r3temp():
def __init__(self):
self.loadStatusData()
def loadTemp(self):
# to be run on the device connected to the sensor!
tfile = open("/sys/bus/w1/devices/10-000801375be4/w1_slave")
text = tfile.read()
tfile.close()
secondline = text.split("\n")[1]
temperaturedata = secondline.split(" ")[9]
temperature = float(temperaturedata[2:])
temperature = temperature / 1000
return temperature
def getTempFromSensor(self):
# to be run on the device connected to the sensor!
while True:
temp = self.loadTemp()
if temp < 85:
break
return temp
def loadStatusData(self):
resp = requests.get(url="https://realraum.at/status.json")
self.data = resp.json()
def getTempByName(self, name):
try:
return filter(lambda x: x['name'] == name, self.data[
'sensors']['temperature'])[0]['value']
except Exception:
return 'error'
def getTemp(self):
return self.getTempByName('Temp@LoTHR')
def printInfo():
api = r3temp()
print 'Temp Outside: ', api.getTempByName('Temp@Outside')
print 'Temp in LoTHR: ', api.getTempByName('Temp@LoTHR')
print 'Temp in CX: ', api.getTempByName('Temp@CX')
print 'Temp in OLGA Room: ', api.getTempByName('Temp@OLGA Room')
print 'Temp in OLGA freezer: ', api.getTempByName('Temp@OLGA freezer')
print 'Temp in UPS Battery: ', api.getTempByName('Temp@UPS Yellow Battery')
if __name__ == '__main__':
printInfo()