Search in sources :

Example 1 with SymmetricMeterNature

use of io.openems.api.device.nature.meter.SymmetricMeterNature in project openems by OpenEMS.

the class Meter method toString.

@Override
public String toString() {
    StringBuilder b = new StringBuilder();
    b.append(meter.id() + " [");
    if (meter instanceof SymmetricMeterNature) {
        SymmetricMeterNature m = (SymmetricMeterNature) meter;
        b.append("L:" + m.activePower().format() + ";" + m.reactivePower().format());
    }
    if (meter instanceof SymmetricMeterNature && meter instanceof AsymmetricMeterNature) {
        b.append("|");
    }
    if (meter instanceof AsymmetricMeterNature) {
        AsymmetricMeterNature m = (AsymmetricMeterNature) meter;
        b.append(// 
        "L1:" + m.activePowerL1().format() + ";" + m.reactivePowerL1().format() + "|" + "L2:" + m.activePowerL2().format() + ";" + m.reactivePowerL2().format() + // 
        "|" + "L3:" + m.activePowerL3().format() + ";" + m.reactivePowerL3().format());
    }
    b.append("]");
    return b.toString();
}
Also used : SymmetricMeterNature(io.openems.api.device.nature.meter.SymmetricMeterNature) AsymmetricMeterNature(io.openems.api.device.nature.meter.AsymmetricMeterNature)

Example 2 with SymmetricMeterNature

use of io.openems.api.device.nature.meter.SymmetricMeterNature in project openems by OpenEMS.

the class MeterClusterNature method loadMeter.

