Skip to content

Commit

Permalink
Merge pull request #161 from bootix/script-interface
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
reserve85 authored Mar 7, 2024
2 parents b20a21d + 0fb7702 commit 5ff3a83
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
34 changes: 34 additions & 0 deletions GetPowerFromVictronMultiplus.sh
Original file line number Diff line number Diff line change
@@ -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 <ip-address> [<username>] [<password>]


# 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"
21 changes: 20 additions & 1 deletion HoymilesZeroExport.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__author__ = "Tobias Kraft"
__version__ = "1.84"
__version__ = "1.85"

import requests
import time
Expand All @@ -30,6 +30,7 @@
from packaging import version
import argparse
import json
import subprocess

logging.basicConfig(
format='%(asctime)s %(levelname)-8s %(message)s',
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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!")

Expand Down
10 changes: 9 additions & 1 deletion HoymilesZeroExport_Config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# ---------------------------------------------------------------------

[VERSION]
VERSION = 1.83
VERSION = 1.85

[SELECT_DTU]
# --- define your DTU (only one) ---
Expand All @@ -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 ---
Expand Down Expand Up @@ -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---
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ff3a83

Please sign in to comment.