diff --git a/CHANGELOG.md b/CHANGELOG.md index 2033627..130ff37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## V1.85 +### script +* Added shell script based powermeter interface (USE_SCRIPT) +### config +* Added parameters for shell script based powermeter interface (SCRIPT_) +### bash script +* Added example shell script for usage with Victron Multiplus II (GetPowerFromVictronMultiplus.sh) +### +* Updated supported interface list in README.md with new shell script based powermeter + ## V1.84 ### script * Add support for priority mixed-mode (combination of battery powered and non-battery powered inverters). diff --git a/GetPowerFromVictronMultiplus.sh b/GetPowerFromVictronMultiplus.sh new file mode 100755 index 0000000..3fc4c9f --- /dev/null +++ b/GetPowerFromVictronMultiplus.sh @@ -0,0 +1,34 @@ +#! /bin/sh + +# Script to read powermeter values from a Victron Multiplus II +# Needs "mbpoll" (command line utility to communicate with ModBus slave) to be installed, e.g. "apt install mbpoll" +# Usage: GetPowerFromVictronMultiplus [] [] + + +# read registers 820-822 via ModbusTCP +VE_SYSTEM=`mbpoll "$1" -a 100 -r 820 -c 3 -t 3 -0 -1 | grep "\[.*\]:"` +if [ $? -ne 0 ]; then + # failed, one more try + sleep 1 + VE_SYSTEM=`mbpoll "$1" -a 100 -r 820 -c 3 -t 3 -0 -1 | grep "\[.*\]:"` + if [ $? -ne 0 ]; then + type mbpoll > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "$0: mbpoll must be installed!" + else + echo 0 + fi + exit 1 + fi +fi + +# /Ac/Grid/L1/Power +AC_GRID_L1=`echo "$VE_SYSTEM" | sed -n -e "s/\[820\]:.*(\(.*\)).*/\1/p" -e "s/\[820\]:[^0-9][^0-9]*\(.*\)/\1/p"` + +# /Ac/Grid/L2/Power +AC_GRID_L2=`echo "$VE_SYSTEM" | sed -n -e "s/\[821\]:.*(\(.*\)).*/\1/p" -e "s/\[821\]:[^0-9][^0-9]*\(.*\)/\1/p"` + +# /Ac/Grid/L3/Power +AC_GRID_L3=`echo "$VE_SYSTEM" | sed -n -e "s/\[822\]:.*(\(.*\)).*/\1/p" -e "s/\[822\]:[^0-9][^0-9]*\(.*\)/\1/p"` + +expr "$AC_GRID_L1" + "$AC_GRID_L2" + "$AC_GRID_L3" diff --git a/HoymilesZeroExport.py b/HoymilesZeroExport.py index befe03a..fdf293a 100644 --- a/HoymilesZeroExport.py +++ b/HoymilesZeroExport.py @@ -15,7 +15,7 @@ # along with this program. If not, see . __author__ = "Tobias Kraft" -__version__ = "1.84" +__version__ = "1.85" import requests import time @@ -30,6 +30,7 @@ from packaging import version import argparse import json +import subprocess logging.basicConfig( format='%(asctime)s %(levelname)-8s %(message)s', @@ -1057,6 +1058,17 @@ def SetPowerStatus(self, pInverterId: int, pActive: bool): if response['type'] != 'success': raise Exception(f"Error: SetPowerStatus error: {response['message']}") +class Script(Powermeter): + def __init__(self, file: str, ip: str, user: str, password: str): + self.file = file + self.ip = ip + self.user = user + self.password = password + + def GetPowermeterWatts(self): + power = subprocess.check_output([self.file, self.ip, self.user, self.password]) + return CastToInt(power) + def CreatePowermeter() -> Powermeter: shelly_ip = config.get('SHELLY', 'SHELLY_IP') @@ -1115,6 +1127,13 @@ def CreatePowermeter() -> Powermeter: config.get('VZLOGGER', 'VZL_PORT'), config.get('VZLOGGER', 'VZL_UUID') ) + elif config.getboolean('SELECT_POWERMETER', 'USE_SCRIPT'): + return Script( + config.get('SCRIPT', 'SCRIPT_FILE'), + config.get('SCRIPT', 'SCRIPT_IP'), + config.get('SCRIPT', 'SCRIPT_USER'), + config.get('SCRIPT', 'SCRIPT_PASS') + ) else: raise Exception("Error: no powermeter defined!") diff --git a/HoymilesZeroExport_Config.ini b/HoymilesZeroExport_Config.ini index 3c84fb1..edeca54 100644 --- a/HoymilesZeroExport_Config.ini +++ b/HoymilesZeroExport_Config.ini @@ -19,7 +19,7 @@ # --------------------------------------------------------------------- [VERSION] -VERSION = 1.83 +VERSION = 1.85 [SELECT_DTU] # --- define your DTU (only one) --- @@ -37,6 +37,7 @@ USE_EMLOG = false USE_IOBROKER = false USE_HOMEASSISTANT = false USE_VZLOGGER = false +USE_SCRIPT = false [AHOY_DTU] # --- defines for AHOY-DTU --- @@ -121,6 +122,13 @@ VZL_PORT = 2081 # you need to specify the uuid of the vzlogger channel for the reading OBIS(16.7.0) (aktuelle Gesamtwirkleistung) VZL_UUID = 30c6c501-9a3c-4b0f-bda5-1d1769904463 +[SCRIPT] +# --- defines for Shell Script Smartmeter Modul --- +SCRIPT_IP = xxx.xxx.xxx.xx +SCRIPT_FILE = GetPowerFromVictronMultiplus.sh +SCRIPT_USER = +SCRIPT_PASS = + [SELECT_INTERMEDIATE_METER] # if you have an intermediate meter ("Zwischenzähler") to measure the outputpower of your inverter you can set it here. It is faster than the DTU current_power value # --- define your intermediate meter - if you don´t have one set the following defines to false to use the value from your DTU--- diff --git a/README.md b/README.md index 8d7a4de..00e9d7b 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ This script does not use MQTT, it's based on webapi communication. - [HomeAssistant](https://www.home-assistant.io/) - [Volkszaehler (VZLogger)](https://volkszaehler.org/) - [ESPHome](https://esphome.io/) +- shell script based interface - easy to implement new smart meter modules supporting WebAPI / JSON ### Supported DTU and Inverters