This article was originally posted at FlexMeasures.
We’ve taken a crucial step in making FlexMeasures even more developer-friendly! Last week, we released version 0.1 of the new FlexMeasures client.
What is the use of a client library for the FlexMeasures platform? Well, FlexMeasures is foremost a web server ― it calculates optimal schedules for flexible energy assets in the cloud, according to price, CO2 output or other constraints. Its API is well-documented. Even though APIs are one of the web architecture’s shining beacons, it’s not really convenient for developers to use them directly. That’s where developer-friendly tooling, like client libraries, come in!
The FlexMeasures client wraps the most important interactions you need to add if you interact with FlexMeasures. For example, if you are connecting a local energy management system (EMS) to be optimized via FlexMeasures, you would need authentication, data I/O and the triggering of new computations. With the client, these functionalities are now as easy to use as calling a function. For instance, here we authorize to a FlexMeasures server, request a schedule for a battery charging sensor and retrieve it (once it’s computed):
import asyncio
from flexmeasures_client.client import FlexMeasuresClient
EMAIL = "admin@admin.nl"
PASSWORD = "admin"
async def my_script():
schedule = await flexmeasures_client.trigger_and_get_schedule(
sensor_id=1,
start="2023-06-18T10:00:00+00:00",
duration="PT45M",
soc_unit="MWh",
soc_at_start=50,
soc_targets=[
{
"value": 100,
"datetime": "2023-06-20T11:00+02:00",
}
],
consumption_price_sensor=3,
)
print(schedule)
client = FlexMeasuresClient(
email=EMAIL,
password=PASSWORD,
host="localhost:5000",
)
asyncio.run(my_script())
The FlexMeasures Client is written in Python, so it’s most useful for Python developers. In principle, other languages could follow.
At Seita, we first started using the client in a new service with smart heat storage control and in our V2G project. The FlexMeasures client will evolve together with the FlexMeasures API. For instance, adding sensors is a feature you can expect soon.
In addition, to the most important interactions, we’re also adding an S2 layer (S2 is a new flexible asset protocol, with explicit flexibility expression ability). We’ll talk more about S2 in another blog post.
If you’re trying out the FlexMeasures Client, we’d love to hear from you. Is it useful? What can be improved? You can add issues on the Github project page. And of course, stars as well as pull requests are welcome 🙂