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..0a479dedb2 --- /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() diff --git a/packages/modules/smarthome/nibe/watt.py b/packages/modules/smarthome/nibe/watt.py new file mode 100644 index 0000000000..3b9bc3f286 --- /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 diff --git a/packages/smarthome/smartcommon.py b/packages/smarthome/smartcommon.py index 5ab6395436..7b6d958a41 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)