This Python package implements the message validation for the EN50491-12-2 "S2" standard for home and building energy management. This implementation is based on the asyncapi description of the protocol provided in the s2-ws-json repository. To learn more about the S2 standard:
- Read the S2 standard's documentation for a detailed explanation of S2
- Visit the website for a high-level explanation of S2
- Read the whitepaper to learn why it's important to expose and utilise energy flexibility
You can install this package using pip or any Python dependency manager that collects the packages from PyPI:
pip install s2-python
pip install s2-python[ws] # for S2 over WebSocketsThe packages on PyPI may be found here.
s2-python uses pydantic at its core to define the various S2 messages. As such, the pydantic mypy plugin is required for type checking to succeed.
Add to your pyproject.toml:
[tool.mypy]
plugins = ['pydantic.mypy']from s2python.common import PowerRange, CommodityQuantity
# create s2 messages as Python objects
number_range = PowerRange(
start_of_range=4.0,
end_of_range=5.0,
commodity_quantity=CommodityQuantity.ELECTRIC_POWER_L1,
)
# serialize s2 messages
number_range.to_json()
# deserialize s2 messages
json_str = '{"start_of_range": 4.0, "end_of_range": 5.0, "commodity_quantity": "ELECTRIC.POWER.L1"}'
PowerRange.from_json(json_str)For development, you can install the required dependencies using the following command:
pip install -e .[testing,development,ws]The tests can be run using tox:
toxTo build the package, you can use tox as well:
tox -e build,cleanThis project is co-financed by TKI-Energie from the Top Consortia for Knowledge and Innovation (TKI) surcharge of the Ministry of Economic Affairs and Climate Policy.