Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
28 changes: 28 additions & 0 deletions packages/modules/smarthome/nibe/smartnibe.py
Original file line number Diff line number Diff line change
@@ -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()
36 changes: 36 additions & 0 deletions packages/modules/smarthome/nibe/watt.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions packages/smarthome/smartcommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down