Skip to content

add (device) consumption and production capacities as sensors#897

Merged
victorgarcia98 merged 19 commits intomainfrom
feature/planning/battery-power-capacity-as-sensor
Dec 19, 2023
Merged

add (device) consumption and production capacities as sensors#897
victorgarcia98 merged 19 commits intomainfrom
feature/planning/battery-power-capacity-as-sensor

Conversation

@victorgarcia98
Copy link
Copy Markdown
Contributor

@victorgarcia98 victorgarcia98 commented Nov 10, 2023

Description

This PR introduces the capability of defining device-level power constraints as time series.

This sensors can be passed through the flex-model and the scheduler will look into the sensors belonging to the device (sensors of the same asset) and look for sensors with some alias.

To support this, this PR introduces the concept of sensor alias, a new column of the sensor table that serves as an internal reference for sensors. Using the name would have been a good alternative but the user could change it, the idea is that the alias is not touched by the user.

Further Improvements

  • Do the same for the site-level capacity. This might require defaulting to a sensor belonging to the parent Asset.
  • Document this.
  • Create more tests where, we are actually checking that the min/max device constraints columns are being set properly.

Related Items

Closes #761

Note: I'll keep this PR as draft for now to flag this as very prototype work.


  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

@victorgarcia98 victorgarcia98 self-assigned this Nov 10, 2023
@Flix6x Flix6x changed the title add (device) consumption and production capacites as sensors add (device) consumption and production capacities as sensors Nov 10, 2023
@Flix6x Flix6x added this to the 0.18.0 milestone Nov 10, 2023
Copy link
Copy Markdown
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand what the alias concept is for yet. Could you give one or two examples of how you'd intend to use it?

@victorgarcia98
Copy link
Copy Markdown
Contributor Author

I don't really understand what the alias concept is for yet. Could you give one or two examples of how you'd intend to use it?

Sure. In short the alias is a protected name which means that users should not be able to edit it. Even though the name cannot be changed via the UI yet (as far as I know), It will probably be something we want to implement. If we rely on the name for internal mechanisms the process might fail in case the name is changed.

Some examples:

  • What is the power sensor of an Asset? The one that has the power alias. The user might decide to use any other name on the visual side but internally, we can fetch that sensor using the alias power. Alternative names: discharge, charge, charge power, discharge power, consumption, production, ...
  • What is the SOC of the battery? The one that has the SOC alias. Same here: the user could chose to present a different sensor name. Some examples: State of Charge, Fill level, Capacity, ...
  • Solar power: power, production, active power, dc power, ...

An alternative would be to define which sensor represents what as a the asset attribute.

Other reasons to have this alias is to standarize operations. Let's say we want to set up 100 sites. In that case, we might use a format for the sensor names, for example: charge power. In another project the client might set this as discharge power. Internally, we could just fetch the power sensor using the power alias and use the consumption_is_positive attribute to get the sign right.

@Flix6x
Copy link
Copy Markdown
Contributor

Flix6x commented Nov 10, 2023

Then technically the alias isn't required for this PR, right? This is about allowing API users to pass a sensor ID rather than a float. My line of thinking is the following.

Right now, we support:

{
    "flex-model": {
        "power-capacity": "25 kW"
    }
}

After this PR, this would become a viable alternative:

{
    "flex-model": {
        "power-capacity": {"sensor": 51}
    }
}

The title of this PR suggests it tackles a second feature at the same time (separate device power capacities for consumption and production), which is fine. My line of thinking would be to keep the API fields as consistent as possible, by introducing the consumption-capacity and production-capacity fields, similarly to what we have done with site-power-capacity, site-consumption-capacity and site-production-capacity. Then we would support flex models such as:

{
    "flex-model": {
        "consumption-capacity": "25 kW",
        "production-capacity": {"sensor": 51}
    }
}

In this example, the consumption capacity is a constant value, while the production capacity changes over time, as recorded in sensor 51.

Victor Garcia Reolid added 3 commits November 13, 2023 09:45
Signed-off-by: Victor Garcia Reolid <[email protected]>
Signed-off-by: Victor Garcia Reolid <[email protected]>
Signed-off-by: Victor Garcia Reolid <[email protected]>
@victorgarcia98
Copy link
Copy Markdown
Contributor Author

victorgarcia98 commented Nov 14, 2023

You're absolutely right, the alias feature is not really needed to allow passing the capacities as sensors.

