Skip to content

Index

frequenz.sdk.microgrid ¤

A microgrid is a local electrical grid that connects a set of electrical components together. They are often built around a passive power consumer, to supplement the electricity consumed from the public grid with on-site power generation or storage systems.

Microgrids can also function in island-mode, without a grid connection, or without a local power consumer, but they have to have at least one of the two, to be meaningful.

Frequenz SDK Microgrid Model¤

The SDK aims to provide an abstract model of the microgrid that enables high-level interactions with microgrid components, without having to worry about (or even be aware of) location-specific details such as:

  • where the meters are placed,
  • how many batteries,
  • whether there's a grid connection or a passive consumer,
  • what models the inverters are, etc.
  • whether components are having downtimes, because metrics and limits get adjusted automatically when components are having downtimes.

Users of the SDK can develop applications around this interface once and deploy anywhere, and the SDK will take care of translating the requests and instructions to correspond to the specific microgrid configurations.

flowchart LR

subgraph Left[Measurements only]
direction LR
  grid["Grid Connection"]
  consumer["Consumer"]
  pv["PV Arrays"]
  chp["CHP"]
end

junction(( ))

subgraph Right[Measurements and control]
direction LR
  bat["Batteries"]
  ev["EV Chargers"]
end

grid --- junction
consumer --- junction
pv --- junction
chp --- junction

junction --- bat
junction --- ev

Grid¤

This refers to a microgrid's connection to the external Grid. The power flowing through this connection can be streamed through grid_power.

In locations without a grid connection, this method remains accessible, and streams zero values.

Consumer¤

This is the main power consumer at the site of a microgrid, and often the load the microgrid is built to support. The power drawn by the consumer is available through consumer_power

In locations without a consumer, this method streams zero values.

Producers: PV Arrays, CHP¤

The total CHP production in a site can be streamed through chp_power. PV Power is available through the PV pool described below. And total producer power is available through microgrid.producer().power.

As is the case with the other methods, if PV Arrays or CHPs are not available in a microgrid, the corresponding methods stream zero values.

PV Arrays¤

The total PV power production is available through pv_pool's power. The PV pool by default uses all PV inverters available at a location, but PV pool instances can be created for subsets of PV inverters if necessary, by specifying the inverter ids.

The pv_pool also provides available power bounds through the power_status method.

The pv_pool also provides a control method propose_power, which accepts values in the Passive Sign Convention and supports only production.

Batteries¤

The total Battery power is available through battery_pool's power. The battery pool by default uses all batteries available at a location, but battery pool instances can be created for subsets of batteries if necessary, by specifying the battery ids.

The battery_pool also provides soc, capacity, temperature and available power bounds through the power_status method.

The battery_pool also provides control methods propose_power (which accepts values in the Passive Sign Convention and supports both charging and discharging), or through propose_charge, or propose_discharge.

EV Chargers¤

The ev_charger_pool offers a power method that streams the total power measured for all the EV Chargers at a site.

The ev_charger_pool also provides available power bounds through the power_status method.

The ev_charger_pool also provides a control method propose_power, which accepts values in the Passive Sign Convention and supports only charging.

Classes¤

Functions¤

frequenz.sdk.microgrid.battery_pool ¤

battery_pool(
    battery_ids: Set[int] | None = None,
    name: str | None = None,
    priority: int = -sys.maxsize - 1,
) -> BatteryPool

Return a new BatteryPool instance for the given parameters.

The priority value is used to resolve conflicts when multiple actors are trying to propose different power values for the same set of batteries.

Note

When specifying priority, bigger values indicate higher priority. The default priority is the lowest possible value.

It is recommended to reuse the same instance of the BatteryPool within the same actor, unless they are managing different sets of batteries.

In deployments with multiple actors managing the same set of batteries, it is recommended to use different priorities to distinguish between them. If not, a random prioritization will be imposed on them to resolve conflicts, which may lead to unexpected behavior like longer duration to converge on the desired power.

PARAMETER DESCRIPTION
battery_ids

Optional set of IDs of batteries to be managed by the BatteryPool. If not specified, all batteries available in the component graph are used.

TYPE: Set[int] | None DEFAULT: None

name

An optional name used to identify this instance of the pool or a corresponding actor in the logs.

TYPE: str | None DEFAULT: None

priority

The priority of the actor making the call.

TYPE: int DEFAULT: -maxsize - 1

RETURNS DESCRIPTION
BatteryPool

A BatteryPool instance.

