test knx und test lüftungsanlage added

This commit is contained in:
Nils Reiners
2026-02-20 20:49:27 +01:00
parent 7b00d622aa
commit 3f19cc518b
2 changed files with 118 additions and 10 deletions

71
test.py
View File

@@ -1,18 +1,69 @@
from pymodbus.client import ModbusTcpClient
import time
import struct
from pymodbus.client import ModbusTcpClient
MODBUS_IP="10.0.0.40"
client=ModbusTcpClient(MODBUS_IP, port=502)
client.connect()
MODBUS_IP = "10.0.0.40"
SLAVE_ID = 1
POLL = 2.0 # Sekunden
def u16_to_i16(u16):
return struct.unpack(">h", struct.pack(">H", u16 & 0xFFFF))[0]
def read_i16(client, addr, scale):
rr = client.read_input_registers(address=addr, count=1, slave=SLAVE_ID)
if rr.isError():
return None
raw = rr.registers[0]
if raw == 65535:
return None
return round(u16_to_i16(raw) / scale, 1)
def fmt(v):
return f"{v:5.1f}" if v is not None else " ---"
client = ModbusTcpClient(MODBUS_IP, port=502)
try:
rr = client.read_input_registers(30, count=3, slave=1)
print("Raw 30..32:", rr.registers)
if not client.connect():
raise RuntimeError("Modbus connect failed")
def as_int16(x):
return struct.unpack(">h", struct.pack(">H", x))[0]
print("Logging temperatures (Ctrl+C to stop)\n")
while True:
# Eintrittsluft = Mittelwert aus 3x0324 & 3x0323 (scale 100)
t_e1 = read_i16(client, 324, 100)
t_e2 = read_i16(client, 323, 100)
t_ein = None
if t_e1 is not None and t_e2 is not None:
t_ein = round((t_e1 + t_e2) / 2, 1)
# Zuluft -> 3x0614 (/10)
t_zuluft = read_i16(client, 614, 10)
# Abluft -> Mittelwert aus 3x0581 & 3x0582 (/10)
t_a1 = read_i16(client, 581, 10)
t_a2 = read_i16(client, 582, 10)
t_abluft = None
if t_a1 is not None and t_a2 is not None:
t_abluft = round((t_a1 + t_a2) / 2, 1)
# Fortluft -> 3x0301 (/100)
t_fortluft = read_i16(client, 301, 100)
ts = time.strftime("%H:%M:%S")
print(
f"{ts} | "
f"Eintritt: {fmt(t_ein)} °C | "
f"Zuluft: {fmt(t_zuluft)} °C | "
f"Abluft: {fmt(t_abluft)} °C | "
f"Fortluft: {fmt(t_fortluft)} °C"
)
time.sleep(POLL)
except KeyboardInterrupt:
print("\nStopped by user.")
for i, raw in enumerate(rr.registers, start=30):
print(i, "raw", raw, "int16", as_int16(raw), "scaled", as_int16(raw)/10.0)
finally:
client.close()