Compare commits

..

4 Commits

Author SHA1 Message Date
neuer a7d5b79251 Update csicsrf token 2024-08-12 22:23:24 +00:00
neuer 28d2f7fe30 Update url auf öffentliche Adresse 2024-08-12 22:15:24 +00:00
neuer 65ef6d9dad FHEM Datenabfrage-Skript erstellt 2024-08-12 22:06:26 +00:00
neuer 3c753a42a0 Initial commit: Projektstruktur erstellt 2024-08-12 21:12:18 +00:00
2 changed files with 37 additions and 3 deletions
-3
View File
@@ -1,3 +0,0 @@
# fhem-extract
Extract data from fhem for visualization and processing
+37
View File
@@ -0,0 +1,37 @@
import requests
# FHEM URL
# FHEM_URL = "http://192.168.2.200:8083/fhem"
FHEM_URL = "https://fhem.auwiesen2.de/fhem"
# Parameters including CSRF token
PARAMS = {
"cmd": "jsonlist2",
"XHR": "1",
"fwcsrf": "csrf_27835177929814" # CSRF token as a parameter
}
# Headers including CSRF token
HEADERS = {
"X-FHEM-csrfToken": "csrf_822558611144652",
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json"
}
# Send the request with both parameters and headers
response = requests.get(FHEM_URL, params=PARAMS, headers=HEADERS)
# Debugging: Check the status code and response content
print("Response Status Code:", response.status_code)
print("Response Content:", response.text)
try:
# Attempt to parse the response as JSON
data = response.json()
devices = data['Results']
for device in devices:
print(f"Device: {device['Name']}, State: {device['Internals']['STATE']}")
except requests.exceptions.JSONDecodeError:
print("Error: Failed to decode JSON response.")
except KeyError:
print("Error: Expected keys not found in the JSON data.")