From e678df76fa52751edd9c3371216a2232c77f1edb Mon Sep 17 00:00:00 2001 From: "Noerenberg, Stephan" Date: Tue, 4 Mar 2025 14:28:26 +0100 Subject: [PATCH 1/3] [ADD] Nibe S-Series Power Consumption Smarthome --- packages/modules/smarthome/nibe/__init__.py | 0 packages/modules/smarthome/nibe/smartnibe.py | 28 +++++++++++++++ packages/modules/smarthome/nibe/watt.py | 36 +++++++++++++++++++ packages/smarthome/smartcommon.py | 3 ++ .../legacy_smart_home/smarthomeconfig.php | 8 +++-- 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 packages/modules/smarthome/nibe/__init__.py create mode 100644 packages/modules/smarthome/nibe/smartnibe.py create mode 100644 packages/modules/smarthome/nibe/watt.py diff --git a/packages/modules/smarthome/nibe/__init__.py b/packages/modules/smarthome/nibe/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/modules/smarthome/nibe/smartnibe.py b/packages/modules/smarthome/nibe/smartnibe.py new file mode 100644 index 0000000000..cbaebda9be --- /dev/null +++ b/packages/modules/smarthome/nibe/smartnibe.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 +from smarthome.smartbase import Sbase +import logging + +log = logging.getLogger(__name__) + + +class Snibe(Sbase): + def __init__(self) -> None: + # setting + super().__init__() + log.debug('__init__ Snibe executed') + + def getwatt(self, uberschuss: int, uberschussoffset: int) -> None: + self.prewatt(uberschuss, uberschussoffset) + argumentList = ['python3', self._prefixpy + 'nibe/watt.py', + str(self.device_nummer), str(self._device_ip) + ] + try: + self.callpro(argumentList) + self.answer = self.readret() + self.newwatt = int(self.answer['power']) + except Exception as e1: + log.warning("(" + str(self.device_nummer) + + ") Leistungsmessung %s %d %s Fehlermeldung: %s " + % ('nibe', self.device_nummer, + str(self._device_ip), str(e1))) + self.postwatt() \ No newline at end of file diff --git a/packages/modules/smarthome/nibe/watt.py b/packages/modules/smarthome/nibe/watt.py new file mode 100644 index 0000000000..21552e6f8f --- /dev/null +++ b/packages/modules/smarthome/nibe/watt.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 +import sys +import json +from pymodbus.client.sync import ModbusTcpClient + +# get variables from arguments +devicenumber = str(sys.argv[1]) # SmartHome device number +SERVER_HOST = str(sys.argv[2]) # IP of server to connect to + +SERVER_PORT = "502" # TCP port to connect to, should be moved into argument as well + +# Registers: +# https://www.waermepumpen-24.de/fileadmin/kaelteklima/Dokumente/W%C3%A4rmepumpen/modbus-ih-s-serie-v-2335.pdf +# 2166 power +# 2740 configure SG Ready input A or B via Modbus +# 2741 activate/deactive Modbus Aux function - can be enabled directly on Heatpump menu 7.4 + +CurrentPowerRegisterAddress = 2166 # register for current power reading + +# need to specify framer to enable RTUoverTCP +client = ModbusTcpClient(SERVER_HOST, SERVER_PORT) + +# Aktueller Verbrauch +resp = client.read_input_registers(CurrentPowerRegisterAddress, 1, unit=1) + +if resp and hasattr(resp, "registers"): + CurrentPower = resp.registers[0] # Get the first register value +else: + CurrentPower = None # Handle error case + +answer = '{"power":' + str(CurrentPower) + '}' +f1 = open('/var/www/html/openWB/ramdisk/smarthome_device_ret' + str(devicenumber), 'w') +json.dump(answer, f1) +f1.close() + +client.close() # clean disconnect from modbus server \ No newline at end of file diff --git a/packages/smarthome/smartcommon.py b/packages/smarthome/smartcommon.py index 5ab6395436..662a280863 100644 --- a/packages/smarthome/smartcommon.py +++ b/packages/smarthome/smartcommon.py @@ -15,6 +15,7 @@ from modules.smarthome.nxdacxx.smartnxdacxx import Snxdacxx from modules.smarthome.acthor.smartacthor import Sacthor from modules.smarthome.avmhomeautomation.smartavm import Savm +from modules.smarthome.nibe.smartnibe import Snibe from smarthome.smartbase import Sbase from typing import Dict, Tuple, Any import paho.mqtt.client as mqtt @@ -310,6 +311,8 @@ def update_devices() -> None: mydevice = Shttp() elif (device_type == 'mystrom'): mydevice = Smystrom() + elif (device_type == 'nibe'): + mydevice = Snibe() else: mydevice = Sbase() mydevice.updatepar(input_param) diff --git a/web/settings/modules/legacy_smart_home/smarthomeconfig.php b/web/settings/modules/legacy_smart_home/smarthomeconfig.php index 4e4be3d92c..90d138658b 100644 --- a/web/settings/modules/legacy_smart_home/smarthomeconfig.php +++ b/web/settings/modules/legacy_smart_home/smarthomeconfig.php @@ -93,6 +93,7 @@ + Dieser Gerätetyp wird nicht in die Regelung eingebunden und es können keine Schalthandlungen ausgeführt oder Sensoren eingelesen werden. Es ist jedoch eine separate Leistungsmessung möglich, um reine Verbraucher zu erfassen. @@ -203,6 +204,9 @@ Mit diesem Typ werden SmartHome Geräte des Herstellers MyStrom unterstützt.
+ + Abfrage der aktuellen Leistung von Nibe S-Series Wärmepumpen. + @@ -309,7 +313,7 @@ -
+

