Skip to content

Commit f216c19

Browse files
committed
Merge branch 'develop' into beta
2 parents 40c3eab + 5a1441a commit f216c19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+673
-184
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# 0003 - Move to calendar entities for Octoplus events
2+
3+
## Status
4+
Accepted
5+
6+
## Context
7+
8+
Currently binary sensors are provided to indicate when a saving or free electricity session is active for the current account. This also provides attributes for current and next start/end times.
9+
10+
Since the introduction of the saving session binary sensor, calendar entities have received more love within Home Assistant and become the preferred way of showing events. These are better supports in UI automations as you can offset calendar events easily (e.g. reminder 10 minutes before) without having to do template gymnastics. The calendar view of Home Assistant is also used by house hold members who are not as involved as other members in things like wall tablets. A few users move the data from the sensor data into a local calendar to produce this.
11+
12+
This request has been made on a few occasions, below are some samples
13+
14+
* https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/561#issuecomment-1826830172
15+
* https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/1397
16+
17+
## Decision
18+
19+
With more people coming on board to Home Assistant who don't necessarily come from a technological background, the automation UI becoming the preferred way of creating automations and the calendar entity getting more love, it has been decided to convert the saving session and free electricity sessions into calendar entities.
20+
21+
The old sensors will continue to be available until **May 2026** when they will be removed, to ease with the transition.
22+
23+
## Consequences
24+
25+
### Positive
26+
- Automations around sessions will be easier via the calendar trigger
27+
- Past and present sessions will be easily viewable in the Home Assistant Calendar view
28+
- Standard approach for people used to calendar entities.
29+
30+
### Negative
31+
- Users using effected entities will need to update all references
32+
- Some short-term disruption may occur as users adapt to the new entity behaviour.
33+
- Event duration (e.g. 60 minutes) will require templating still

_docs/entities/octoplus.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Determines the current Octoplus points balance. This sensor will only be availab
1818

1919
## Saving Sessions
2020

