Browse Source

pypackage add powerfactor where possible

pull/54/head
Jan-Jonas Sämann 3 years ago
parent
commit
88e9de42b8
  1. 6
      tools/rpi/hoymiles/__main__.py
  2. 10
      tools/rpi/hoymiles/decoders/__init__.py
  3. 4
      tools/rpi/hoymiles/outputs.py

6
tools/rpi/hoymiles/__main__.py

@ -81,7 +81,9 @@ def poll_inverter(inverter, retries=4):
if isinstance(result, hoymiles.decoders.StatusResponse):
data = result.__dict__()
if hoymiles.HOYMILES_DEBUG_LOGGING:
print(f'{c_datetime} Decoded: {data["temperature"]}', end='')
print(f'{c_datetime} Decoded: temp={data["temperature"]}', end='')
if data['powerfactor'] is not None:
print(f', pf={data["powerfactor"]}', end='')
phase_id = 0
for phase in data['phases']:
print(f' phase{phase_id}=voltage:{phase["voltage"]}, current:{phase["current"]}, power:{phase["power"]}, frequency:{data["frequency"]}', end='')
@ -129,6 +131,8 @@ def mqtt_send_status(broker, inverter_ser, data, topic=None):
broker.publish(f'{topic}/emeter-dc/{string_id}/current', string['current'])
string_id = string_id + 1
# Global
if data['powerfactor'] is not None:
broker.publish(f'{topic}/pf', data['powerfactor'])
broker.publish(f'{topic}/frequency', data['frequency'])
broker.publish(f'{topic}/temperature', data['temperature'])

10
tools/rpi/hoymiles/decoders/__init__.py

@ -45,6 +45,7 @@ class StatusResponse(Response):
e_keys = ['voltage','current','power','energy_total','energy_daily','powerfactor']
temperature = None
frequency = None
powerfactor = None
def unpack(self, fmt, base):
"""
@ -118,6 +119,7 @@ class StatusResponse(Response):
data['strings'] = self.strings
data['temperature'] = self.temperature
data['frequency'] = self.frequency
data['powerfactor'] = self.powerfactor
data['time'] = self.time_rx
return data
@ -534,6 +536,10 @@ class Hm600Decode0B(StatusResponse):
""" Grid frequency in Hertz """
return self.unpack('>H', 28)[0]/100
@property
def powerfactor(self):
""" Powerfactor """
return self.unpack('>H', 36)[0]/1000
@property
def temperature(self):
""" Inverter temperature in °C """
return self.unpack('>H', 38)[0]/10
@ -654,6 +660,10 @@ class Hm1200Decode0B(StatusResponse):
""" Grid frequency in Hertz """
return self.unpack('>H', 48)[0]/100
@property
def powerfactor(self):
""" Powerfactor """
return self.unpack('>H', 56)[0]/1000
@property
def temperature(self):
""" Inverter temperature in °C """
return self.unpack('>H', 58)[0]/10

4
tools/rpi/hoymiles/outputs.py

@ -114,6 +114,8 @@ class InfluxOutputPlugin(OutputPluginFactory):
data_stack.append(f'{measurement},string={string_id},type=current value={string["current"]:3f} {ctime}')
string_id = string_id + 1
# Global
if data['powerfactor'] is not None:
data_stack.append(f'{measurement},type=pf value={data["powerfactor"]:f} {ctime}')
data_stack.append(f'{measurement},type=frequency value={data["frequency"]:.3f} {ctime}')
data_stack.append(f'{measurement},type=temperature value={data["temperature"]:.2f} {ctime}')
@ -193,5 +195,7 @@ class MqttOutputPlugin(OutputPluginFactory):
self.client.publish(f'{topic}/emeter-dc/{string_id}/current', string['current'])
string_id = string_id + 1
# Global
if data['powerfactor'] is not None:
self.client.publish(f'{topic}/pf', data['powerfactor'])
self.client.publish(f'{topic}/frequency', data['frequency'])
self.client.publish(f'{topic}/temperature', data['temperature'])

Loading…
Cancel
Save