add copilot instructions

This commit is contained in:
Julian Pawlowski 2025-04-23 17:46:12 +00:00
parent 6f66588fd0
commit 59cd48977b
5 changed files with 268 additions and 35 deletions

8
.copilot/config.json Normal file
View file

@ -0,0 +1,8 @@
{
"instructionFiles": [
{
"pattern": "**",
"path": ".github/copilot-instructions.md"
}
]
}

50
.github/copilot-instructions.md vendored Normal file
View file

@ -0,0 +1,50 @@
# Copilot Instructions
This repository contains a **custom component for Home Assistant**, intended to be distributed via the **HACS (Home Assistant Community Store)**.
## Development Guidelines
- Follow the **latest development practices** from both Home Assistant and HACS.
- This component is actively maintained and must be compatible with the **latest Home Assistant release**.
- When working with dates or time references, always use the **current real-world date** and assume it is fetched from the internet — never use outdated or static values from training data.
- Use **async functions**, **non-blocking I/O**, and **config flows** where applicable.
- Ensure the component is structured with proper files: `__init__.py`, `manifest.json`, `config_flow.py` (if needed), and versioning compatible with HACS.
## Coding Style
- Follow **PEP8** and Home Assistant's coding conventions.
- Use **type hints** and include **docstrings** for all public classes and methods.
- Prefer **f-strings** for string formatting over `%` or `.format()`.
## Linting and Code Quality
- Code must be clean and compliant with **Ruff**, which runs:
- **Locally** in the **devcontainer** (VS Code or Cursor)
- **Remotely** via **GitHub Actions**
- Follow these key Ruff rules:
- `F401`, `F841` No unused imports or variables
- `E402`, `E501` Imports at top, lines ≤88 chars
- `C901`, `PLR0912`, `PLR0915` Keep functions small and simple
- `PLR0911`, `RET504` Avoid redundant returns and `else` after `return`
- `B008` No mutable default arguments
- `T201` Use `_LOGGER`, not `print()`
- `SIM102` Use direct conditions (`if x`, not `if x == True`)
- Prefer a **single return statement** at the end of a function for clarity
(prepare the return value first, then return it once)
- Avoid returning early unless it clearly improves readability
- Use **Black** for formatting and **isort** for import sorting
- See `.ruff.toml` for detailed settings
## Additional Notes
- Avoid generating placeholder or mock data unless explicitly required.
- Dont assume hardcoded paths or specific local setups use **relative paths** and **configurable options**.
- YAML examples should be valid and properly formatted for use in Home Assistant configs.
> ✅ Tip for Copilot: Generate clean, modular, and lint-compliant code from the start to minimize review and CI errors.
## Tests
This project does **not currently include automated tests**. Simplicity and fast iteration are prioritized over test coverage at this stage.
> ⚠️ If you generate tests, keep them minimal and **do not introduce testing frameworks or infrastructure** that are not already present in the project.

196
README.md
View file