Source code in frequenz/sdk/microgrid/_data_pipeline.py
def battery_pool(
    battery_ids: abc.Set[int] | None = None,
    name: str | None = None,
    priority: int = -sys.maxsize - 1,
) -> BatteryPool:
    """Return a new `BatteryPool` instance for the given parameters.

    The priority value is used to resolve conflicts when multiple actors are trying to
    propose different power values for the same set of batteries.

    !!! note
        When specifying priority, bigger values indicate higher priority. The default
        priority is the lowest possible value.

        It is recommended to reuse the same instance of the `BatteryPool` within the
        same actor, unless they are managing different sets of batteries.

        In deployments with multiple actors managing the same set of batteries, it is
        recommended to use different priorities to distinguish between them.  If not,
        a random prioritization will be imposed on them to resolve conflicts, which may
        lead to unexpected behavior like longer duration to converge on the desired
        power.

    Args:
        battery_ids: Optional set of IDs of batteries to be managed by the `BatteryPool`.
            If not specified, all batteries available in the component graph are used.
        name: An optional name used to identify this instance of the pool or a
            corresponding actor in the logs.
        priority: The priority of the actor making the call.

    Returns:
        A `BatteryPool` instance.
    """
    return _get().battery_pool(battery_ids, name, priority)

frequenz.sdk.microgrid.consumer ¤

consumer() -> Consumer

Return the Consumption measuring point.

Source code in frequenz/sdk/microgrid/_data_pipeline.py
def consumer() -> Consumer:
    """Return the [`Consumption`][frequenz.sdk.timeseries.consumer.Consumer] measuring point."""
    return _get().consumer()

frequenz.sdk.microgrid.ev_charger_pool ¤

ev_charger_pool(
    ev_charger_ids: Set[int] | None = None,
    name: str | None = None,
    priority: int = -sys.maxsize - 1,
) -> EVChargerPool

Return a new EVChargerPool instance for the given parameters.

The priority value is used to resolve conflicts when multiple actors are trying to propose different power values for the same set of EV chargers.

Note

When specifying priority, bigger values indicate higher priority. The default priority is the lowest possible value.

It is recommended to reuse the same instance of the EVChargerPool within the same actor, unless they are managing different sets of EV chargers.

In deployments with multiple actors managing the same set of EV chargers, it is recommended to use different priorities to distinguish between them. If not, a random prioritization will be imposed on them to resolve conflicts, which may lead to unexpected behavior like longer duration to converge on the desired power.

PARAMETER DESCRIPTION
ev_charger_ids

Optional set of IDs of EV Chargers to be managed by the EVChargerPool. If not specified, all EV Chargers available in the component graph are used.

TYPE: Set[int] | None DEFAULT: None

name

An optional name used to identify this instance of the pool or a corresponding actor in the logs.

TYPE: str | None DEFAULT: None

priority

The priority of the actor making the call.

TYPE: int DEFAULT: -maxsize - 1

RETURNS DESCRIPTION
EVChargerPool

An EVChargerPool instance.

Source code in frequenz/sdk/microgrid/_data_pipeline.py
def ev_charger_pool(
    ev_charger_ids: abc.Set[int] | None = None,
    name: str | None = None,
    priority: int = -sys.maxsize - 1,
) -> EVChargerPool:
    """Return a new `EVChargerPool` instance for the given parameters.

    The priority value is used to resolve conflicts when multiple actors are trying to
    propose different power values for the same set of EV chargers.

    !!! note
        When specifying priority, bigger values indicate higher priority. The default
        priority is the lowest possible value.

        It is recommended to reuse the same instance of the `EVChargerPool` within the
        same actor, unless they are managing different sets of EV chargers.

        In deployments with multiple actors managing the same set of EV chargers, it is
        recommended to use different priorities to distinguish between them.  If not,
        a random prioritization will be imposed on them to resolve conflicts, which may
        lead to unexpected behavior like longer duration to converge on the desired
        power.

    Args:
        ev_charger_ids: Optional set of IDs of EV Chargers to be managed by the
            EVChargerPool.  If not specified, all EV Chargers available in the
            component graph are used.
        name: An optional name used to identify this instance of the pool or a
            corresponding actor in the logs.
        priority: The priority of the actor making the call.

    Returns:
        An `EVChargerPool` instance.
    """
    return _get().ev_charger_pool(ev_charger_ids, name, priority)

frequenz.sdk.microgrid.frequency ¤

frequency() -> GridFrequency

Return the grid frequency measuring point.

Source code in frequenz/sdk/microgrid/_data_pipeline.py
def frequency() -> GridFrequency:
    """Return the grid frequency measuring point."""
    return _get().frequency()

frequenz.sdk.microgrid.grid ¤

grid() -> Grid

Return the grid measuring point.

