Use OpenEMS to manage a simulated microgrid

Thank you again for your quick answer. I had tried implementing an ESS device (again, thanks to @Josef for his help) and put some logs in the applyPower method. It was always being called with 0 as argument, and I couldn’t figure out why this was happening. Then, thanks to your reply in this thread I’ve understood that I needed to set max apparent power, allowed charge power and allowed discharge power in the Ess impl class, so I’ve set them in the activate method. Now the battery gets discharged, but never charged, and the value passed to applyPower is different from the calculated power in ControllerEssBalancing. Could you please help me making it work? I just want to know how to reproduce the same scenario of the getting started tutorial, but using my Ess instead of SimulatorEssSymmetricReacting. Thank you again for your precious help.

Here are same samples of my Ess class

In the activate method I put this code:

this._setGridMode(GridMode.ON_GRID);
		this._setCapacity(config.capacity());
		this._setMaxApparentPower(config.maxApparentPower());
		this._setAllowedChargePower(config.capacity() * -1);
		this._setAllowedDischargePower(config.capacity());

This is my applyPower method:

@Override
	public void applyPower(int activePower, int reactivePower) throws OpenemsNamedException {
		log.info("applyPower called with active power {}", activePower);
		if (this.config.readOnlyMode()) {
			return;
		}

		EnumWriteChannel setControlMode = this.channel(Ess.ChannelId.SET_CONTROL_MODE);
		IntegerWriteChannel setActivePowerChannel = this.channel(Ess.ChannelId.SET_ACTIVE_POWER);
		IntegerWriteChannel setReactivePowerChannel = this.channel(Ess.ChannelId.SET_REACTIVE_POWER);

		setControlMode.setNextWriteValue(SetControlMode.START);
		setActivePowerChannel.setNextWriteValue(activePower);
		setReactivePowerChannel.setNextWriteValue(reactivePower);
	}

And, finally, this is the defineModbusProtocol method (this is not a real device, hence the very simple register table) :

@Override
	protected ModbusProtocol defineModbusProtocol() {
		return new ModbusProtocol(this, //				

				new FC3ReadRegistersTask(4, Priority.HIGH, 
						m(SymmetricEss.ChannelId.SOC, new UnsignedWordElement(4))),
				new FC3ReadRegistersTask(5, Priority.HIGH, 
						m(SymmetricEss.ChannelId.CAPACITY, new UnsignedWordElement(5))),
				new FC3ReadRegistersTask(7, Priority.HIGH, 
						m(SymmetricEss.ChannelId.ACTIVE_POWER, new SignedWordElement(7))),
			

				new FC16WriteRegistersTask(6,
						m(Ess.ChannelId.SET_ACTIVE_POWER, new SignedWordElement(6))));
	}

P.S.: I’ve noticed that, when using the SimulatorEssSymmetricReacting, the active power passed to the applyPower method is slightly different from the calculated power obtained in ControllerEssBalancing passed to the setActivePowerEqualsWithPid method. I can’t understand why is it so, could you please explain that to me? Do I have to expect the same when using my custom Ess device?

I’m sorry if my questions may sound silly, but I’m new to this domain and, even having read the docs, some things are still not very clear to me.