Skip to content

Commit 5ff3a83

Browse files
authored
Merge pull request #161 from bootix/script-interface
## 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
2 parents b20a21d + 0fb7702 commit 5ff3a83

5 files changed

Lines changed: 74 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## V1.85
4+
### script
5+
* Added shell script based powermeter interface (USE_SCRIPT)
6+
### config
7+
* Added parameters for shell script based powermeter interface (SCRIPT_)
8+
### bash script
9+
* Added example shell script for usage with Victron Multiplus II (GetPowerFromVictronMultiplus.sh)
10+
###
11+
* Updated supported interface list in README.md with new shell script based powermeter
12+
313
## V1.84
414
### script
515
* Add support for priority mixed-mode (combination of battery powered and non-battery powered inverters).

GetPowerFromVictronMultiplus.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#! /bin/sh
2+
3+
# Script to read powermeter values from a Victron Multiplus II
4+
# Needs "mbpoll" (command line utility to communicate with ModBus slave) to be installed, e.g. "apt install mbpoll"
5+
# Usage: GetPowerFromVictronMultiplus <ip-address> [<username>] [<password>]
6+
7+
8+
# read registers 820-822 via ModbusTCP
9+
VE_SYSTEM=`mbpoll "$1" -a 100 -r 820 -c 3 -t 3 -0 -1 | grep "\[.*\]:"`
10+
if [ $? -ne 0 ]; then
11+
# failed, one more try
12+
sleep 1
13+
VE_SYSTEM=`mbpoll "$1" -a 100 -r 820 -c 3 -t 3 -0 -1 | grep "\[.*\]:"`
14+
if [ $? -ne 0 ]; then
15+
type mbpoll > /dev/null 2>&1
16+
if [ $? -ne 0 ]; then
17+
echo "$0: mbpoll must be installed!"
18+
else
19+
echo 0
20+
fi
21+
exit 1
22+
fi
23+
fi
24+
25+
# /Ac/Grid/L1/Power
26+
AC_GRID_L1=`echo "$VE_SYSTEM" | sed -n -e "s/\[820\]:.*(\(.*\)).*/\1/p" -e "s/\[820\]:[^0-9][^0-9]*\(.*\)/\1/p"`
27+
28+
# /Ac/Grid/L2/Power
29+
AC_GRID_L2=`echo "$VE_SYSTEM" | sed -n -e "s/\[821\]:.*(\(.*\)).*/\1/p" -e "s/\[821\]:[^0-9][^0-9]*\(.*\)/\1/p"`
30+
31+
# /Ac/Grid/L3/Power
32+
AC_GRID_L3=`echo "$VE_SYSTEM" | sed -n -e "s/\[822\]:.*(\(.*\)).*/\1/p" -e "s/\[822\]:[^0-9][^0-9]*\(.*\)/\1/p"`
33+
34+
expr "$AC_GRID_L1" + "$AC_GRID_L2" + "$AC_GRID_L3"

HoymilesZeroExport.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
__author__ = "Tobias Kraft"
18-
__version__ = "1.84"
18+
__version__ = "1.85"
1919

2020
import requests
2121
import time
@@ -30,6 +30,7 @@
3030
from packaging import version
3131
import argparse
3232
import json
33+
import subprocess
3334

3435
logging.basicConfig(
3536
format='%(asctime)s %(levelname)-8s %(message)s',
@@ -1057,6 +1058,17 @@ def SetPowerStatus(self, pInverterId: int, pActive: bool):
10571058
if response['type'] != 'success':
10581059
raise Exception(f"Error: SetPowerStatus error: {response['message']}")
10591060

1061+
class Script(Powermeter):
1062+
def __init__(self, file: str, ip: str, user: str, password: str):
1063+
self.file = file
1064+
self.ip = ip
1065+
self.user = user
1066+
self.password = password
1067+
1068+
def GetPowermeterWatts(self):
1069+
power = subprocess.check_output([self.file, self.ip, self.user, self.password])
1070+
return CastToInt(power)
1071+
10601072

10611073
def CreatePowermeter() -> Powermeter:
10621074
shelly_ip = config.get('SHELLY', 'SHELLY_IP')
@@ -1115,6 +1127,13 @@ def CreatePowermeter() -> Powermeter:
11151127
config.get('VZLOGGER', 'VZL_PORT'),
11161128
config.get('VZLOGGER', 'VZL_UUID')
11171129
)
1130+
elif config.getboolean('SELECT_POWERMETER', 'USE_SCRIPT'):
1131+
return Script(
1132+
config.get('SCRIPT', 'SCRIPT_FILE'),
1133+
config.get('SCRIPT', 'SCRIPT_IP'),
1134+
config.get('SCRIPT', 'SCRIPT_USER'),
1135+
config.get('SCRIPT', 'SCRIPT_PASS')
1136+
)
11181137
else:
11191138
raise Exception("Error: no powermeter defined!")
11201139

HoymilesZeroExport_Config.ini

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# ---------------------------------------------------------------------
2020

2121
[VERSION]
22-
VERSION = 1.83
22+
VERSION = 1.85
2323

2424
[SELECT_DTU]
2525
# --- define your DTU (only one) ---
@@ -37,6 +37,7 @@ USE_EMLOG = false
3737
USE_IOBROKER = false
3838
USE_HOMEASSISTANT = false
3939
USE_VZLOGGER = false
40+
USE_SCRIPT = false
4041

4142
[AHOY_DTU]
4243
# --- defines for AHOY-DTU ---
@@ -121,6 +122,13 @@ VZL_PORT = 2081
121122
# you need to specify the uuid of the vzlogger channel for the reading OBIS(16.7.0) (aktuelle Gesamtwirkleistung)
122123
VZL_UUID = 30c6c501-9a3c-4b0f-bda5-1d1769904463
123124

125+
[SCRIPT]
126+
# --- defines for Shell Script Smartmeter Modul ---
127+
SCRIPT_IP = xxx.xxx.xxx.xx
128+
SCRIPT_FILE = GetPowerFromVictronMultiplus.sh
129+
SCRIPT_USER =
130+
SCRIPT_PASS =
131+
124132
[SELECT_INTERMEDIATE_METER]
125133
# 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
126134
# --- define your intermediate meter - if you don´t have one set the following defines to false to use the value from your DTU---

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This script does not use MQTT, it's based on webapi communication.
1717
- [HomeAssistant](https://www.home-assistant.io/)
1818
- [Volkszaehler (VZLogger)](https://volkszaehler.org/)
1919
- [ESPHome](https://esphome.io/)
20+
- shell script based interface
2021
- easy to implement new smart meter modules supporting WebAPI / JSON
2122

2223
### Supported DTU and Inverters

0 commit comments

Comments
 (0)