Skip to content

Commit

Permalink
Merge pull request #135 from reserve85/emlog_fix
Browse files Browse the repository at this point in the history
EMLOG Fix
  • Loading branch information
reserve85 authored Feb 8, 2024
2 parents 8aa3285 + ee40ae6 commit e8432a4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## V1.72
### script
* Emlog fix https://github.com/reserve85/HoymilesZeroExport/issues/134 -> calculate power
### Config
* added `EMLOG_JSON_POWER_CALCULATE` to `EMLOG`

## V1.71
### script
* When intermediate meter is not available then try to get "ActualPower" from DTU
Expand Down
18 changes: 13 additions & 5 deletions 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.71"
__version__ = "1.72"

import requests
import time
Expand Down Expand Up @@ -825,17 +825,23 @@ def GetPowermeterWatts(self):
return CastToInt(CastToInt(ParsedData['1.7.0']) - CastToInt(ParsedData['2.7.0']))

class Emlog(Powermeter):
def __init__(self, ip: str, meterindex: str):
def __init__(self, ip: str, meterindex: str, json_power_calculate: bool):
self.ip = ip
self.meterindex = meterindex
self.json_power_calculate = json_power_calculate

def GetJson(self, path):
url = f'http://{self.ip}{path}'
return requests.get(url, timeout=10).json()

def GetPowermeterWatts(self):
ParsedData = self.GetJson(f'/pages/getinformation.php?heute&meterindex={self.meterindex}')
return CastToInt(ParsedData['Leistung170'])
if not self.json_power_calculate:
return CastToInt(ParsedData['Leistung170'])
else:
input = ParsedData['Leistung170']
ouput = ParsedData['Leistung270']
return CastToInt(input - ouput)

class IoBroker(Powermeter):
def __init__(self, ip: str, port: str, current_power_alias: str, power_calculate: bool, power_input_alias: str, power_output_alias: str):
Expand Down Expand Up @@ -973,7 +979,8 @@ def CreatePowermeter() -> Powermeter:
elif config.getboolean('SELECT_POWERMETER', 'USE_EMLOG'):
return Emlog(
config.get('EMLOG', 'EMLOG_IP'),
config.get('EMLOG', 'EMLOG_METERINDEX')
config.get('EMLOG', 'EMLOG_METERINDEX'),
config.getboolean('EMLOG', 'EMLOG_JSON_POWER_CALCULATE', fallback=False)
)
elif config.getboolean('SELECT_POWERMETER', 'USE_IOBROKER'):
return IoBroker(
Expand Down Expand Up @@ -1036,7 +1043,8 @@ def CreateIntermediatePowermeter(dtu: DTU) -> Powermeter:
elif config.getboolean('SELECT_INTERMEDIATE_METER', 'USE_EMLOG_INTERMEDIATE'):
return Emlog(
config.get('INTERMEDIATE_EMLOG', 'EMLOG_IP_INTERMEDIATE'),
config.get('INTERMEDIATE_EMLOG', 'EMLOG_METERINDEX_INTERMEDIATE')
config.get('INTERMEDIATE_EMLOG', 'EMLOG_METERINDEX_INTERMEDIATE'),
config.getboolean('INTERMEDIATE_EMLOG', 'EMLOG_JSON_POWER_CALCULATE', fallback=False)
)
elif config.getboolean('SELECT_INTERMEDIATE_METER', 'USE_IOBROKER_INTERMEDIATE'):
return IoBroker(
Expand Down
4 changes: 3 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.68
VERSION = 1.72

[SELECT_DTU]
# --- define your DTU (only one) ---
Expand Down Expand Up @@ -84,6 +84,8 @@ SHRDZM_PASS =
# --- defines for EMLOG (electronic meter log) System ---
EMLOG_IP = xxx.xxx.xxx.xxx
EMLOG_METERINDEX =
# if your powermeter does NOT output the current power: you need to calculate it -> Power(W) = OBIS(1.7.0) - OBIS(2.7.0)
EMLOG_JSON_POWER_CALCULATE = TRUE

[IOBROKER]
# --- defines for IOBROKER (make sure you installed https://github.com/ioBroker/ioBroker.simple-api) ---
Expand Down

0 comments on commit e8432a4

Please sign in to comment.