21+
!!! warning
22+
23+
This sensor has been deprecated in favour of [Saving Session Calendar](#saving-sessions-calendar) and will be removed around **May 2026**
24+
2125
`binary_sensor.octopus_energy_{{ACCOUNT_ID}}_octoplus_saving_sessions`
2226

2327
Binary sensor to indicate if a saving session that the account has joined is active.
@@ -35,6 +39,20 @@ Binary sensor to indicate if a saving session that the account has joined is act
3539

3640
You can use the [data_last_retrieved sensor](./diagnostics.md#saving-sessions-data-last-retrieved) to determine when the underlying data was last retrieved from the OE servers.
3741

42+
## Saving Sessions Calendar
43+
44+
`calendar.octopus_energy_{{ACCOUNT_ID}}_octoplus_saving_sessions`
45+
46+
Calendar sensor to record saving sessions. Will be `on` when a saving session that the account has joined is active. Standard calendar attributes will indicate the current/next saving session.
47+
48+
!!! info
49+
50+
You can use the [data_last_retrieved sensor](./diagnostics.md#saving-sessions-data-last-retrieved) to determine when the underlying data was last retrieved from the OE servers.
51+
52+
!!! note
53+
54+
The events are supplied by OE API and does not store past events indefinitely. Past events could be removed without notice.
55+
3856
## Saving Session Events
3957

4058
`event.octopus_energy_{{ACCOUNT_ID}}_octoplus_saving_session_events`
@@ -121,6 +139,10 @@ Each item within `baselines` consists of the following attributes
121139

122140
## Free Electricity Sessions
123141

142+
!!! warning
143+
144+
This sensor has been deprecated in favour of [Free Electricity Sessions Calendar](#free-electricity-sessions-calendar) and will be removed around **May 2026**
145+
124146
`binary_sensor.octopus_energy_{{ACCOUNT_ID}}_octoplus_free_electricity_session`
125147

126148
Binary sensor to indicate if a free electricity session is active.
@@ -140,6 +162,22 @@ Binary sensor to indicate if a free electricity session is active.
140162
| `next_event_end` | `datetime` | The datetime the next free electricity session will end |
141163
| `next_event_duration_in_minutes` | `float` | The duration in minutes of the next free electricity session |
142164

165+
!!! info
166+
167+
You can use the [data_last_retrieved sensor](./diagnostics.md#free-electricity-sessions-data-last-retrieved) to determine when the underlying data was last retrieved from the OE servers.
168+
169+
## Free Electricity Sessions Calendar
170+
171+
`calendar.octopus_energy_{{ACCOUNT_ID}}_octoplus_free_electricity_session`
172+
173+
Calendar sensor to record free electricity sessions. Will be `on` when a free electricity session is active. Standard calendar attributes will indicate the current/next saving session.
174+
175+
!!! note
176+
This will only be available if you have enrolled into Octoplus. Once enrolled, reload the integration to gain access to this sensor. This is only applicable if you have signed up to [free electricity sessions](https://octopus.energy/free-electricity/). This sensor uses public information supplied by https://github.com/BottlecapDave/OctopusEnergyApi.
177+
178+
!!! note
179+
This is [disabled by default](../faq.md#there-are-entities-that-are-disabled-why-are-they-disabled-and-how-do-i-enable-them).
180+
143181
!!! info
144182

145183
You can use the [data_last_retrieved sensor](./diagnostics.md#free-electricity-sessions-data-last-retrieved) to determine when the underlying data was last retrieved from the OE servers.

custom_components/octopus_energy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
REPAIR_UNKNOWN_INTELLIGENT_PROVIDER
8585
)
8686

87-
ACCOUNT_PLATFORMS = ["sensor", "binary_sensor", "number", "switch", "text", "time", "event", "select", "climate", "water_heater"]
87+
ACCOUNT_PLATFORMS = ["sensor", "binary_sensor", "number", "switch", "text", "time", "event", "select", "climate", "water_heater", "calendar"]
8888
TARGET_RATE_PLATFORMS = ["binary_sensor"]
8989
COST_TRACKER_PLATFORMS = ["sensor"]
9090
TARIFF_COMPARISON_PLATFORMS = ["sensor"]

custom_components/octopus_energy/binary_sensor.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
DATA_ACCOUNT,
4747
INTELLIGENT_DEVICE_KIND_ELECTRIC_VEHICLE_CHARGERS,
4848
INTELLIGENT_DEVICE_KIND_ELECTRIC_VEHICLES,
49+
REPAIR_FREE_ELECTRICITY_SESSION_BINARY_SENSOR_DEPRECATED,
50+
REPAIR_SAVING_SESSION_BINARY_SENSOR_DEPRECATED,
4951
REPAIR_TARGET_RATE_REMOVAL_PROPOSAL
5052
)
5153

@@ -138,8 +140,27 @@ async def async_setup_main_sensors(hass, entry, async_add_entities):
138140
OctopusEnergyGreennessForecastHighlighted(hass, greenness_forecast_coordinator, account_id)
139141
]
140142

143+
ir.async_create_issue(
144+
hass,
145+
DOMAIN,
146+
REPAIR_SAVING_SESSION_BINARY_SENSOR_DEPRECATED,
147+
is_fixable=False,
148+
severity=ir.IssueSeverity.WARNING,
149+
learn_more_url="https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/architecture_decision_records/0003_move_to_calendar_entities_for_octoplus_events",
150+
translation_key="saving_session_binary_sensor_deprecated",
151+
)
152+
141153
if octoplus_enrolled:
142-
entities.append(OctopusEnergyFreeElectricitySessions(hass, free_electricity_session_coordinator, account_id))
154+
entities.append(OctopusEnergyFreeElectricitySessions(hass, free_electricity_session_coordinator, account_id))
155+
ir.async_create_issue(
156+
hass,
157+
DOMAIN,
158+
REPAIR_FREE_ELECTRICITY_SESSION_BINARY_SENSOR_DEPRECATED,
159+
is_fixable=False,
160+
severity=ir.IssueSeverity.WARNING,
161+
learn_more_url="https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/architecture_decision_records/0003_move_to_calendar_entities_for_octoplus_events",
162+
translation_key="free_electricity_session_binary_sensor_deprecated",
163+
)
143164

144165
if len(account_info["electricity_meter_points"]) > 0:
145166

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import logging
2+
3+
from homeassistant.util.dt import (utcnow)
4+
5+
6+
from .const import (
7+
CONFIG_KIND,
8+
CONFIG_KIND_ACCOUNT,
9+
CONFIG_ACCOUNT_ID,
10+
DATA_FREE_ELECTRICITY_SESSIONS_COORDINATOR,
11+
DOMAIN,
12+
13+
DATA_SAVING_SESSIONS_COORDINATOR,
14+
DATA_ACCOUNT
15+
)
16+
17+
from .octoplus.free_electricity_sessions_calendar import OctopusEnergyFreeElectricitySessionsCalendar
18+
from .octoplus.saving_sessions_calendar import OctopusEnergySavingSessionsCalendar
19+
20+
_LOGGER = logging.getLogger(__name__)
21+
22+
async def async_setup_entry(hass, entry, async_add_entities):
23+
"""Setup sensors based on our entry"""
24+
25+
if entry.data[CONFIG_KIND] == CONFIG_KIND_ACCOUNT:
26+
await async_setup_main_sensors(hass, entry, async_add_entities)
27+
28+
return True
29+
30+
async def async_setup_main_sensors(hass, entry, async_add_entities):
31+
_LOGGER.debug('Setting up main sensors')
32+
config = dict(entry.data)
33+
34+
account_id = config[CONFIG_ACCOUNT_ID]
35+
account_result = hass.data[DOMAIN][account_id][DATA_ACCOUNT]
36+
account_info = account_result.account if account_result is not None else None
37+
octoplus_enrolled = account_info is not None and account_info["octoplus_enrolled"] == True
38+
39+
saving_session_coordinator = hass.data[DOMAIN][account_id][DATA_SAVING_SESSIONS_COORDINATOR]
40+
free_electricity_session_coordinator = hass.data[DOMAIN][account_id][DATA_FREE_ELECTRICITY_SESSIONS_COORDINATOR]
41+
42+
now = utcnow()
43+
entities = [
44+
OctopusEnergySavingSessionsCalendar(hass, saving_session_coordinator, account_id),
45+
]
46+
47+
if octoplus_enrolled:
48+
entities.append(OctopusEnergyFreeElectricitySessionsCalendar(hass, free_electricity_session_coordinator, account_id))
49+
50+
if len(entities) > 0:
51+
async_add_entities(entities)

custom_components/octopus_energy/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@
214214
REPAIR_INTELLIGENT_DEVICE_ADDED = "intelligent_device_added_{}"
215215
REPAIR_INTELLIGENT_DEVICE_REMOVED = "intelligent_device_removed_{}"
216216
REPAIR_TARIFF_RATES_EMPTY = "tariff_rates_empty_{}_{}"
217+
REPAIR_SAVING_SESSION_BINARY_SENSOR_DEPRECATED = "saving_session_binary_sensor_deprecated"
218+
REPAIR_FREE_ELECTRICITY_SESSION_BINARY_SENSOR_DEPRECATED = "saving_session_binary_sensor_deprecated"
217219

218220
# During BST, two records are returned before the rest of the data is available
219221
MINIMUM_CONSUMPTION_DATA_LENGTH = 3

custom_components/octopus_energy/diagnostics_entities/current_consumption_data_last_retrieved.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

custom_components/octopus_energy/diagnostics_entities/current_consumption_home_pro_data_last_retrieved.py

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from .base import OctopusEnergyBaseDataLastRetrieved
2+
from ..electricity.base import OctopusEnergyElectricitySensor
3+
4+
class OctopusEnergyElectricityCurrentConsumptionDataLastRetrieved(OctopusEnergyElectricitySensor, OctopusEnergyBaseDataLastRetrieved):
5+
"""Sensor for displaying the last time the current consumption data was last retrieved."""
6+
7+
def __init__(self, hass, coordinator, meter, point):
8+
"""Init sensor."""
9+
self._mpan = point["mpan"]
10+
self._serial_number = meter["serial_number"]
11+
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)
12+
OctopusEnergyBaseDataLastRetrieved.__init__(self, hass, coordinator)
13+
14+
@property
15+
def unique_id(self):
16+
"""The id of the sensor."""
17+
return f"octopus_energy_electricity_{self._serial_number}_{self._mpan}_current_consumption_data_last_retrieved"
18+
19+
@property
20+
def name(self):
21+
"""Name of the sensor."""
22+
return f"Current Consumption Data Last Retrieved Electricity ({self._serial_number}/{self._mpan})"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from .base import OctopusEnergyBaseDataLastRetrieved
2+
from ..electricity.base import OctopusEnergyElectricitySensor
3+
4+
class OctopusEnergyElectricityCurrentConsumptionHomeProDataLastRetrieved(OctopusEnergyElectricitySensor, OctopusEnergyBaseDataLastRetrieved):
5+
"""Sensor for displaying the last time the current consumption home pro data was last retrieved."""
6+
7+
def __init__(self, hass, coordinator, meter, point):
8+
"""Init sensor."""
9+
self._mpan = point["mpan"]
10+
self._serial_number = meter["serial_number"]
11+
OctopusEnergyElectricitySensor.__init__(self, hass, meter, point)
12+
OctopusEnergyBaseDataLastRetrieved.__init__(self, hass, coordinator)
13+
14+
@property
15+
def unique_id(self):
16+
"""The id of the sensor."""
17+
return f"octopus_energy_electricity_{self._serial_number}_{self._mpan}_home_pro_current_consumption_data_last_retrieved"
18+
19+
@property
20+
def name(self):
21+
"""Name of the sensor."""
22+
return f"Home Pro Current Consumption Data Last Retrieved Electricity ({self._serial_number}/{self._mpan})"

0 commit comments

Comments
 (0)