mirror of
https://github.com/lumapu/ahoy.git
synced 2025-08-06 09:58:23 +02:00
rpi: calculate energy_total for whole inverter
This commit is contained in:
parent
36eadb73f1
commit
8c843af71d
3 changed files with 16 additions and 1 deletions
|
@ -106,8 +106,9 @@ def poll_inverter(inverter, do_init, retries=4):
|
|||
result = decoder.decode()
|
||||
if isinstance(result, hoymiles.decoders.StatusResponse):
|
||||
data = result.__dict__()
|
||||
|
||||
if hoymiles.HOYMILES_DEBUG_LOGGING:
|
||||
print(f'{c_datetime} Decoded: temp={data["temperature"]}', end='')
|
||||
print(f'{c_datetime} Decoded: temp={data["temperature"]}, total={data["energy_total"]/1000:.3f}', end='')
|
||||
if data['powerfactor'] is not None:
|
||||
print(f', pf={data["powerfactor"]}', end='')
|
||||
phase_id = 0
|
||||
|
@ -169,6 +170,8 @@ def mqtt_send_status(broker, inverter_ser, data, topic=None):
|
|||
broker.publish(f'{topic}/pf', data['powerfactor'])
|
||||
broker.publish(f'{topic}/frequency', data['frequency'])
|
||||
broker.publish(f'{topic}/temperature', data['temperature'])
|
||||
if data['energy_total'] is not None:
|
||||
broker.publish(f'{topic}/total', data['energy_total']/1000)
|
||||
|
||||
def mqtt_on_command(client, userdata, message):
|
||||
"""
|
||||
|
|
|
@ -169,6 +169,11 @@ class StatusResponse(Response):
|
|||
data['powerfactor'] = self.powerfactor
|
||||
data['event_count'] = self.event_count
|
||||
data['time'] = self.time_rx
|
||||
|
||||
data['energy_total'] = 0.0
|
||||
for string in data['strings']:
|
||||
data['energy_total'] += string['energy_total']
|
||||
|
||||
return data
|
||||
|
||||
class UnknownResponse(Response):
|
||||
|
|
|
@ -120,6 +120,8 @@ class InfluxOutputPlugin(OutputPluginFactory):
|
|||
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}')
|
||||
if data['energy_total'] is not None:
|
||||
data_stack.append(f'{measurement},type=total value={data["energy_total"]/1000:.3f} {ctime}')
|
||||
|
||||
self.api.write(self._bucket, self._org, data_stack)
|
||||
|
||||
|
@ -201,6 +203,8 @@ class MqttOutputPlugin(OutputPluginFactory):
|
|||
self.client.publish(f'{topic}/pf', data['powerfactor'])
|
||||
self.client.publish(f'{topic}/frequency', data['frequency'])
|
||||
self.client.publish(f'{topic}/temperature', data['temperature'])
|
||||
if data['energy_total'] is not None:
|
||||
self.client.publish(f'{topic}/total', data['energy_total']/1000)
|
||||
|
||||
try:
|
||||
import requests
|
||||
|
@ -256,6 +260,9 @@ class VzInverterOutput:
|
|||
self.try_publish(ts, f'frequency', data['frequency'])
|
||||
self.try_publish(ts, f'temperature', data['temperature'])
|
||||
|
||||
if data['energy_total'] is not None:
|
||||
self.try_publish(ts, f'total', data['energy_total'])
|
||||
|
||||
def try_publish(self, ts, ctype, value):
|
||||
if not ctype in self.channels:
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue