Skip to content

Commit

Permalink
fix: Fixed off peak sensor turning on during extended intelligent off…
Browse files Browse the repository at this point in the history
… peak periods
  • Loading branch information
BottlecapDave committed Jan 2, 2024
1 parent 0ecd453 commit 9b36f07
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions _docs/entities/electricity.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ Each rate item has the following attributes

This is `on` when you're within your tariff's off peak period, and `off` at all other times. This is [disabled by default](../faq.md#there-are-entities-that-are-disabled-why-are-they-disabled-and-how-do-i-enable-them). This will only be work if you're on a tariff with an off peak period.

!!! warning

For intelligent tariffs, this sensor will only turn on during the standard off peak period. If you are wanting to know when extended off peak rates are available, you'll want to use the [is dispatching](./intelligent.md#is-dispatching) sensor.

## Smart Meter Entities

If your account information doesn't determine you have a smart meter, then you will have the following entities in a disabled state. If you enable these entities, they might not work correctly in this scenario.
Expand Down
12 changes: 9 additions & 3 deletions _docs/entities/intelligent.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ If you are on the [intelligent tariff](https://octopus.energy/smart/intelligent-

`binary_sensor.octopus_energy_{{ACCOUNT_ID}}_intelligent_dispatching`

This sensor is used to determine if you're currently in a planned dispatch period (i.e. "smart-charge" determined by Octopus Energy) or are within the off peak period.
This sensor is used to determine if you're currently in a planned dispatch period (i.e. "smart-charge" determined by Octopus Energy) or are within the standard off peak period.

!!! warning

If you are using this to drive other automations for cheap rates (e.g. to fill batteries), you should perform additional checks to make sure your vehicle is actually charging. If it isn't, this sensor could be incorrectly on if during a dispatch outside of the standard off peak period and you will therefore not receive the off peak rate.

If you are wanting to know when you are within a guaranteed off peak period, you should use the [off peak](./electricity.md#off-peak) sensor.

!!! info

`planned_dispatches` is not supported for the following intelligent providers
This sensor is only partially supported for the following intelligent providers

* OHME

`planned_dispatches` will therefore always return an empty collection and this entity will only turn on when within of the standard off peak period.
If you are supplied by one of the above providers, `planned_dispatches` will always return an empty collection and this entity will only turn on when within the standard off peak period.

| Attribute | Type | Description |
|-----------|------|-------------|
Expand Down
5 changes: 4 additions & 1 deletion custom_components/octopus_energy/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def is_off_peak(current: datetime, rates):

rate_information = get_current_rate_information(rates, current)

return off_peak_value is not None and rate_information is not None and value_inc_vat_to_pounds(off_peak_value) == rate_information["current_rate"]["value_inc_vat"]
return (off_peak_value is not None and
rate_information is not None and
rate_information["current_rate"]["is_intelligent_adjusted"] == False and
value_inc_vat_to_pounds(off_peak_value) == rate_information["current_rate"]["value_inc_vat"])

def private_rates_to_public_rates(rates: list):
if rates is None:
Expand Down
16 changes: 15 additions & 1 deletion tests/unit/utils/test_is_off_peak.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ async def test_when_off_peak_available_and_current_off_peak_then_true_returned()
rate_data = create_rate_data(period_from, period_to, [10, 10, 30, 30])

# Act
assert is_off_peak(current, rate_data) == True
assert is_off_peak(current, rate_data) == True

@pytest.mark.asyncio
async def test_when_off_peak_available_and_current_off_peak_and_intelligent_adjusted_then_false_returned():
# Arrange
period_from = datetime.strptime("2022-02-01T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z")
period_to = datetime.strptime("2022-02-01T02:00:00Z", "%Y-%m-%dT%H:%M:%S%z")
current = datetime.strptime("2022-02-01T00:00:01Z", "%Y-%m-%dT%H:%M:%S%z")

rate_data = create_rate_data(period_from, period_to, [10, 10, 30, 30])
for rate in rate_data:
rate["is_intelligent_adjusted"] = True

# Act
assert is_off_peak(current, rate_data) == False

0 comments on commit 9b36f07

Please sign in to comment.