@ -1,46 +1,174 @@
# Notice
# Tibber Price Information & Ratings
The component and platforms in this repository are not meant to be used by a
user, but as a "blueprint" that custom component developers can build
upon, to make more awesome stuff.
[![GitHub Release][releases-shield]][releases]
[![GitHub Activity][commits-shield]][commits]
[![License][license-shield]](LICENSE)
HAVE FUN! 😎
[![hacs][hacsbadge]][hacs]
[![Project Maintenance][maintenance-shield]][user_profile]
[![BuyMeCoffee][buymecoffeebadge]][buymecoffee]
## Why?
A Home Assistant integration that provides advanced price information and ratings from Tibber. This integration allows you to monitor electricity prices, price levels, and rating information to help you optimize your energy consumption and save money.
This is simple, by having custom_components look (README + structure) the same
it is easier for developers to help each other and for users to start using them.
![Tibber Price Information & Ratings][exampleimg]
If you are a developer and you want to add things to this "blueprint" that you think more
developers will have use for, please open a PR to add it :)
## Features
## What?
- **Current and Next Hour Prices**: Get real-time price data in both EUR and cents/kWh
- **Price Level Indicators**: Know when you're in a low, normal, or high price period
- **Statistical Sensors**: Track lowest, highest, and average prices for the day
- **Price Ratings**: Hourly, daily, and monthly ratings to understand how current prices compare to historical data
- **Smart Indicators**: Binary sensors to detect peak hours and best price hours for automations
- **Diagnostic Sensors**: Monitor data freshness and availability
This repository contains multiple files, here is a overview:
## Installation
File | Purpose | Documentation
-- | -- | --
`.devcontainer.json` | Used for development/testing with Visual Studio Code. | [Documentation](https://code.visualstudio.com/docs/remote/containers)
`.github/ISSUE_TEMPLATE/*.yml` | Templates for the issue tracker | [Documentation](https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository)
`custom_components/tibber_prices/*` | Integration files, this is where everything happens. | [Documentation](https://developers.home-assistant.io/docs/creating_component_index)
`CONTRIBUTING.md` | Guidelines on how to contribute. | [Documentation](https://help.github.com/en/github/building-a-strong-community/setting-guidelines-for-repository-contributors)
`LICENSE` | The license file for the project. | [Documentation](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/licensing-a-repository)
`README.md` | The file you are reading now, should contain info about the integration, installation and configuration instructions. | [Documentation](https://help.github.com/en/github/writing-on-github/basic-writing-and-formatting-syntax)
`requirements.txt` | Python packages used for development/lint/testing this integration. | [Documentation](https://pip.pypa.io/en/stable/user_guide/#requirements-files)
### HACS Installation (Recommended)
## How?
1. Ensure [HACS](https://hacs.xyz/) is installed in your Home Assistant instance
2. Go to HACS > Integrations > Click the three dots in the top right > Custom repositories
3. Add this repository URL: `https://github.com/jpawlowski/hass.tibber_prices`
4. Click "Add"
5. Search for "Tibber Price Information & Ratings" in the Integrations tab
6. Click "Install"
7. Restart Home Assistant
1. Create a new repository in GitHub, using this repository as a template by clicking the "Use this template" button in the GitHub UI.
1. Open your new repository in Visual Studio Code devcontainer (Preferably with the "`Dev Containers: Clone Repository in Named Container Volume...`" option).
1. Rename all instances of the `integration_blueprint` to `custom_components/<your_integration_domain>` (e.g. `custom_components/awesome_integration`).
1. Rename all instances of the `Integration Blueprint` to `<Your Integration Name>` (e.g. `Awesome Integration`).
1. Run the `scripts/develop` to start HA and test out your new integration.
### Manual Installation
## Next steps
1. Copy the `custom_components/tibber_prices` directory from this repository into your Home Assistant's `custom_components` directory
2. Restart Home Assistant
These are some next steps you may want to look into:
- Add tests to your integration, [`pytest-homeassistant-custom-component`](https://github.com/MatthewFlamm/pytest-homeassistant-custom-component) can help you get started.
- Add brand images (logo/icon) to https://github.com/home-assistant/brands.
- Create your first release.
- Share your integration on the [Home Assistant Forum](https://community.home-assistant.io/).
- Submit your integration to [HACS](https://hacs.xyz/docs/publish/start).
## Configuration
### Requirements
- A Tibber account with an active subscription
- A Tibber API access token (obtain from [developer.tibber.com](https://developer.tibber.com/settings/access-token))
### Setup Process
1. Go to **Settings** > **Devices & Services** in your Home Assistant UI
2. Click the **+ ADD INTEGRATION** button in the bottom right
3. Search for "Tibber Price Information & Ratings"
4. Enter your Tibber API access token when prompted
5. Click "Submit"
## Available Entities
### Price Sensors
| Entity | Description | Unit | Default Enabled |
|--------|-------------|------|----------------|
| Current Electricity Price | The current hourly price | ct/kWh | Yes |
| Current Electricity Price (EUR) | The current hourly price | € | No |
| Next Hour Electricity Price | The price for the upcoming hour | ct/kWh | Yes |
| Next Hour Electricity Price (EUR) | The price for the upcoming hour | € | No |
| Current Price Level | Tibber's classification of the price (VERY_CHEAP, CHEAP, NORMAL, EXPENSIVE, VERY_EXPENSIVE) | - | Yes |
### Statistical Sensors
| Entity | Description | Unit | Default Enabled |
|--------|-------------|------|----------------|
| Today's Lowest Price | The lowest price for the current day | ct/kWh | Yes |
| Today's Lowest Price (EUR) | The lowest price for the current day | € | No |
| Today's Highest Price | The highest price for the current day | ct/kWh | Yes |
| Today's Highest Price (EUR) | The highest price for the current day | € | No |
| Today's Average Price | The average price for the current day | ct/kWh | Yes |
| Today's Average Price (EUR) | The average price for the current day | € | No |
### Rating Sensors
| Entity | Description | Unit | Default Enabled |
|--------|-------------|------|----------------|
| Hourly Price Rating | How the current hour's price compares to historical data | % | Yes |
| Daily Price Rating | How today's prices compare to historical data | % | Yes |
| Monthly Price Rating | How this month's prices compare to historical data | % | Yes |
### Binary Sensors
| Entity | Description | Default Enabled |
|--------|-------------|----------------|
| Peak Hour | Whether the current hour is in the top 20% of prices for the day | Yes |
| Best Price Hour | Whether the current hour is in the bottom 20% of prices for the day | Yes |
| Tibber API Connection | Shows connection status to the Tibber API | Yes |
### Diagnostic Sensors
| Entity | Description | Default Enabled |
|--------|-------------|----------------|
| Last Data Update | Timestamp of the most recent data update | Yes |
| Tomorrow's Data Status | Indicates if tomorrow's price data is available (Yes/No/Partial) | Yes |
## Automation Examples
### Run Appliances During Cheap Hours
```yaml
automation:
- alias: "Run Dishwasher During Cheap Hours"
trigger:
- platform: state
entity_id: binary_sensor.tibber_best_price_hour
to: "on"
condition:
- condition: time
after: "21:00:00"
before: "06:00:00"
action:
- service: switch.turn_on
target:
entity_id: switch.dishwasher
```
### Notify on Extremely High Prices
```yaml
automation:
- alias: "Notify on Very Expensive Electricity"
trigger:
- platform: state
entity_id: sensor.tibber_current_price_level
to: "VERY_EXPENSIVE"
action:
- service: notify.mobile_app
data:
title: "⚠️ High Electricity Prices"
message: "Current electricity price is in the VERY EXPENSIVE range. Consider reducing consumption."
```
## Troubleshooting
### No data appearing
1. Check your API token is valid at [developer.tibber.com](https://developer.tibber.com/settings/access-token)
2. Verify you have an active Tibber subscription
3. Check the Home Assistant logs for detailed error messages
4. Restart the integration by going to Configuration > Integrations > Tibber Price Information & Ratings > Options
### Missing tomorrow's price data
- Tomorrow's price data usually becomes available between 13:00 and 15:00 each day
- If data is still unavailable after this time, check the Tibber app to see if data is available there
## Contributing
If you want to contribute to this project, please read the [Contributing Guidelines](CONTRIBUTING.md).
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
---
[releases]: https://github.com/jpawlowski/hass.tibber_prices/releases
[releases-shield]: https://img.shields.io/github/release/jpawlowski/hass.tibber_prices.svg?style=for-the-badge
[commits-shield]: https://img.shields.io/github/commit-activity/y/jpawlowski/hass.tibber_prices.svg?style=for-the-badge
[commits]: https://github.com/jpawlowski/hass.tibber_prices/commits/main
[hacs]: https://github.com/hacs/integration
[hacsbadge]: https://img.shields.io/badge/HACS-Custom-orange.svg?style=for-the-badge
[exampleimg]: https://raw.githubusercontent.com/jpawlowski/hass.tibber_prices/main/images/example.png
[license-shield]: https://img.shields.io/github/license/jpawlowski/hass.tibber_prices.svg?style=for-the-badge
[maintenance-shield]: https://img.shields.io/badge/maintainer-%40jpawlowski-blue.svg?style=for-the-badge
[user_profile]: https://github.com/jpawlowski
[buymecoffee]: https://www.buymeacoffee.com/jpawlowski
[buymecoffeebadge]: https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow.svg?style=for-the-badge

View file

@ -0,0 +1,42 @@
"""Diagnostics support for tibber_prices."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from homeassistant.components.diagnostics import async_redact_data
from .const import DOMAIN
if TYPE_CHECKING:
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
TO_REDACT = {"access_token"}
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
coordinator = hass.data[DOMAIN][entry.entry_id].coordinator
return {
"entry": async_redact_data(entry.as_dict(), TO_REDACT),
"coordinator_data": coordinator.data,
"last_update_success": coordinator.last_update_success,
"update_timestamps": {
"price": coordinator.last_price_update.isoformat()
if coordinator.last_price_update
else None,
"hourly_rating": coordinator.last_rating_update_hourly.isoformat()
if coordinator.last_rating_update_hourly
else None,
"daily_rating": coordinator.last_rating_update_daily.isoformat()
if coordinator.last_rating_update_daily
else None,
"monthly_rating": coordinator.last_rating_update_monthly.isoformat()
if coordinator.last_rating_update_monthly
else None,
},
}

View file

@ -1,5 +1,10 @@
{
"name": "Tibber Price Information & Ratings",
"homeassistant": "2025.4.2",
"hacs": "2.0.1"
"hacs": "2.0.1",
"render_readme": true,
"domains": [
"sensor",
"binary_sensor"
]
}