@@ -481,7 +485,7 @@
-
+

From ca7ad482615f4e6520bde9cb5f5d20329938435e Mon Sep 17 00:00:00 2001 From: "Noerenberg, Stephan" Date: Wed, 5 Mar 2025 13:04:28 +0100 Subject: [PATCH 2/3] Fixe Flake8 issues --- packages/modules/smarthome/nibe/smartnibe.py | 2 +- packages/modules/smarthome/nibe/watt.py | 2 +- packages/smarthome/smartcommon.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/modules/smarthome/nibe/smartnibe.py b/packages/modules/smarthome/nibe/smartnibe.py index cbaebda9be..0a479dedb2 100644 --- a/packages/modules/smarthome/nibe/smartnibe.py +++ b/packages/modules/smarthome/nibe/smartnibe.py @@ -25,4 +25,4 @@ def getwatt(self, uberschuss: int, uberschussoffset: int) -> None: ") Leistungsmessung %s %d %s Fehlermeldung: %s " % ('nibe', self.device_nummer, str(self._device_ip), str(e1))) - self.postwatt() \ No newline at end of file + self.postwatt() diff --git a/packages/modules/smarthome/nibe/watt.py b/packages/modules/smarthome/nibe/watt.py index 21552e6f8f..3b9bc3f286 100644 --- a/packages/modules/smarthome/nibe/watt.py +++ b/packages/modules/smarthome/nibe/watt.py @@ -33,4 +33,4 @@ json.dump(answer, f1) f1.close() -client.close() # clean disconnect from modbus server \ No newline at end of file +client.close() # clean disconnect from modbus server diff --git a/packages/smarthome/smartcommon.py b/packages/smarthome/smartcommon.py index 662a280863..7b6d958a41 100644 --- a/packages/smarthome/smartcommon.py +++ b/packages/smarthome/smartcommon.py @@ -312,7 +312,7 @@ def update_devices() -> None: elif (device_type == 'mystrom'): mydevice = Smystrom() elif (device_type == 'nibe'): - mydevice = Snibe() + mydevice = Snibe() else: mydevice = Sbase() mydevice.updatepar(input_param) From c81a137dc926bf2ca7f267664676a52e2649a38d Mon Sep 17 00:00:00 2001 From: "Noerenberg, Stephan" Date: Tue, 18 Mar 2025 09:06:42 +0100 Subject: [PATCH 3/3] Reverted smarthomeconfig.php to state from 3575fbf --- .../modules/legacy_smart_home/smarthomeconfig.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/web/settings/modules/legacy_smart_home/smarthomeconfig.php b/web/settings/modules/legacy_smart_home/smarthomeconfig.php index 90d138658b..4e4be3d92c 100644 --- a/web/settings/modules/legacy_smart_home/smarthomeconfig.php +++ b/web/settings/modules/legacy_smart_home/smarthomeconfig.php @@ -93,7 +93,6 @@ - Dieser Gerätetyp wird nicht in die Regelung eingebunden und es können keine Schalthandlungen ausgeführt oder Sensoren eingelesen werden. Es ist jedoch eine separate Leistungsmessung möglich, um reine Verbraucher zu erfassen. @@ -204,9 +203,6 @@ Mit diesem Typ werden SmartHome Geräte des Herstellers MyStrom unterstützt.
- - Abfrage der aktuellen Leistung von Nibe S-Series Wärmepumpen. -
@@ -313,7 +309,7 @@
-
+

@@ -485,7 +481,7 @@
-
+