Beginner Questions

Hello!

I’m new here and I don’t have much background in Java. Really good work! I would like to learn more about how does OpenEMS does the allocation of loads. I could see that when the battery is completely full it will automatically send the power to the grid. Where exactly can I see this part of the code? For example, if I want to add more storage sources, for instance, another type of battery, what should I do?

My idea is to create my own system with PV production (maybe also other sources) and different storage systems, that with the EMS the user can decide how to allocate the loads i.e: the user prefers to charge the battery until 80% only and the rest of production goes to the grid.

Hi Carlos,

Thanks for getting in touch. Power is not actually ‘sent to grid’. It rather follows the simple formula that in each point in time Consumption = Grid + Production + Storage (where Grid and Storage may also be negative values, meaning ‘sell-to-grid’ or ‘charge battery’ respectively). I posted some slides of my lecture a while ago here (sorry - German): FH Kiel: Pro 9-12 + OpenEMS Potential.

With this formula in mind we can control:

  • charge/discharge the battery
  • curtail photovoltaics production
  • start additional generators
  • start/stop/reduce consumption

and as a result the grid exchange power will change. And this is what OpenEMS Controllers do.In our Gidpod Live-Demo you can play with this yourself, using OpenEMS as a simulator:

For your use-case you could write a Controller that evaluates with how much power you would want to charge/discharge any of your storage systems (e.g. stop at 80 %). The rest is solved by physicis :wink:

Regards,
Stefan

Hello Stefan,

Thanks a lot for the prompt reply. I read the presentation and it helped me to understand much more. Now I have some other questions:

  • So I’m still quite new with Java but I wanted to know exactly where is it stated this simple formula of the consumption is equal to the sum of production, grid, and storage.
  • I can change the values of Grid, Storage, and PV production for fixed values in the simulator, so I can put negative values if I want them to change direction/charge. But of course, all these values including the PV production vary throughout the day. Is it possible to input a series of values? Maybe real-time data?
  • About the Energymonitor feature, I’m not able to make it show trends, do I have to do something specific for it to work?

Thanks again, it is really interesting for me, I’ll keep playing with the simulator and reading the codes so that I can write a controller with the function you suggested.

Best regards,
Carlos

Hi Carlos,

The calculation for the _sum/ConsumptionActivePower-Channel is here:

Yes of course. The example simulation is just very simplified to not get overwhelmed with everything at once. The simulator uses Datasources to provide the data. In the Gitpod there are three Simulator.Datasource.Single.Direct configured (- by the way: the configuration file for the docker container is here)

You could easily enter multiple values in that configuration (e.g. via Apache Felix or OpenEMS UI) or e.g. use a simulator that takes a CSV-file (see openems/io.openems.edge.simulator/src/io/openems/edge/simulator/datasource at develop · OpenEMS/openems · GitHub).

What do you mean by “show trends” exactly?

Regards,
Stefan

Hi Stefan

Thanks a lot for replying. As you see I took some time to understand more about the code. I’ve been looking into more details and I had some questions about it, hope you or anyone can help me with it.

*I’m thinking of doing optimization of the power allocation, for example, I would like the EMS to allocate the energy efficiently to my system, fulfill my consumption first, then charge the storage system and then sell it to the grid if possible. Of course, here there would be some factors like the market selling price: if the selling price is good, and it is better than storing it, then the EMS should automatically change the first approach to this one. And maybe other factors apart from the market price can be added here. Is it feasible what I’m thinking? Or maybe openEMS already do this?

*Also I have a question about the CSV files, so if I want to use new data sets for my simulation I should just add a csv file in the csv/predefined folder? Going few more steps ahead, is it possible to save data acquired from a meter (say for example in the PV modules), save it automatically as a csv file and make the code read the most recent one?

Regarding my previous last question, I was referring to this:


It shows nothing when I tried, I guess I need to activate some other functions first! I will check it out.

Best regards,
Carlos

Hi Carlos,

Optimization of power allocation:
As we discussed in person, good examples for similar Controllers are:

and

