Skip to content

Commit

Permalink
README, images, adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Mihaylov committed Dec 24, 2023
1 parent de846b0 commit 43ca5bf
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 24 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[![](https://img.shields.io/github/release/avataar/bg_electricity_regulated_pricing/all.svg?style=for-the-badge)](https://github.com/avataar/bg_electricity_regulated_pricing/releases)
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg?style=for-the-badge)](https://github.com/hacs/integration)
[![](https://img.shields.io/github/license/avataar/bg_electricity_regulated_pricing?style=for-the-badge)](LICENSE)
[![](https://img.shields.io/github/workflow/status/avataar/bg_electricity_regulated_pricing/Python%20package?style=for-the-badge)](https://github.com/avataar/bg_electricity_regulated_pricing/actions)

# Bulgarian Electricity Regulated Pricing for Home Assistant

Custom integration for [Home Assistant](https://www.home-assistant.io) that provides the price of electricity on the regulated market for domestic customers.

The integration provides two sensors that adjust according to the time of day and the configuration:

* Current price in BGN per kWh
* Current tariff (day or night)

All three global providers, Electrohold, EVN and ENERGO-PRO are supported.

The prices are defined statically as they change only about once a year. The official source for the current prices is section 6 from [Resolution C-14/30.06.2023 of the Bulgarian Energy and Water Regulatory Commission](https://www.dker.bg/uploads/reshenia/2023/res_c_14_23.pdf).

## Install

At present the only way to install the integration is to copy the [custom_components/bg_electricity_regulated_pricing]() folder to your Home Assistant's custom_components folder just like with any other manually installed custom integration.

In the future, this integration may be added to HACS.

## Configuration

Search for the integration by name (Bulgarian Electricity Regulated Pricing). To configure it for most users, it will suffice to choose the provider.

| ![](images/configure-bg.png) | ![](images/configure-en.png) |
|------------------------------|------------------------------|

### Advanced options

* Custom provider / Доставчик Потребителска цена - choose this to define custom prices for day and night rate below.
* Clock offset / Избързване/изоставане на часовника - this is the offset of the actual clock used to switch your tariff. For example, if your clock is 30 minutes ahead set it to 30; if it's 15 minutes behind set it to -15.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)

from .const import DOMAIN, PROVIDERS, CONF_PROVIDER, CONF_TARIFF_TYPE, TARIFF_TYPES, \
CONF_NIGHT_OFFSET, CONF_CUSTOM_DAY_PRICE, CONF_CUSTOM_NIGHT_PRICE, \
CONF_CLOCK_OFFSET, CONF_CUSTOM_DAY_PRICE, CONF_CUSTOM_NIGHT_PRICE, \
BGN_PER_KILOWATT_HOUR

OPTIONS_SCHEMA = vol.Schema(
Expand All @@ -31,7 +31,7 @@
translation_key=CONF_TARIFF_TYPE
)
),
vol.Required(CONF_NIGHT_OFFSET, default=0): selector.NumberSelector(
vol.Required(CONF_CLOCK_OFFSET, default=0): selector.NumberSelector(
selector.NumberSelectorConfig(
min=-720, max=720, mode=selector.NumberSelectorMode.BOX,
unit_of_measurement=UnitOfTime.MINUTES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
CONF_TARIFF_TYPE = "tariff_type"
TARIFF_TYPES = ["dual", "single"]

CONF_NIGHT_OFFSET = "night_offset"
CONF_CLOCK_OFFSET = "clock_offset"

CONF_CUSTOM_DAY_PRICE = "custom_day_price"

Expand Down
12 changes: 6 additions & 6 deletions custom_components/bg_electricity_regulated_pricing/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


from .const import CONF_TARIFF_TYPE, CONF_PROVIDER, CONF_CUSTOM_DAY_PRICE, \
CONF_CUSTOM_NIGHT_PRICE, PROVIDER_PRICES, CONF_NIGHT_OFFSET, \
CONF_CUSTOM_NIGHT_PRICE, PROVIDER_PRICES, CONF_CLOCK_OFFSET, \
BGN_PER_KILOWATT_HOUR, VAT_RATE, DOMAIN


Expand All @@ -25,7 +25,7 @@ async def async_setup_entry(
unique_id = config_entry.entry_id

tariff_type = config_entry.options[CONF_TARIFF_TYPE]
night_offset = config_entry.options[CONF_NIGHT_OFFSET]
clock_offset = config_entry.options[CONF_CLOCK_OFFSET]
provider = config_entry.options[CONF_PROVIDER]
if provider == "custom":
price_day = config_entry.options[CONF_CUSTOM_DAY_PRICE]
Expand All @@ -36,7 +36,7 @@ async def async_setup_entry(
price_night = (PROVIDER_PRICES[provider]["night"]
+ PROVIDER_PRICES[provider]["fees"]) * (1 + VAT_RATE)

price_provider = BgElectricityRegulatedPricingProvider(tariff_type, night_offset,
price_provider = BgElectricityRegulatedPricingProvider(tariff_type, clock_offset,
price_day, price_night)

desc_price = SensorEntityDescription(
Expand Down Expand Up @@ -119,9 +119,9 @@ def update(self):
class BgElectricityRegulatedPricingProvider:
"""Pricing provider aware of current tariff and price."""

def __init__(self, tariff_type, night_offset, price_day, price_night):
def __init__(self, tariff_type, clock_offset, price_day, price_night):
self._tariff_type = tariff_type
self._night_offset = night_offset
self._clock_offset = clock_offset
self._price_day = price_day
self._price_night = price_night

Expand All @@ -132,7 +132,7 @@ def tariff(self):
hour_minutes = (
(utc.hour + 2) % 24 * 60
+ utc.minute
+ self._night_offset
+ self._clock_offset
) % 1440
if self._tariff_type == "dual":
if hour_minutes >= 22 * 60 or hour_minutes < 6 * 60:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Име",
"provider": "Доставчик",
"tariff_type": "Тарифност",
"night_offset": "Нощна тарифа отместване",
"clock_offset": "Избързване/изоставане на часовника",
"custom_day_price": "Потребителска цена дневна тарифа",
"custom_night_price": "Потребителска цена нощна тарифа"
}
Expand All @@ -19,7 +19,7 @@
"data": {
"provider": "Доставчик",
"tariff_type": "Тарифност",
"night_offset": "Нощна тарифа отместване",
"clock_offset": "Избързване/изоставане на часовника",
"custom_day_price": "Потребителска цена дневна тарифа",
"custom_night_price": "Потребителска цена нощна тарифа"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Name",
"provider": "Provider",
"tariff_type": "Tariff Type",
"night_offset": "Night Tariff Offset",
"clock_offset": "Clock Offset",
"custom_day_price": "Custom Provider Day Price",
"custom_night_price": "Custom Provider Night Price"
}
Expand All @@ -19,7 +19,7 @@
"data": {
"provider": "Provider",
"tariff_type": "Tariff Type",
"night_offset": "Night Tariff Offset",
"clock_offset": "Clock Offset",
"custom_day_price": "Custom Provider Day Price",
"custom_night_price": "Custom Provider Night Price"
}
Expand Down
Binary file added images/configure-bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/configure-en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def test_config_flow(
"""Test the config flow."""
provider = "electrohold"
tariff_type = "dual"
night_offset = 0
clock_offset = 0
custom_day_price = 0
custom_night_price = 0

Expand All @@ -32,7 +32,7 @@ async def test_config_flow(
"name": "My Provider",
"provider": provider,
"tariff_type": tariff_type,
"night_offset": night_offset,
"clock_offset": clock_offset,
"custom_day_price": custom_day_price,
"custom_night_price": custom_night_price
},
Expand All @@ -46,7 +46,7 @@ async def test_config_flow(
"name": "My Provider",
"provider": provider,
"tariff_type": tariff_type,
"night_offset": night_offset,
"clock_offset": clock_offset,
"custom_day_price": custom_day_price,
"custom_night_price": custom_night_price
}
Expand All @@ -58,7 +58,7 @@ async def test_config_flow(
"name": "My Provider",
"provider": provider,
"tariff_type": tariff_type,
"night_offset": night_offset,
"clock_offset": clock_offset,
"custom_day_price": custom_day_price,
"custom_night_price": custom_night_price
}
Expand All @@ -80,7 +80,7 @@ async def test_options(hass: HomeAssistant) -> None:
"""Test reconfiguring."""
provider = "electrohold"
tariff_type = "dual"
night_offset = 0
clock_offset = 0
custom_day_price = 0
custom_night_price = 0

Expand All @@ -92,7 +92,7 @@ async def test_options(hass: HomeAssistant) -> None:
"name": "My Provider",
"provider": provider,
"tariff_type": tariff_type,
"night_offset": night_offset,
"clock_offset": clock_offset,
"custom_day_price": custom_day_price,
"custom_night_price": custom_night_price
},
Expand All @@ -113,7 +113,7 @@ async def test_options(hass: HomeAssistant) -> None:
user_input={
"provider": "evn",
"tariff_type": tariff_type,
"night_offset": night_offset,
"clock_offset": clock_offset,
"custom_day_price": custom_day_price,
"custom_night_price": custom_night_price
},
Expand All @@ -123,7 +123,7 @@ async def test_options(hass: HomeAssistant) -> None:
"name": "My Provider",
"provider": "evn",
"tariff_type": tariff_type,
"night_offset": night_offset,
"clock_offset": clock_offset,
"custom_day_price": custom_day_price,
"custom_night_price": custom_night_price
}
Expand All @@ -132,7 +132,7 @@ async def test_options(hass: HomeAssistant) -> None:
"name": "My Provider",
"provider": "evn",
"tariff_type": tariff_type,
"night_offset": night_offset,
"clock_offset": clock_offset,
"custom_day_price": custom_day_price,
"custom_night_price": custom_night_price
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def test_setup_and_remove_config_entry(hass: HomeAssistant,


async def do_setup_test(hass: HomeAssistant, provider: str, tariff_type: str,
expected_tariff: str, night_offset=0):
expected_tariff: str, clock_offset=0):
registry = er.async_get(hass)
custom_day_price = 0.25
custom_night_price = 0.15
Expand All @@ -102,7 +102,7 @@ async def do_setup_test(hass: HomeAssistant, provider: str, tariff_type: str,
"name": "My Provider",
"provider": provider,
"tariff_type": tariff_type,
"night_offset": night_offset,
"clock_offset": clock_offset,
"custom_day_price": custom_day_price,
"custom_night_price": custom_night_price
},
Expand Down

0 comments on commit 43ca5bf

Please sign in to comment.