Source code in frequenz/sdk/microgrid/_data_pipeline.py
def grid() -> Grid:
    """Return the grid measuring point."""
    return _get().grid()

frequenz.sdk.microgrid.initialize async ¤

initialize(
    host: str, port: int, resampler_config: ResamplerConfig
) -> None

Initialize the microgrid connection manager and the data pipeline.

PARAMETER DESCRIPTION
host

Host to connect to, to reach the microgrid API.

TYPE: str

port

port to connect to.

TYPE: int

resampler_config

Configuration for the resampling actor.

TYPE: ResamplerConfig

Source code in frequenz/sdk/microgrid/__init__.py
async def initialize(host: str, port: int, resampler_config: ResamplerConfig) -> None:
    """Initialize the microgrid connection manager and the data pipeline.

    Args:
        host: Host to connect to, to reach the microgrid API.
        port: port to connect to.
        resampler_config: Configuration for the resampling actor.
    """
    await connection_manager.initialize(host, port)
    await _data_pipeline.initialize(resampler_config)

frequenz.sdk.microgrid.logical_meter ¤

logical_meter() -> LogicalMeter

Return the logical meter of the microgrid.

Source code in frequenz/sdk/microgrid/_data_pipeline.py
def logical_meter() -> LogicalMeter:
    """Return the logical meter of the microgrid."""
    return _get().logical_meter()

frequenz.sdk.microgrid.producer ¤

producer() -> Producer

Return the Production measuring point.

Source code in frequenz/sdk/microgrid/_data_pipeline.py
def producer() -> Producer:
    """Return the [`Production`][frequenz.sdk.timeseries.producer.Producer] measuring point."""
    return _get().producer()

frequenz.sdk.microgrid.pv_pool ¤

pv_pool(
    pv_inverter_ids: Set[int] | None = None,
    name: str | None = None,
    priority: int = -sys.maxsize - 1,
) -> PVPool

Return a new PVPool instance for the given parameters.

The priority value is used to resolve conflicts when multiple actors are trying to propose different power values for the same set of PV inverters.

Note

When specifying priority, bigger values indicate higher priority. The default priority is the lowest possible value.

It is recommended to reuse the same instance of the PVPool within the same actor, unless they are managing different sets of PV inverters.

In deployments with multiple actors managing the same set of PV inverters, it is recommended to use different priorities to distinguish between them. If not, a random prioritization will be imposed on them to resolve conflicts, which may lead to unexpected behavior like longer duration to converge on the desired power.

PARAMETER DESCRIPTION
pv_inverter_ids

Optional set of IDs of PV inverters to be managed by the PVPool. If not specified, all PV inverters available in the component graph are used.

TYPE: Set[int] | None DEFAULT: None

name

An optional name used to identify this instance of the pool or a corresponding actor in the logs.

TYPE: str | None DEFAULT: None

priority

The priority of the actor making the call.

TYPE: int DEFAULT: -maxsize - 1

RETURNS DESCRIPTION
PVPool

A PVPool instance.

Source code in frequenz/sdk/microgrid/_data_pipeline.py
def pv_pool(
    pv_inverter_ids: abc.Set[int] | None = None,
    name: str | None = None,
    priority: int = -sys.maxsize - 1,
) -> PVPool:
    """Return a new `PVPool` instance for the given parameters.

    The priority value is used to resolve conflicts when multiple actors are trying to
    propose different power values for the same set of PV inverters.

    !!! note
        When specifying priority, bigger values indicate higher priority. The default
        priority is the lowest possible value.

        It is recommended to reuse the same instance of the `PVPool` within the same
        actor, unless they are managing different sets of PV inverters.

        In deployments with multiple actors managing the same set of PV inverters, it is
        recommended to use different priorities to distinguish between them.  If not,
        a random prioritization will be imposed on them to resolve conflicts, which may
        lead to unexpected behavior like longer duration to converge on the desired
        power.

    Args:
        pv_inverter_ids: Optional set of IDs of PV inverters to be managed by the
            `PVPool`. If not specified, all PV inverters available in the component
            graph are used.
        name: An optional name used to identify this instance of the pool or a
            corresponding actor in the logs.
        priority: The priority of the actor making the call.

    Returns:
        A `PVPool` instance.
    """
    return _get().pv_pool(pv_inverter_ids, name, priority)

frequenz.sdk.microgrid.voltage ¤

voltage() -> VoltageStreamer

Return the 3-phase voltage measuring point.

Source code in frequenz/sdk/microgrid/_data_pipeline.py
def voltage() -> VoltageStreamer:
    """Return the 3-phase voltage measuring point."""
    return _get().voltage()