Seeking Assistance with Time-Based Data Simulation in OpenEMS

Hello OpenEMS Community,

I am currently working on a project where I aim to simulate PV solar data in a more realistic manner, specifically by showing data during daylight hours and none at night. To achieve this, I’ve made some modifications to the SimulatorDatasourceCsvPredefinedImpl.java file in the OpenEMS Edge Simulator. My goal is to have the simulation reflect actual solar production patterns, with output during the day and no output at night.

Here’s an overview of the changes I implemented:

  1. Time-Based Data Handling: I added a time check within the getData() method to differentiate between day and night hours. The system is set to read data from a CSV file during the day (6 AM to 11:55 PM Tunisian time) and to return zero data during the night.
  2. Scheduled Data Updates: I used a ScheduledExecutorService to update the data every minute.

However, I’ve encountered a challenge: the time-based data change seems to be effective only when I deactivate and then reactivate the application. This behavior limits the dynamic nature of the simulation, as it doesn’t automatically update the data based on the current time.

Here’s a snippet of the key part of my code for reference:

// … [initial part of the class]

private void updateData() {
// Perform the time check and update currentData
try {
this.currentData = getData();
} catch (Exception e) {
// Handle exceptions
}
}

// …

protected DataContainer getData() throws NumberFormatException, IOException {
// Always check the current time
ZoneId tunisZoneId = ZoneId.of(“Africa/Tunis”);
LocalTime now = LocalTime.now(tunisZoneId);

// Define day and night hours
LocalTime dayStart = LocalTime.of(6, 0); // 6 AM
LocalTime dayEnd = LocalTime.of(19, 00); // 7:00 PM

// Check if the selected source is H0_HOUSEHOLD_SUMMER_WEEKDAY_PV_PRODUCTION_TUNISIAN_TIME
if (this.config.source() == Source.H0_HOUSEHOLD_SUMMER_WEEKDAY_PV_PRODUCTION_TUNISIAN_TIME) {
    if (now.isAfter(dayStart) && now.isBefore(dayEnd)) {
        // It's day, read data from CSV
        return CsvUtils.readCsvFileFromResource(SimulatorDatasourceCsvPredefinedImpl.class,
                this.config.source().filename, this.config.format(), this.config.factor());
    } else {
        // It's night, return zero data
        return createZeroDataContainer();
    }
} else {
    // For other sources, just read data from CSV
    return CsvUtils.readCsvFileFromResource(SimulatorDatasourceCsvPredefinedImpl.class,
            this.config.source().filename, this.config.format(), this.config.factor());
}

}

// …

I would greatly appreciate any insights or suggestions on how to resolve this issue. Specifically, I’m looking for a way to ensure that the simulation data updates according to the actual time of day, without needing to manually deactivate and reactivate the app.

Thank you in advance for your help!

Hi @ChahtourAla,

I did not fully understand your requirement. You are planning to run a real-time-simulation with feasible PV data?

The h0-summer-weekday-pv-production.csv (https://github.com/OpenEMS/openems/blob/develop/io.openems.edge.simulator/src/io/openems/edge/simulator/datasource/csv/predefined/h0-summer-weekday-pv-production.csv) already holds 24 hours values with one value per minute.

What I would do is: load the CSV data into a TreeMap with LocalTime (every minute) as Key and the data of the CSV file as value. Then use this data to return the proper data from the Datasource for the actual LocalTime.now().

Regards,
Stefan