I've created a new Schema for what I call a QuantityOrSensor (name TBD). Maybe the name should be something more inline with QuantityOrEntity to allow for an Asset to be an input? Perhaps it's fine to limit it to a sensor given that it's the way we describe the data.

On the side, I've created the utility function get_series_from_sensor_or_quantity to create a pandas series from the output of a QuantityOrEntity field.

This feature is tested in flexmeasures/data/models/planning/tests/test_solver.py:test_battery_power_capacity_as_sensor.

Signed-off-by: Victor Garcia Reolid <[email protected]>
@victorgarcia98 victorgarcia98 marked this pull request as ready for review November 14, 2023 22:16
Victor Garcia Reolid added 4 commits November 16, 2023 15:25
Signed-off-by: Victor Garcia Reolid <[email protected]>
Signed-off-by: Victor Garcia Reolid <[email protected]>
Signed-off-by: Victor Garcia Reolid <[email protected]>
Signed-off-by: Victor Garcia Reolid <[email protected]>
Signed-off-by: Victor Garcia Reolid <[email protected]>
@Flix6x
Copy link
Copy Markdown
Contributor

Flix6x commented Nov 22, 2023

Just an update: I'm refactoring this work slightly and will create a PR to merge into this branch any day now.

@victorgarcia98 victorgarcia98 mentioned this pull request Nov 22, 2023
5 tasks
@Flix6x Flix6x mentioned this pull request Nov 23, 2023
* refactor: fix spelling

Signed-off-by: F.N. Claessen <[email protected]>

* style: missing type annotation

Signed-off-by: F.N. Claessen <[email protected]>

* refactor: method and variable renaming

Signed-off-by: F.N. Claessen <[email protected]>

* refactor: add test case explanations

Signed-off-by: F.N. Claessen <[email protected]>

---------

Signed-off-by: F.N. Claessen <[email protected]>
* refactor: fix spelling

Signed-off-by: F.N. Claessen <[email protected]>

* style: missing type annotation

Signed-off-by: F.N. Claessen <[email protected]>

* refactor: method and variable renaming

Signed-off-by: F.N. Claessen <[email protected]>

* refactor: add test case explanations

Signed-off-by: F.N. Claessen <[email protected]>

* fix: separate logic for falling back on a default attribute and applying a maximum capacity limit

Signed-off-by: F.N. Claessen <[email protected]>

* fix: fill gaps in capacity sensor data using the max_value rather than with the fallback

Signed-off-by: F.N. Claessen <[email protected]>

* fix: type annotation (see https://docs.python.org/3/library/typing.html#typing.Optional)

Signed-off-by: F.N. Claessen <[email protected]>

* refactor: clearly separate steps of falling back and performing a nanmin

Signed-off-by: F.N. Claessen <[email protected]>

* refactor: simplify and have get_quantity_from_attribute return a Quantity, as its name already suggested

Signed-off-by: F.N. Claessen <[email protected]>

* refactor: switch argument order

Signed-off-by: F.N. Claessen <[email protected]>

* refactor: update docstring

Signed-off-by: F.N. Claessen <[email protected]>

* style: flake8

Signed-off-by: F.N. Claessen <[email protected]>

---------

Signed-off-by: F.N. Claessen <[email protected]>
@Flix6x
Copy link
Copy Markdown
Contributor

Flix6x commented Dec 4, 2023

Looks like this is almost ready to ship out. Can you resolve the merge conflict, add a changelog item, and create tickets for your suggested follow-ups?

Victor Garcia Reolid added 2 commits December 12, 2023 11:07
…ery-power-capacity-as-sensor

Signed-off-by: Victor Garcia Reolid <[email protected]>
Signed-off-by: Victor Garcia Reolid <[email protected]>
Signed-off-by: Victor Garcia Reolid <[email protected]>
@victorgarcia98
Copy link
Copy Markdown
Contributor Author

Looks like this is almost ready to ship out. Can you resolve the merge conflict, add a changelog item, and create tickets for your suggested follow-ups?

Thanks! I've resolved the merge conflict added the changelog entry and created the tickets.

Signed-off-by: Victor Garcia Reolid <[email protected]>
Copy link
Copy Markdown
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A side question: These capacity fields are not supported in flexmeasures add schedule for-storage, right? Should this be a new issue?

@Flix6x
Copy link
Copy Markdown
Contributor

Flix6x commented Dec 14, 2023

Yes, new issue please. We want to make headway with the API first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let flex_model.capacity_in_mw be a sensor

3 participants