CSV file
The way we usually do it, is:

  • Record data via Timedata.InfluxDB into an InfluxDB database
  • Analyze data using Grafana (https://grafana.com/)
  • Export data from Grafana to CSV
  • Import to OpenEMS

This gives good control about what data we want to use for simulation and in which resolution (e.g. one value per second or one value per 15 minutes).

Otherwise, see also this post for details on how to implement your own Datasource: EMS-Simulation durch Daten aus DB statt CSV-Dateien - #2 by stefan.feilmeier

UI historic view

The Datasource for simulated meters is a different concept than the Timedata provider. I understand, that those can easily get mixed up.

  • Datasource provides a new value on each Cycle for live simulation
  • Timedata provides access to historic data that it was previously recording

Regards,
Stefan

Hi Stefan,

Thanks as always for the reply. I’m looking at the controllers and also as suggested by you the balancing controller.

  • First I have a question about the balancing controller. We have below the definition of the “calculateRequiredPower” method, it uses the “meter.getActivePower().getOrError()” which I understand represents the current buying or selling power from the grid, then it sums “ess.getActivePower().getOrError()” that represents the current power charging or discharging the battery, and lastly it subtracts “config.targetGridSetpoint()” which if I believe it is predetermined as 0. What does this last term mean? and why it is subtracted?

      private int calculateRequiredPower(ManagedSymmetricEss ess, SymmetricMeter meter) throws InvalidValueException {
      	return meter.getActivePower().getOrError() /* current buy-from/sell-to grid */
      			+ ess.getActivePower().getOrError() /* current charge/discharge Ess */
      			- config.targetGridSetpoint(); /* the configured target setpoint */
    
  • Now, I’m doing a simple example of optimization, so I consider a system with PV production, a battery and grid connected. So based in the grid optimized charge controller I thought about the some possible scenarios to model, all of them with if/else commands. For example, one case would be with my system having insufficient PV energy production, and the logic would be: if I have charge in my battery, use it, otherwise get from grid. I think it would look like this (not sure yet how to write it):

       if (meter.getActivePower().getOrError() + ess.getActivePower().getOrError() > 0) {
              if (battery?.getCapacity() > 0){
                  return "use battery for consumption";
              }else{
                  "get from grid"
              }
          } else if ...
    

Does it makes sense? Is there a way to have the “use battery” or “get from grid”?

Best regards,
Carlos

Hi Carlos,

First question you got completely correct. The targetGridSetpoint configuration settings allows to balance to a different value than 0 on the grid - e.g. if you set it to -1000 it would continuously try to feed 1 kW to grid, i.e. charging the battery when there is more feed-to-grid power and discharging the battery when in the evening there is less feed-to-grid power by PV.

Regarding the calculation, see this example:

  • Initial setting:
    • currently measured grid power = 5000 (i.e. 5 kW buy from grid)
    • current battery-inverter power = 0 (i.e. no charging or dischargin)
    • target set-point: -1000 (i.e. continously sell to grid 1 kW)
    • set-point for battery: 5000 - 0 + 1000 = 6000 (discharge battery with 6 kW to compensate buy-from-grid power plus sell-to-grid with 1 kW)
  • Next Cycle (ideally):
    • currently measured grid power = -1000 (i.e. as result of discharging the battery)
    • current battery-inverter power = 6000 (i.e. discharge with 6 kW)
    • target set-point: -1000 (i.e. continously sell to grid 1 kW)
    • set-point for battery: -1000 - 6000 + 1000 = 6000 (stay same because grid power is already exactly matching)

I say “ideally”, because in reality battery-inverters have a power ramp, meters take some time to measure, communication takes a while and consumption may change inbetween. There is a PID filter in place to compensate this.

Regarding your second point: you do not necessarily have to check here if the battery still has remaining capacity. This is internally handled here, wenn the battery-inverter set-point is checked against its current min-/max-values:

If you wanted to e.g. stop discharging early - lets say at 30 % state-of-charge, your approach would be correct. Just use battery.getSoc() instead; it gives state-of-charge in percentage. Capacity is the nominal capacity of the (full) battery.

In the end your algorithm should come up with set-points for devices you can actually control, i.e. a energy storage system (battery+battery-inverter), a CHP, a Diesel generator,… as you are not able to directly control the “get from grid” power.

Regards,
Stefan

Hi Stefan,

Thank you, the example was really helpful. Now I have another question about it, so as for the initial setting, the currently measured grid power is 5kW because we want to consume it, or charge the battery? how does the consumption or charging is differentiated? Why is it that in the set point for battery we “discharge the battery with 6kW”? the battery is not in 0? or is it that we buy from the grid in total 6kW and charge the battery? (going again through the first question, does the power bought from the grid always go through the battery before consumption?)

What I understand is that we need 5kW and always sell 1kW, then we need 6kW to fulfill the next cycle requirement. As for the next ideal cycle, the measured grid power is -1000 because we are fulfilling the target setpoint (selling from our 6kW) and the setpoint for battery stays the same because in this example we do not require more power either for consumption or battery. If we, e.g. need 4kW more, then the setpoint for the battery would be different right? (9kW in total)

And regarding this:

Perfect, then I will rethink the algorithm with controllable devices.

Best regards,
Carlos

We measure the power at Grid Buy/Sell (1), Production (2) and Battery Charge/Discharge (3). From those values Consumption (4) can be calculated. The measured power the the grid can only be influenced by production, battery charge/discharge or consumption. As we know about production and battery, because we measure them, it can only come from consumption.

In first cycle, the measured battery charge/discharge is 0 kW. We give a set-point of 6 kW, so that ideally in the second cycle we measure a power of 6 kW for charge/discharge. No, power is of course not always going through the battery.

In the example 6 kW would actually be required to fulfil the requirement of the first cycle, but in control systems we always lag (at least) one cycle behind.

For your example: yes, if either the consumption would increase by 4 kW (e.g. some device turned on) or the production would decrease by 4 kW (e.g. a cloud above the pv system), this would get directly reflected on the measured grid power. The grid value would then be 3000 instead of -1000 and as such the new set-point for discharging the battery would be 9000.