private void loadMeter() {
    JsonArray meterIds;
    try {
        meterIds = meter.value();
        // remove old ess
        synchronized (symmetricMeterList) {
            synchronized (asymmetricMeterList) {
                symmetricMeterList.clear();
                for (AsymmetricMeterNature meter : asymmetricMeterList) {
                    this.thingState.removeChangeListener(meter.getStateChannel());
                }
                asymmetricMeterList.clear();
                if (meterIds != null) {
                    for (JsonElement id : meterIds) {
                        Optional<Thing> nature = repo.getThingById(id.getAsString());
                        if (nature.isPresent()) {
                            if (nature.get() instanceof AsymmetricMeterNature) {
                                AsymmetricMeterNature meter = (AsymmetricMeterNature) nature.get();
                                asymmetricMeterList.add(meter);
                            } else if (nature.get() instanceof SymmetricMeterNature) {
                                SymmetricMeterNature meter = (SymmetricMeterNature) nature.get();
                                symmetricMeterList.add(meter);
                            } else {
                                log.error("ThingID: " + id.getAsString() + " is no Meter!");
                            }
                        } else {
                            log.warn("meter: " + id.getAsString() + " not found!");
                        }
                    }
                }
            }
        }
    } catch (InvalidValueException e) {
        log.error("meter value is invalid!", e);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) InvalidValueException(io.openems.api.exception.InvalidValueException) SymmetricMeterNature(io.openems.api.device.nature.meter.SymmetricMeterNature) AsymmetricMeterNature(io.openems.api.device.nature.meter.AsymmetricMeterNature) JsonElement(com.google.gson.JsonElement) Thing(io.openems.api.thing.Thing)

Example 3 with SymmetricMeterNature

use of io.openems.api.device.nature.meter.SymmetricMeterNature in project openems by OpenEMS.

the class SimulatorGridMeter method update.

@Override
protected void update() {
    super.update();
    long activePower = 0;
    long activePowerL1 = 0;
    long activePowerL2 = 0;
    long activePowerL3 = 0;
    if (activePowerLoad != null) {
        factorL1 = SimulatorTools.addRandomDouble(factorL1, 0, 1, 0.01);
        factorL2 = SimulatorTools.addRandomDouble(factorL2, 0, 1 - factorL1, 0.01);
        factorL3 = 1 - factorL1 - factorL2;
        long load = activePowerLoad.getLoad();
        activePower = load;
        activePowerL1 = (long) (load * factorL1);
        activePowerL2 = (long) (load * factorL2);
        activePowerL3 = (long) (load * factorL3);
    }
    long reactivePower = 0;
    long reactivePowerL1 = 0;
    long reactivePowerL2 = 0;
    long reactivePowerL3 = 0;
    if (reactivePowerLoad != null) {
        reactivePower = reactivePowerLoad.getLoad();
        reactivePowerL1 = reactivePower / 3;
        reactivePowerL2 = reactivePower / 3;
        reactivePowerL3 = reactivePower / 3;
    }
    for (EssNature entry : essNatures) {
        if (entry instanceof SymmetricEssNature) {
            SymmetricEssNature ess = (SymmetricEssNature) entry;
            activePower -= ess.activePower().valueOptional().orElse(0L);
            activePowerL1 -= ess.activePower().valueOptional().orElse(0L) / 3;
            activePowerL2 -= ess.activePower().valueOptional().orElse(0L) / 3;
            activePowerL3 -= ess.activePower().valueOptional().orElse(0L) / 3;
            reactivePower -= ess.reactivePower().valueOptional().orElse(0L);
            reactivePowerL1 -= ess.reactivePower().valueOptional().orElse(0L) / 3;
            reactivePowerL2 -= ess.reactivePower().valueOptional().orElse(0L) / 3;
            reactivePowerL3 -= ess.reactivePower().valueOptional().orElse(0L) / 3;
        } else if (entry instanceof AsymmetricEssNature) {
            AsymmetricEssNature ess = (AsymmetricEssNature) entry;
            activePower -= ess.activePowerL1().valueOptional().orElse(0L) + ess.activePowerL2().valueOptional().orElse(0L) + ess.activePowerL3().valueOptional().orElse(0L);
            activePowerL1 -= ess.activePowerL1().valueOptional().orElse(0L);
            activePowerL2 -= ess.activePowerL2().valueOptional().orElse(0L);
            activePowerL3 -= ess.activePowerL3().valueOptional().orElse(0L);
            reactivePower -= ess.reactivePowerL1().valueOptional().orElse(0L) + ess.reactivePowerL2().valueOptional().orElse(0L) + ess.reactivePowerL3().valueOptional().orElse(0L);
            reactivePowerL1 -= ess.reactivePowerL1().valueOptional().orElse(0L);
            reactivePowerL2 -= ess.reactivePowerL2().valueOptional().orElse(0L);
            reactivePowerL3 -= ess.reactivePowerL3().valueOptional().orElse(0L);
        }
    }
    for (MeterNature entry : meterNatures) {
        if (entry instanceof SymmetricMeterNature) {
            SymmetricMeterNature meter = (SymmetricMeterNature) entry;
            activePower -= meter.activePower().valueOptional().orElse(0L);
            activePowerL1 -= meter.activePower().valueOptional().orElse(0L) / 3;
            activePowerL2 -= meter.activePower().valueOptional().orElse(0L) / 3;
            activePowerL3 -= meter.activePower().valueOptional().orElse(0L) / 3;
            reactivePower -= meter.reactivePower().valueOptional().orElse(0L);
            reactivePowerL1 -= meter.reactivePower().valueOptional().orElse(0L) / 3;
            reactivePowerL2 -= meter.reactivePower().valueOptional().orElse(0L) / 3;
            reactivePowerL3 -= meter.reactivePower().valueOptional().orElse(0L) / 3;
        } else if (entry instanceof AsymmetricMeterNature) {
            AsymmetricMeterNature meter = (AsymmetricMeterNature) entry;
            activePower -= meter.activePowerL1().valueOptional().orElse(0L) + meter.activePowerL2().valueOptional().orElse(0L) + meter.activePowerL3().valueOptional().orElse(0L);
            activePowerL1 -= meter.activePowerL1().valueOptional().orElse(0L);
            activePowerL2 -= meter.activePowerL2().valueOptional().orElse(0L);
            activePowerL3 -= meter.activePowerL3().valueOptional().orElse(0L);
            reactivePower -= meter.reactivePowerL1().valueOptional().orElse(0L) + meter.reactivePowerL2().valueOptional().orElse(0L) + meter.reactivePowerL3().valueOptional().orElse(0L);
            reactivePowerL1 -= meter.reactivePowerL1().valueOptional().orElse(0L);
            reactivePowerL2 -= meter.reactivePowerL2().valueOptional().orElse(0L);
            reactivePowerL3 -= meter.reactivePowerL3().valueOptional().orElse(0L);
        }
    }
    if (isOffGrid(essNatures)) {
        this.activePower.updateValue(null);
        this.activePowerL1.updateValue(null);
        this.activePowerL2.updateValue(null);
        this.activePowerL3.updateValue(null);
        this.reactivePower.updateValue(null);
        this.reactivePowerL1.updateValue(null);
        this.reactivePowerL2.updateValue(null);
        this.reactivePowerL3.updateValue(null);
    } else {
        this.activePower.updateValue(activePower);
        this.activePowerL1.updateValue(activePowerL1);
        this.activePowerL2.updateValue(activePowerL2);
        this.activePowerL3.updateValue(activePowerL3);
        this.reactivePower.updateValue(reactivePower);
        this.reactivePowerL1.updateValue(reactivePowerL1);
        this.reactivePowerL2.updateValue(reactivePowerL2);
        this.reactivePowerL3.updateValue(reactivePowerL3);
    }
}
Also used : AsymmetricEssNature(io.openems.api.device.nature.ess.AsymmetricEssNature) EssNature(io.openems.api.device.nature.ess.EssNature) SymmetricEssNature(io.openems.api.device.nature.ess.SymmetricEssNature) SymmetricMeterNature(io.openems.api.device.nature.meter.SymmetricMeterNature) AsymmetricMeterNature(io.openems.api.device.nature.meter.AsymmetricMeterNature) MeterNature(io.openems.api.device.nature.meter.MeterNature) SymmetricMeterNature(io.openems.api.device.nature.meter.SymmetricMeterNature) AsymmetricMeterNature(io.openems.api.device.nature.meter.AsymmetricMeterNature) SymmetricEssNature(io.openems.api.device.nature.ess.SymmetricEssNature) AsymmetricEssNature(io.openems.api.device.nature.ess.AsymmetricEssNature)

Example 4 with SymmetricMeterNature

use of io.openems.api.device.nature.meter.SymmetricMeterNature in project openems by OpenEMS.

the class MeterClusterNature method update.

@Override
protected void update() {
    Long activePower = null;
    Long activePowerL1 = null;
    Long activePowerL2 = null;
    Long activePowerL3 = null;
    Long reactivePower = null;
    Long reactivePowerL1 = null;
    Long reactivePowerL2 = null;
    Long reactivePowerL3 = null;
    Long voltage = null;
    Long voltageL1 = null;
    Long voltageL2 = null;
    Long voltageL3 = null;
    synchronized (asymmetricMeterList) {
        for (AsymmetricMeterNature meter : asymmetricMeterList) {
            if (meter.activePowerL1().valueOptional().isPresent()) {
                if (activePower == null) {
                    activePower = 0L;
                }
                if (activePowerL1 == null) {
                    activePowerL1 = 0L;
                }
                activePower += meter.activePowerL1().valueOptional().get();
                activePowerL1 += meter.activePowerL1().valueOptional().get();
            } else {
                log.warn(meter.id() + ": activePowerL1 is invalid!");
            }
            if (meter.activePowerL2().valueOptional().isPresent()) {
                if (activePower == null) {
                    activePower = 0L;
                }
                if (activePowerL2 == null) {
                    activePowerL2 = 0L;
                }
                activePower += meter.activePowerL2().valueOptional().get();
                activePowerL2 += meter.activePowerL2().valueOptional().get();
            } else {
                log.warn(meter.id() + ": activePowerL2 is invalid!");
            }
            if (meter.activePowerL3().valueOptional().isPresent()) {
                if (activePower == null) {
                    activePower = 0L;
                }
                if (activePowerL3 == null) {
                    activePowerL3 = 0L;
                }
                activePower += meter.activePowerL3().valueOptional().get();
                activePowerL3 += meter.activePowerL3().valueOptional().get();
            } else {
                log.warn(meter.id() + ": activePowerL3 is invalid!");
            }
            if (meter.reactivePowerL1().valueOptional().isPresent()) {
                if (reactivePower == null) {
                    reactivePower = 0L;
                }
                if (reactivePowerL1 == null) {
                    reactivePowerL1 = 0L;
                }
                reactivePower += meter.reactivePowerL1().valueOptional().get();
                reactivePowerL1 += meter.reactivePowerL1().valueOptional().get();
            } else {
                log.warn(meter.id() + ": reactivePowerL1 is invalid!");
            }
            if (meter.reactivePowerL2().valueOptional().isPresent()) {
                if (reactivePower == null) {
                    reactivePower = 0L;
                }
                if (reactivePowerL2 == null) {
                    reactivePowerL2 = 0L;
                }
                reactivePower += meter.reactivePowerL2().valueOptional().get();
                reactivePowerL2 += meter.reactivePowerL2().valueOptional().get();
            } else {
                log.warn(meter.id() + ": reactivePowerL2 is invalid!");
            }
            if (meter.reactivePowerL3().valueOptional().isPresent()) {
                if (reactivePower == null) {
                    reactivePower = 0L;
                }
                if (reactivePowerL3 == null) {
                    reactivePowerL3 = 0L;
                }
                reactivePower += meter.reactivePowerL3().valueOptional().get();
                reactivePowerL3 += meter.reactivePowerL3().valueOptional().get();
            } else {
                log.warn(meter.id() + ": reactivePowerL3 is invalid!");
            }
            try {
                if (voltage == null) {
                    voltage = meter.voltageL1().value();
                }
                if (voltageL1 == null) {
                    voltageL1 = meter.voltageL1().value();
                }
            } catch (InvalidValueException e) {
                log.warn(meter.id() + ": voltageL1 is invalid!");
            }
            try {
                if (voltage == null) {
                    voltage = meter.voltageL2().value();
                }
                if (voltageL2 == null) {
                    voltageL2 = meter.voltageL2().value();
                }
            } catch (InvalidValueException e) {
                log.warn(meter.id() + ": voltageL2 is invalid!");
            }
            try {
                if (voltage == null) {
                    voltage = meter.voltageL3().value();
                }
                if (voltageL3 == null) {
                    voltageL3 = meter.voltageL3().value();
                }
            } catch (InvalidValueException e) {
                log.warn(meter.id() + ": voltageL3 is invalid!");
            }
        }
    }
    synchronized (symmetricMeterList) {
        for (SymmetricMeterNature meter : symmetricMeterList) {
            if (meter.activePower().valueOptional().isPresent()) {
                if (activePower == null) {
                    activePower = 0L;
                }
                if (activePowerL1 == null) {
                    activePowerL1 = 0L;
                }
                if (activePowerL2 == null) {
                    activePowerL2 = 0L;
                }
                if (activePowerL3 == null) {
                    activePowerL3 = 0L;
                }
                activePower += meter.activePower().valueOptional().get();
                activePowerL1 += meter.activePower().valueOptional().get() / 3;
                activePowerL2 += meter.activePower().valueOptional().get() / 3;
                activePowerL3 += meter.activePower().valueOptional().get() / 3;
            } else {
                log.warn(meter.id() + ": activePower is invalid!");
            }
            if (meter.activePower().valueOptional().isPresent()) {
                if (reactivePower == null) {
                    reactivePower = 0L;
                }
                if (reactivePowerL1 == null) {
                    reactivePowerL1 = 0L;
                }
                if (reactivePowerL2 == null) {
                    reactivePowerL2 = 0L;
                }
                if (reactivePowerL3 == null) {
                    reactivePowerL3 = 0L;
                }
                reactivePower += meter.reactivePower().valueOptional().get();
                reactivePowerL1 += meter.reactivePower().valueOptional().get() / 3;
                reactivePowerL2 += meter.reactivePower().valueOptional().get() / 3;
                reactivePowerL3 += meter.reactivePower().valueOptional().get() / 3;
            } else {
                log.warn(meter.id() + ": reactivePower is invalid!");
            }
            try {
                if (voltage == null) {
                    voltage = meter.voltage().value();
                }
            } catch (InvalidValueException e) {
                log.warn(meter.id() + ": voltage is invalid!");
            }
        }
    }
    this.activePower.updateValue(activePower);
    this.activePowerL1.updateValue(activePowerL1);
    this.activePowerL2.updateValue(activePowerL2);
    this.activePowerL3.updateValue(activePowerL3);
    this.reactivePower.updateValue(reactivePower);
    this.reactivePowerL1.updateValue(reactivePowerL1);
    this.reactivePowerL2.updateValue(reactivePowerL2);
    this.reactivePowerL3.updateValue(reactivePowerL3);
    if (activePower != null && reactivePower != null) {
        this.apparentPower.updateValue(ControllerUtils.calculateApparentPower(activePower, reactivePower));
    } else {
        this.apparentPower.updateValue(null);
    }
    this.voltage.updateValue(voltage);
    this.voltageL1.updateValue(voltageL1);
    this.voltageL2.updateValue(voltageL2);
    this.voltageL3.updateValue(voltageL3);
}
Also used : InvalidValueException(io.openems.api.exception.InvalidValueException) SymmetricMeterNature(io.openems.api.device.nature.meter.SymmetricMeterNature) AsymmetricMeterNature(io.openems.api.device.nature.meter.AsymmetricMeterNature)

Aggregations

AsymmetricMeterNature (io.openems.api.device.nature.meter.AsymmetricMeterNature)4 SymmetricMeterNature (io.openems.api.device.nature.meter.SymmetricMeterNature)4 InvalidValueException (io.openems.api.exception.InvalidValueException)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 AsymmetricEssNature (io.openems.api.device.nature.ess.AsymmetricEssNature)1 EssNature (io.openems.api.device.nature.ess.EssNature)1 SymmetricEssNature (io.openems.api.device.nature.ess.SymmetricEssNature)1 MeterNature (io.openems.api.device.nature.meter.MeterNature)1 Thing (io.openems.api.thing.Thing)1