From 1ad1a8adc90843b1254c42ce0725f3281ded5fc4 Mon Sep 17 00:00:00 2001 From: Cyrill Wyss Date: Wed, 2 Oct 2024 16:07:47 +0200 Subject: [PATCH 1/5] Add additional obis codes --- sma/src/emeter.py | 58 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/sma/src/emeter.py b/sma/src/emeter.py index fc83759..76a9a4d 100644 --- a/sma/src/emeter.py +++ b/sma/src/emeter.py @@ -1,10 +1,62 @@ class emeterPacket: SMA_POSITIVE_ACTIVE_POWER = 0x00010400 - SMA_POSITIVE_REACTIVE_POWER = 0x00030400 + SMA_POSITIVE_ACTIVE_POWER_L1 = 0x00150400 + SMA_POSITIVE_ACTIVE_POWER_L2 = 0x00290400 + SMA_POSITIVE_ACTIVE_POWER_L3 = 0x003D0400 + SMA_POSITIVE_ACITVE_ENERGY = 0x00010800 + SMA_POSITIVE_ACITVE_ENERGY_L1 = 0x00150800 + SMA_POSITIVE_ACITVE_ENERGY_L2 = 0x00290800 + SMA_POSITIVE_ACITVE_ENERGY_L3 = 0x003D0800 SMA_NEGATIVE_ACTIVE_POWER = 0x00020400 - SMA_NEGATIVE_REACTIVE_POWER = 0x00040400 - SMA_POSITIVE_ENERGY = 0x00010800 + SMA_NEGATIVE_ACTIVE_POWER_L1 = 0x00160400 + SMA_NEGATIVE_ACTIVE_POWER_L2 = 0x002A0400 + SMA_NEGATIVE_ACTIVE_POWER_L3 = 0x003E0400 SMA_NEGATIVE_ENERGY = 0x00020800 + SMA_NEGATIVE_ENERGY_L1 = 0x00160800 + SMA_NEGATIVE_ENERGY_L2 = 0x002A0800 + SMA_NEGATIVE_ENERGY_L3 = 0x003E0800 + SMA_POSITIVE_REACTIVE_POWER = 0x00030400 + SMA_POSITIVE_REACTIVE_POWER_L1 = 0x00170400 + SMA_POSITIVE_REACTIVE_POWER_L2 = 0x002B0400 + SMA_POSITIVE_REACTIVE_POWER_L3 = 0x003F0400 + SMA_POSITIVE_REACTIVE_ENERGY = 0x00030800 + SMA_POSITIVE_REACTIVE_ENERGY_L1 = 0x00170800 + SMA_POSITIVE_REACTIVE_ENERGY_L2 = 0x002B0800 + SMA_POSITIVE_REACTIVE_ENERGY_L3 = 0x003F0800 + SMA_NEGATIVE_REACTIVE_POWER = 0x00040400 + SMA_NEGATIVE_REACTIVE_POWER_L1 = 0x00180400 + SMA_NEGATIVE_REACTIVE_POWER_L2 = 0x002C0400 + SMA_NEGATIVE_REACTIVE_POWER_L3 = 0x00400400 + SMA_NEGATIVE_REACTIVE_ENERGY = 0x00040800 + SMA_NEGATIVE_REACTIVE_ENERGY_L1 = 0x00180800 + SMA_NEGATIVE_REACTIVE_ENERGY_L2 = 0x002C0800 + SMA_NEGATIVE_REACTIVE_ENERGY_L3 = 0x00400800 + SMA_POSITIVE_APPARENT_POWER = 0x00090400 + SMA_POSITIVE_APPARENT_POWER_L1 = 0x001D0400 + SMA_POSITIVE_APPARENT_POWER_L2 = 0x00310400 + SMA_POSITIVE_APPARENT_POWER_L3 = 0x00450400 + SMA_POSITIVE_APPARENT_ENERGY = 0x00090800 + SMA_POSITIVE_APPARENT_ENERGY_L1 = 0x001D0800 + SMA_POSITIVE_APPARENT_ENERGY_L2 = 0x00310800 + SMA_POSITIVE_APPARENT_ENERGY_L3 = 0x00450800 + SMA_NEGATIVE_APPARENT_POWER = 0x000A0400 + SMA_NEGATIVE_APPARENT_POWER_L1 = 0x001E0400 + SMA_NEGATIVE_APPARENT_POWER_L2 = 0x00320400 + SMA_NEGATIVE_APPARENT_POWER_L3 = 0x00460400 + SMA_NEGATIVE_APPARENT_ENERGY = 0x000A0800 + SMA_NEGATIVE_APPARENT_ENERGY_L1 = 0x001E0800 + SMA_NEGATIVE_APPARENT_ENERGY_L2 = 0x00320800 + SMA_NEGATIVE_APPARENT_ENERGY_L3 = 0x00460800 + SMA_POWER_FACTOR = 0x000D0400 + SMA_POWER_FACTOR_L1 = 0x00210400 + SMA_POWER_FACTOR_L2 = 0x00350400 + SMA_POWER_FACTOR_L3 = 0x00490400 + SMA_CURRENT_L1 = 0x001F0400 + SMA_CURRENT_L2 = 0x00330400 + SMA_CURRENT_L3 = 0x00470400 + SMA_VOLTAGE_L1 = 0x00020400 + SMA_VOLTAGE_L2 = 0x00340400 + SMA_VOLTAGE_L3 = 0x00480400 SMA_VERSION = 0x90000000 INITIAL_PAYLOAD_LENGTH = 12 From 59809f02163809d5f7153fb9e667c800276cb9f1 Mon Sep 17 00:00:00 2001 From: Cyrill Wyss Date: Wed, 2 Oct 2024 16:32:15 +0200 Subject: [PATCH 2/5] add a more complete protocol to the emeter packet --- sma/src/mqtt.py | 85 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/sma/src/mqtt.py b/sma/src/mqtt.py index b02c47c..e12f020 100644 --- a/sma/src/mqtt.py +++ b/sma/src/mqtt.py @@ -52,14 +52,81 @@ def on_message(client, userdata, msg): packet = emeterPacket(int(serial_number)) packet.begin(int(time.time() * 1000)) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER, round(data['powerIn'] * 10)) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER, round(data['powerOut'] *10)) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER, 0) - - packet.addCounterValue(emeterPacket.SMA_POSITIVE_ENERGY, round(data['energyIn'] * 1000 * 3600)) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ENERGY, round(data['energyOut'] * 1000 * 3600)) - + if settings.get("full_data_packet", False) is False: + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER, round(data['powerIn'] * 10)) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER, round(data['powerOut'] *10)) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER, 0) + + packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY, round(data['energyIn'] * 1000 * 3600)) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY, round(data['energyOut'] * 1000 * 3600)) + else: + # Totals + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER, round(data['powerIn'] * 10)) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY, round(data['energyIn'] * 1000 * 3600)) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER, round(data['powerOut'] *10)) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY, round(data['energyOut'] * 1000 * 3600)) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY, 0) + packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR, 900) # assume almost perfect power factor of 0.9 for default value + + #L1 + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L1, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L1, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L1, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L1, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L1, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L1, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L1, 900) # assume almost perfect power factor of 0.9 for default value + + #L2 + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L2, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L2, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L2, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L2, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L2, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L2, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L2, 900) # assume almost perfect power factor of 0.9 for default value + + #L3 + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L3, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L3, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L3, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L3, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L3, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L3, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L3, 900) # assume almost perfect power factor of 0.9 for default value + packet.end() packet_data = packet.getData()[:packet.getLength()] @@ -96,4 +163,4 @@ def set_mqtt_settings(): settings["mqtt"]["broker"] = broker_host settings["mqtt"]["port"] = broker_port settings["mqtt"]["username"] = broker_user - settings["mqtt"]["password"] = broker_pass \ No newline at end of file + settings["mqtt"]["password"] = broker_pass From e7463cc3fd6719e19beac8adf0cc837dc95ddcc1 Mon Sep 17 00:00:00 2001 From: Cyrill Wyss Date: Wed, 2 Oct 2024 16:34:08 +0200 Subject: [PATCH 3/5] Add setting for more complete data packets --- sma/config.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sma/config.yaml b/sma/config.yaml index 5d9cc92..1b043df 100644 --- a/sma/config.yaml +++ b/sma/config.yaml @@ -20,6 +20,7 @@ options: username: "auto_user" password: "auto_password" enable_homewizard: false + full_data_packet: false schema: enable_mqtt: bool? mqtt: @@ -28,6 +29,7 @@ schema: username: str? password: str? enable_homewizard: bool + full_data_packet: bool? homewizard_manual_addresses: - str? homewizard_destination_addresses: From 31e59411fd3d7ce9b2bd35386343619a0648d74c Mon Sep 17 00:00:00 2001 From: Roeland Date: Wed, 2 Oct 2024 23:30:29 +0200 Subject: [PATCH 4/5] fixing naming extending package --- sma/config.yaml | 4 +- sma/src/emeter.py | 16 ++--- sma/src/homewizard.py | 16 +++-- sma/src/mqtt.py | 145 ++++++++++++++++++++---------------------- 4 files changed, 87 insertions(+), 94 deletions(-) diff --git a/sma/config.yaml b/sma/config.yaml index 1b043df..8369765 100644 --- a/sma/config.yaml +++ b/sma/config.yaml @@ -1,6 +1,6 @@ name: "SMA Energy Meter emulator" description: "Simulate one or more SMA energy meters based on mqtt messages." -version: "0.1.0" +version: "0.1.1" slug: sma url: "https://github.com/Roeland54/SMA-Energy-Meter-emulator" arch: @@ -20,7 +20,6 @@ options: username: "auto_user" password: "auto_password" enable_homewizard: false - full_data_packet: false schema: enable_mqtt: bool? mqtt: @@ -29,7 +28,6 @@ schema: username: str? password: str? enable_homewizard: bool - full_data_packet: bool? homewizard_manual_addresses: - str? homewizard_destination_addresses: diff --git a/sma/src/emeter.py b/sma/src/emeter.py index 76a9a4d..fb4702b 100644 --- a/sma/src/emeter.py +++ b/sma/src/emeter.py @@ -3,18 +3,18 @@ class emeterPacket: SMA_POSITIVE_ACTIVE_POWER_L1 = 0x00150400 SMA_POSITIVE_ACTIVE_POWER_L2 = 0x00290400 SMA_POSITIVE_ACTIVE_POWER_L3 = 0x003D0400 - SMA_POSITIVE_ACITVE_ENERGY = 0x00010800 - SMA_POSITIVE_ACITVE_ENERGY_L1 = 0x00150800 - SMA_POSITIVE_ACITVE_ENERGY_L2 = 0x00290800 - SMA_POSITIVE_ACITVE_ENERGY_L3 = 0x003D0800 + SMA_POSITIVE_ACTIVE_ENERGY = 0x00010800 + SMA_POSITIVE_ACTIVE_ENERGY_L1 = 0x00150800 + SMA_POSITIVE_ACTIVE_ENERGY_L2 = 0x00290800 + SMA_POSITIVE_ACTIVE_ENERGY_L3 = 0x003D0800 SMA_NEGATIVE_ACTIVE_POWER = 0x00020400 SMA_NEGATIVE_ACTIVE_POWER_L1 = 0x00160400 SMA_NEGATIVE_ACTIVE_POWER_L2 = 0x002A0400 SMA_NEGATIVE_ACTIVE_POWER_L3 = 0x003E0400 - SMA_NEGATIVE_ENERGY = 0x00020800 - SMA_NEGATIVE_ENERGY_L1 = 0x00160800 - SMA_NEGATIVE_ENERGY_L2 = 0x002A0800 - SMA_NEGATIVE_ENERGY_L3 = 0x003E0800 + SMA_NEGATIVE_ACTIVE_ENERGY = 0x00020800 + SMA_NEGATIVE_ACTIVE_ENERGY_L1 = 0x00160800 + SMA_NEGATIVE_ACTIVE_ENERGY_L2 = 0x002A0800 + SMA_NEGATIVE_ACTIVE_ENERGY_L3 = 0x003E0800 SMA_POSITIVE_REACTIVE_POWER = 0x00030400 SMA_POSITIVE_REACTIVE_POWER_L1 = 0x00170400 SMA_POSITIVE_REACTIVE_POWER_L2 = 0x002B0400 diff --git a/sma/src/homewizard.py b/sma/src/homewizard.py index 48f4ad4..0b8bd29 100644 --- a/sma/src/homewizard.py +++ b/sma/src/homewizard.py @@ -1,11 +1,13 @@ -from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange -from config import settings, workingdata +import hashlib +import json import logging +import time + import requests -import hashlib +from config import settings, workingdata from emeter import emeterPacket -import time -import json +from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf + def setup_homewizard(): if settings.get("enable_homewizard", False) is False: @@ -82,11 +84,11 @@ def update_homewizard(): # Sum the total energy imports (t1 and t2) total_power_import_kwh = data['total_power_import_t1_kwh'] + data['total_power_import_t2_kwh'] - packet.addCounterValue(emeterPacket.SMA_POSITIVE_ENERGY, round(total_power_import_kwh * 1000 * 3600)) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY, round(total_power_import_kwh * 1000 * 3600)) # Sum the total energy exports (t1 and t2) total_power_export_kwh = data['total_power_export_t1_kwh'] + data['total_power_export_t2_kwh'] - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ENERGY, round(total_power_export_kwh * 1000 * 3600)) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY, round(total_power_export_kwh * 1000 * 3600)) packet.end() diff --git a/sma/src/mqtt.py b/sma/src/mqtt.py index e12f020..cedea97 100644 --- a/sma/src/mqtt.py +++ b/sma/src/mqtt.py @@ -1,12 +1,14 @@ import json import logging -import time import os +import time + import paho.mqtt.client as mqtt import util from config import settings, workingdata from emeter import emeterPacket + def setup_mqtt(): if settings.get("enable_mqtt", False) is False: return None @@ -52,81 +54,72 @@ def on_message(client, userdata, msg): packet = emeterPacket(int(serial_number)) packet.begin(int(time.time() * 1000)) - if settings.get("full_data_packet", False) is False: - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER, round(data['powerIn'] * 10)) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER, round(data['powerOut'] *10)) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER, 0) - - packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY, round(data['energyIn'] * 1000 * 3600)) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY, round(data['energyOut'] * 1000 * 3600)) - else: - # Totals - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER, round(data['powerIn'] * 10)) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY, round(data['energyIn'] * 1000 * 3600)) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER, round(data['powerOut'] *10)) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY, round(data['energyOut'] * 1000 * 3600)) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY, 0) - packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR, 900) # assume almost perfect power factor of 0.9 for default value - - #L1 - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L1, 900) # assume almost perfect power factor of 0.9 for default value - - #L2 - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L2, 900) # assume almost perfect power factor of 0.9 for default value - - #L3 - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L3, 900) # assume almost perfect power factor of 0.9 for default value - + # Totals + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER, round(data['powerIn'] * 10)) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY, round(data['energyIn'] * 1000 * 3600)) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER, round(data['powerOut'] *10)) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY, round(data['energyOut'] * 1000 * 3600)) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY, 0) + packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR, 900) # assume almost perfect power factor of 0.9 for default value + + #L1 + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L1, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L1, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L1, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L1, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L1, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L1, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L1, 0) + packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L1, 900) # assume almost perfect power factor of 0.9 for default value + + #L2 + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L2, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L2, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L2, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L2, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L2, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L2, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L2, 0) + packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L2, 900) # assume almost perfect power factor of 0.9 for default value + + #L3 + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L3, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L3, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L3, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L3, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L3, 0) + packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L3, 0) + packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L3, 0) + packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L3, 900) # assume almost perfect power factor of 0.9 for default value + packet.end() packet_data = packet.getData()[:packet.getLength()] From 356f66aec6852bcb8fd10e2e9250cde8746afa50 Mon Sep 17 00:00:00 2001 From: Roeland Date: Thu, 3 Oct 2024 14:49:17 +0200 Subject: [PATCH 5/5] Always add dummy values for all possible values to udp packet --- sma/CHANGELOG.md | 4 +++ sma/config.yaml | 2 +- sma/src/emeter.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++ sma/src/mqtt.py | 62 +------------------------------------------ 4 files changed, 73 insertions(+), 62 deletions(-) diff --git a/sma/CHANGELOG.md b/sma/CHANGELOG.md index 70fa2a6..90bbc55 100644 --- a/sma/CHANGELOG.md +++ b/sma/CHANGELOG.md @@ -1,5 +1,9 @@ +## 0.1.2 + +- Extend package to support tripower inverters + ## 0.1.0 - Add homewizard support diff --git a/sma/config.yaml b/sma/config.yaml index 8369765..d9bc3c6 100644 --- a/sma/config.yaml +++ b/sma/config.yaml @@ -1,6 +1,6 @@ name: "SMA Energy Meter emulator" description: "Simulate one or more SMA energy meters based on mqtt messages." -version: "0.1.1" +version: "0.1.2" slug: sma url: "https://github.com/Roeland54/SMA-Energy-Meter-emulator" arch: diff --git a/sma/src/emeter.py b/sma/src/emeter.py index fb4702b..1bf4dfd 100644 --- a/sma/src/emeter.py +++ b/sma/src/emeter.py @@ -144,3 +144,70 @@ def initEmeterPacket(self, serNo): pSerNo = self.offsetOf(self.meterPacket, DSRC, self._headerLength) self.storeU32BE(pSerNo, serNo) + + # Add dummy values for measurements to make sure the package always contains these. Solves tripower inverters not recognizing the data as valid. + # Totals + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY, 0) + self.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR, 0) + + #L1 + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L1, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L1, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L1, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L1, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L1, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L1, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_CURRENT_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L1, 0) + self.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L1, 0) + + #L2 + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L2, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L2, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L2, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L2, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L2, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L2, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_CURRENT_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L2, 0) + self.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L2, 0) + + #L3 + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L3, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L3, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L3, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L3, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L3, 0) + self.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L3, 0) + self.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_CURRENT_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L3, 0) + self.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L3, 0) diff --git a/sma/src/mqtt.py b/sma/src/mqtt.py index cedea97..439e156 100644 --- a/sma/src/mqtt.py +++ b/sma/src/mqtt.py @@ -59,67 +59,7 @@ def on_message(client, userdata, msg): packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY, round(data['energyIn'] * 1000 * 3600)) packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER, round(data['powerOut'] *10)) packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY, round(data['energyOut'] * 1000 * 3600)) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY, 0) - packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR, 900) # assume almost perfect power factor of 0.9 for default value - - #L1 - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L1, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L1, 0) - packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L1, 900) # assume almost perfect power factor of 0.9 for default value - - #L2 - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L2, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L2, 0) - packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L2, 900) # assume almost perfect power factor of 0.9 for default value - - #L3 - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_ACTIVE_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_ACTIVE_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_ACTIVE_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_ACTIVE_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_REACTIVE_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_REACTIVE_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_REACTIVE_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_REACTIVE_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_POSITIVE_APPARENT_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_POSITIVE_APPARENT_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_NEGATIVE_APPARENT_POWER_L3, 0) - packet.addCounterValue(emeterPacket.SMA_NEGATIVE_APPARENT_ENERGY_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_CURRENT_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_VOLTAGE_L3, 0) - packet.addMeasurementValue(emeterPacket.SMA_POWER_FACTOR_L3, 900) # assume almost perfect power factor of 0.9 for default value - + packet.end() packet_data = packet.getData()[:packet.getLength()]