Light weight Python package to interface with EnergyID Webhooks
Project description
energyid-webhooks
Python package for interfacing with EnergyID Webhooks (supports both V1 and V2 APIs)
Installation
pip install energyid-webhooks
Features
- V2 API support with device provisioning and claiming
- Authentication with automatic token renewal
- Smart sensor bundling for efficient data transmission
- Async support
- Full type hints
Type Checking
This package is fully type-hinted and checked with strict mypy settings.
V2 API Usage (Recommended)
The V2 API includes device provisioning, authentication, and smart bundling:
import asyncio
from energyid_webhooks import WebhookClient
# Create the client
client = WebhookClient(
client_id="your_provisioning_key",
client_secret="your_provisioning_secret",
device_id="unique_device_id",
device_name="My Device",
reauth_interval=24 # Hours between token refresh
)
async def main():
# Authenticate with EnergyID
is_claimed = await client.authenticate()
if not is_claimed:
# Device needs to be claimed
claim_info = client.get_claim_info()
print(f"Claim your device at {claim_info['claim_url']} with code {claim_info['claim_code']}")
# Wait for claiming...
return
# Add and update sensors
client.update_sensor("el", 1250.5) # Electricity consumption
client.update_sensor("pv", 3560.2) # Solar production
# Synchronize with EnergyID
await client.synchronize_sensors()
# Or enable automatic synchronization
client.start_auto_sync(interval_seconds=300) # Every 5 minutes
# Don't forget to close when done
await client.close()
asyncio.run(main())
V1 API Usage (Legacy)
The original API is still available for backward compatibility:
from energyid_webhooks import WebhookClientV1, WebhookPayload
url = "https://app.energyid.eu/integrations/WebhookIn/..."
client = WebhookClientV1(url)
# Post some data to the webhook
data = {
'remoteId': 'my-solar-inverter',
'remoteName': 'My Solar Panels',
'metric': 'solarPhotovoltaicProduction',
'metricKind': 'total',
'unit': 'kWh',
'interval': 'P1D',
'data': [['2022-10-05T08:00+0200', 0.004]]
}
client.post(data)
V1 Async Usage (Legacy)
import asyncio
from energyid_webhooks import WebhookClientAsyncV1
url = "https://app.energyid.eu/integrations/WebhookIn/..."
client = WebhookClientAsyncV1(url)
async def main():
data = {
'remoteId': 'my-solar-inverter',
'remoteName': 'My Solar Panels',
'metric': 'solarPhotovoltaicProduction',
'metricKind': 'total',
'unit': 'kWh',
'interval': 'P1D',
'data': [['2022-10-05T08:00+0200', 0.004]]
}
await client.post(data)
asyncio.run(main())
Demo Notebook
See energyid_webhook_demo.ipynb for a complete V2 API demo.
Development
Setup
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file energyid_webhooks-0.0.14.tar.gz
.
File metadata
- Download URL: energyid_webhooks-0.0.14.tar.gz
- Upload date:
- Size: 96.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b71cd8f8ed77244d49b1cda736a654241ceeb65058a1b6c73f741edb751ee2dd |
|
MD5 | 75e914fba15afa5f5483074b0591ef64 |
|
BLAKE2b-256 | 10712389b2786f904b1835012e9ec31cc18a69d6b2e9a1998182b98cba3ed247 |
Provenance
The following attestation bundles were made for energyid_webhooks-0.0.14.tar.gz
:
Publisher:
publish.yml
on EnergieID/energyid-webhooks-py
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
energyid_webhooks-0.0.14.tar.gz
- Subject digest:
b71cd8f8ed77244d49b1cda736a654241ceeb65058a1b6c73f741edb751ee2dd
- Sigstore transparency entry: 207366786
- Sigstore integration time:
- Permalink:
EnergieID/energyid-webhooks-py@0451cd0e8a59268941f3a53f2c68799c5396eeb7
- Branch / Tag:
refs/tags/v0.0.14
- Owner: https://github.com/EnergieID
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
publish.yml@0451cd0e8a59268941f3a53f2c68799c5396eeb7
- Trigger Event:
push
- Statement type:
File details
Details for the file energyid_webhooks-0.0.14-py3-none-any.whl
.
File metadata
- Download URL: energyid_webhooks-0.0.14-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd179a4682f92b85d5890f5e5d0801392804314783ef180b203bab12a7d72e12 |
|
MD5 | fa6295744d44404aa6fad8c893867f92 |
|
BLAKE2b-256 | c4aafb6de8596160a75e225d559cd0582a7d95addfff5d25f1bdaa70265f7b0b |
Provenance
The following attestation bundles were made for energyid_webhooks-0.0.14-py3-none-any.whl
:
Publisher:
publish.yml
on EnergieID/energyid-webhooks-py
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
energyid_webhooks-0.0.14-py3-none-any.whl
- Subject digest:
bd179a4682f92b85d5890f5e5d0801392804314783ef180b203bab12a7d72e12
- Sigstore transparency entry: 207366787
- Sigstore integration time:
- Permalink:
EnergieID/energyid-webhooks-py@0451cd0e8a59268941f3a53f2c68799c5396eeb7
- Branch / Tag:
refs/tags/v0.0.14
- Owner: https://github.com/EnergieID
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
publish.yml@0451cd0e8a59268941f3a53f2c68799c5396eeb7
- Trigger Event:
push
- Statement type: