I will share the SourceCode of the Impl here… Maybe you could have a look…
I have 3 Problems in Summary 
- Meter is not shown in UI (only in Log) if i activate it.
- 2023-07-25T02:20:19,083 [_cycle ] INFO [ebuglog.ControllerDebugLogImpl] [ctrlDebugLog0] _sum[State:Ok Production:-65536000 W Consumption:-65536000 W] meter0[[ActivePower]: -65536000 W[L1 Volt]: 230000 mV[L2 Volt]: 230000 mV[L3 Volt]: 230000 mV[L1 Amp]: 230000 mA[L2 Amp]: 150000 mA[L3 Amp]: 150000 mA[Frequency]:200 mHz]
As you can see i get Production AND Consumption even the MeterType is Production…
package io.openems.edge.meter.test;
import static io.openems.edge.bridge.modbus.api.ElementToChannelConverter.SCALE_FACTOR_1;
import static io.openems.edge.bridge.modbus.api.ElementToChannelConverter.SCALE_FACTOR_1_AND_INVERT_IF_TRUE;
import static io.openems.edge.bridge.modbus.api.ElementToChannelConverter.SCALE_FACTOR_2;
import io.openems.common.channel.AccessMode;
import io.openems.common.exceptions.OpenemsException;
import io.openems.edge.bridge.modbus.api.BridgeModbus;
import io.openems.edge.bridge.modbus.api.task.FC4ReadInputRegistersTask;
import io.openems.edge.bridge.modbus.api.ModbusComponent;
import io.openems.edge.bridge.modbus.api.element.*;
import io.openems.edge.common.component.OpenemsComponent;
import io.openems.edge.common.modbusslave.ModbusSlave;
import io.openems.edge.common.modbusslave.ModbusSlaveTable;
import io.openems.edge.common.taskmanager.Priority;
import io.openems.edge.meter.api.ElectricityMeter;
import io.openems.edge.meter.api.MeterType;
import io.openems.edge.meter.test.AbstractTestMeter;
import io.openems.edge.meter.test.TestMeter;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import org.osgi.service.metatype.annotations.Designate;
@Designate(ocd = Config.class, factory = true)
@Component(//
name = "Meter.Test.Test", //
immediate = true, //
configurationPolicy = ConfigurationPolicy.REQUIRE //
)
public class TestImpl extends AbstractTestMeter implements TestMeter,
ElectricityMeter, ModbusComponent, OpenemsComponent, ModbusSlave {
private Config config;
@Reference
private ConfigurationAdmin cm;
@Override
@Reference(policy = ReferencePolicy.STATIC, policyOption = ReferencePolicyOption.GREEDY, cardinality = ReferenceCardinality.MANDATORY)
protected void setModbus(BridgeModbus modbus) {
super.setModbus(modbus);
}
public TestImpl() throws OpenemsException {
super(//
OpenemsComponent.ChannelId.values(), //
ModbusComponent.ChannelId.values(), //
ElectricityMeter.ChannelId.values(), //
TestMeter.ChannelId.values() //
);
// Automatically calculate sum values from L1/L2/L3
ElectricityMeter.calculateSumCurrentFromPhases(this);
ElectricityMeter.calculateAverageVoltageFromPhases(this);
ElectricityMeter.calculatePhasesFromActivePower(this);
}
@Activate
private void activate(ComponentContext context, Config config) throws OpenemsException {
if (super.activate(context, config.id(), config.alias(), config.enabled(), config.modbusUnitId(), this.cm,
"Modbus", config.modbus_id())) {
return;
}
this.config = config;
this.identifyTestMeter();
}
@Override
@Deactivate
protected void deactivate() {
super.deactivate();
}
@Override
public MeterType getMeterType() {
return this.config.type();
}
@Override
protected void identifiedTestMeter() throws OpenemsException {
this.modbusProtocol.addTask(//
new FC4ReadInputRegistersTask(5018, Priority.HIGH, //
m(ElectricityMeter.ChannelId.VOLTAGE_L1, new UnsignedWordElement(5018), SCALE_FACTOR_2), //
m(ElectricityMeter.ChannelId.VOLTAGE_L2, new UnsignedWordElement(5019), SCALE_FACTOR_2), //
m(ElectricityMeter.ChannelId.VOLTAGE_L3, new UnsignedWordElement(5020), SCALE_FACTOR_2), //
m(ElectricityMeter.ChannelId.CURRENT_L1, new UnsignedWordElement(5021), SCALE_FACTOR_2), //
m(ElectricityMeter.ChannelId.CURRENT_L2, new UnsignedWordElement(5022), SCALE_FACTOR_2), //
m(ElectricityMeter.ChannelId.CURRENT_L3, new UnsignedWordElement(5023), SCALE_FACTOR_2), //
new DummyRegisterElement(5024, 5029), //
m(ElectricityMeter.ChannelId.ACTIVE_POWER, new UnsignedDoublewordElement(5030),SCALE_FACTOR_1_AND_INVERT_IF_TRUE(this.config.invert())), //
m(ElectricityMeter.ChannelId.REACTIVE_POWER, new SignedDoublewordElement(5032),SCALE_FACTOR_1_AND_INVERT_IF_TRUE(this.config.invert())), //
new DummyRegisterElement(5034), //
m(ElectricityMeter.ChannelId.FREQUENCY, new UnsignedWordElement(5035), SCALE_FACTOR_1)));
}
@Override
public String debugLog() {
return "[ActivePower]: " + this.getActivePower().asString()
+ "[L1 Volt]: " + this.getVoltageL1().asString()
+ "[L2 Volt]: " + this.getVoltageL2().asString()
+ "[L3 Volt]: " + this.getVoltageL3().asString()
+ "[L1 Amp]: " + this.getCurrentL1().asString()
+ "[L2 Amp]: " + this.getCurrentL2().asString()
+ "[L3 Amp]: " + this.getCurrentL3().asString()
+ "[Frequency]:" + this.getFrequency().asString();
}
@Override
public ModbusSlaveTable getModbusSlaveTable(AccessMode accessMode) {
return new ModbusSlaveTable(//
OpenemsComponent.getModbusSlaveNatureTable(accessMode), //
ElectricityMeter.getModbusSlaveNatureTable(accessMode) //
);
}}
Would be nice, if you could have a look and help me out 