collect outside temperature

This commit is contained in:
2025-10-21 20:19:13 +02:00
parent 531506cfe4
commit 069b8b3e0e
3 changed files with 64 additions and 5 deletions
+32
View File
@@ -0,0 +1,32 @@
import urllib.request
from fritz_rest import get_sid
class FritzSmartHome:
def __init__(self, host: str):
self.host = host
self.sid = None
def session_start(self, username: str, password: str):
self.sid = get_sid(self.host, username, password)
def session_end(self):
self.sid = None
def query(self, ain: str, cmd: str):
if self.sid is None:
raise Exception("Start Session")
with urllib.request.urlopen(f"{self.host}/webservices/homeautoswitch.lua?ain={ain}&switchcmd={cmd}&sid={self.sid}") as f:
return f.read()
def get_temperature(hnd: FritzSmartHome, ain: str):
response = hnd.query(ain, 'gettemperature')
value = float(response.decode()) / 10
return value
if __name__ == '__main__':
f = FritzSmartHome("http://192.168.22.4")
f.session_start("fritz6632", "body9517")
temp = get_temperature(f, "116570135300")
print(f"Temp = {temp}°C")