baspa/energyzero-php-api
Composer 安装命令:
composer require baspa/energyzero-php-api
包简介
PHP client for the dynamic prices from EnergyZero
README 文档
README
This PHP package provides a client for fetching dynamic energy prices from the EnergyZero API. It allows you to retrieve energy prices for a specified date range with customizable intervals and VAT options.
Building your own client? See API.md for detailed API documentation with examples in multiple languages.
Price Availability
| Energy Type | Today's Prices | Tomorrow's Prices |
|---|---|---|
| Electricity | Available from 00:00 | Published around 14:00 UTC (15:00 CET / 16:00 CEST) |
| Gas | Available from 06:00 CET | Published around 05:00 UTC (06:00 CET / 07:00 CEST) |
Installation
You can install the package via composer:
composer require baspa/energyzero-php-api
Usage
You can fetch the energy prices for a specific date range with a specific interval and VAT option. When the VAT option is not provided, it will default to true. Make sure you provide a date in the format Y-m-d.
use Baspa\EnergyZero\EnergyZero; use Baspa\EnergyZero\Enums\Interval; $prices = (new EnergyZero())->energyPrices( startDate: '2024-01-01', endDate: '2024-01-02', interval: Interval::HOUR, vat: true );
The response will be an array of prices for the specified date range and also include the average price for the period.
Interval options
The following interval options are available:
| Interval | Enum | Value | Description |
|---|---|---|---|
| Quarter | Interval::QUARTER |
3 | 15-minute intervals |
| Hour | Interval::HOUR |
4 | Hourly intervals (default) |
| Day | Interval::DAY |
5 | Daily intervals |
| Week | Interval::WEEK |
6 | Weekly intervals |
| Month | Interval::MONTH |
7 | Monthly intervals |
| Year | Interval::YEAR |
8 | Yearly intervals |
You can also use integer values directly for backward compatibility:
$prices = (new EnergyZero())->energyPrices('2024-01-01', '2024-01-02', 4);
Set default interval
You can set a default interval that will be used for all requests:
use Baspa\EnergyZero\EnergyZero; use Baspa\EnergyZero\Enums\Interval; $energyZero = (new EnergyZero())->setDefaultInterval(Interval::QUARTER); // All subsequent calls will use 15-minute intervals by default $prices = $energyZero->energyPrices('2024-01-01', '2024-01-02');
Get quarter-hour prices
Fetch prices in 15-minute intervals for more granular data:
use Baspa\EnergyZero\EnergyZero; use Baspa\EnergyZero\Enums\Interval; $prices = (new EnergyZero())->energyPrices( startDate: '2024-01-01', endDate: '2024-01-01', interval: Interval::QUARTER );
Get gas prices
Fetch gas prices instead of electricity prices:
use Baspa\EnergyZero\EnergyZero; $gasPrices = (new EnergyZero())->gasPrices( startDate: '2024-01-01', endDate: '2024-01-02', vat: true );
Or set the default energy type:
use Baspa\EnergyZero\EnergyZero; use Baspa\EnergyZero\Enums\EnergyType; $energyZero = (new EnergyZero())->setDefaultEnergyType(EnergyType::GAS); $prices = $energyZero->energyPrices('2024-01-01', '2024-01-02');
Get the current price
Get the current electricity price for the current hour:
$currentPrice = (new EnergyZero())->getCurrentPrice(); // Returns: ['price' => 0.25, 'datetime' => '2024-01-01T14:00:00']
Get prices for specific hours
Get prices for specific hours of a day:
$prices = (new EnergyZero())->getPricesForHours( date: '2024-01-01', hours: [8, 12, 18, 22] );
Get the average price for a period
$averagePrice = (new EnergyZero())->getAveragePriceForPeriod( startDate: '2024-01-01', endDate: '2024-01-02', interval: Interval::HOUR, vat: true );
Get the lowest price for a period
$lowestPrice = (new EnergyZero())->getLowestPriceForPeriod( startDate: '2024-01-01', endDate: '2024-01-02', interval: Interval::HOUR, vat: true );
Get the highest price for a period
$highestPrice = (new EnergyZero())->getHighestPriceForPeriod( startDate: '2024-01-01', endDate: '2024-01-02', interval: Interval::HOUR, vat: true );
Get the prices above a threshold
$prices = (new EnergyZero())->getPricesAboveThreshold( startDate: '2024-01-01', endDate: '2024-01-02', threshold: 0.05, interval: Interval::HOUR, vat: true );
Get the prices below a threshold
$prices = (new EnergyZero())->getPricesBelowThreshold( startDate: '2024-01-01', endDate: '2024-01-02', threshold: 0.05, interval: Interval::HOUR, vat: true );
Get the peak hours
Get the top N peak hours for a period.
$peakHours = (new EnergyZero())->getPeakHours( startDate: '2024-01-01', endDate: '2024-01-02', topN: 5, interval: Interval::HOUR, vat: true );
Get the valley hours
Get the top N valley hours for a period.
$valleyHours = (new EnergyZero())->getValleyHours( startDate: '2024-01-01', endDate: '2024-01-02', topN: 5, interval: Interval::HOUR, vat: true );
Testing
composer test
API Documentation
For developers who want to build their own client in another programming language, see API.md for:
- Complete API endpoint documentation
- Query parameters and response format
- Code examples in Python, JavaScript, and cURL
- Information about price availability times
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
baspa/energyzero-php-api 适用场景与选型建议
baspa/energyzero-php-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 08 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Baspa」 「energyzero-php-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 baspa/energyzero-php-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 baspa/energyzero-php-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 baspa/energyzero-php-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel package to generate arrays of available timezones to be used in lists.
PHP package to provide fluent syntax for the Buienradar API
y
Upload local files and folders to S3 from an Artisan command
A runtime smoke-sweep that asserts every Filament page mounts and authorizes, enforceable in CI.
Widget to show the Dutch forecast in a Filament widget
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-26