Skip to content

Commit 6f83dfa

Browse files
feat(octopus): broaden saving/free session entity regex to match Power Down/Up rename
Octopus Energy integration v19.0.0 renamed the saving-session and free-electricity event entities to Power Down and Power Up (event.octopus_energy_ACCOUNT_ID_octoplus_power_down_events / ..._power_up_events). Both old and new entities remain registered until January 2027 (ADR-0004), and resolve_arg_re()'s regex matching against HA state keys is a one-off startup resolution, so broadening the 're:' alternation to match either name is enough - no runtime try-new-then-old logic is needed here, unlike the join service rename in point 3. Updates the octopus_saving_session/octopus_free_session regex in apps.yaml (default, coverage test fixture, and all 23 inverter templates that configure them), plus docs/energy-rates.md to mention the rename, the entity_registry_enabled_default=False gotcha, and the January 2027 cutoff. Part of #4548 (point 2). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent dabf8a7 commit 6f83dfa

28 files changed

Lines changed: 106 additions & 50 deletions

apps/predbat/config/apps.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,12 @@ pred_bat:
393393

394394
# Octopus saving session points to the saving session Sensor in the Octopus plugin, when enabled saving sessions will be at the assumed
395395
# Rate is read automatically from the add-in and converted to pence using the conversion rate below (default is 8)
396-
octopus_saving_session: 're:(event.octopus_energy([0-9a-z_]+|)_saving_session_event(s|))'
396+
octopus_saving_session: 're:(event.octopus_energy([0-9a-z_]+|)_(saving_session_events?|power_down_events))'
397397
octopus_saving_session_octopoints_per_penny: 8
398398

399399
# Octopus free session points to the free session Sensor in the Octopus plugin
400400
# Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work
401-
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)'
401+
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_(free_electricity_session_events|power_up_events))'
402402

403403
# Alternative scraper from Octopus web site if the above is not working
404404
# octopus_free_url: 'http://octopus.energy/free-electricity'

apps/predbat/tests/test_saving_session.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,3 +845,45 @@ def test_saving_session_default_rate(my_predbat):
845845
print(f"PASS: Default rate correctly injected for null octopoints: {expected_rate} p/kWh")
846846

847847
return failed
848+
849+
850+
def test_saving_session_entity_regex_power_rename(my_predbat):
851+
"""
852+
Test that the octopus_saving_session/octopus_free_session apps.yaml 're:' patterns
853+
match both the deprecated saving-session/free-electricity entity names and the
854+
replacement Power Down/Power Up entity names introduced by Octopus integration
855+
v19.0.0, and that each pattern does not cross-match the other event type.
856+
Covers GitHub issue #4548 point 2.
857+
"""
858+
print("Test octopus_saving_session/octopus_free_session entity regex Power Down/Up rename (issue #4548 point 2)")
859+
failed = False
860+
861+
saving_pattern = "re:(event.octopus_energy([0-9a-z_]+|)_(saving_session_events?|power_down_events))"
862+
free_pattern = "re:(event.octopus_energy_([0-9a-z_]+|)_octoplus_(free_electricity_session_events|power_up_events))"
863+
864+
cases = [
865+
# (arg, pattern, state_keys, expected_match, description)
866+
("octopus_saving_session", saving_pattern, ["event.octopus_energy_a4dd6c5ee_octoplus_saving_session_events"], "event.octopus_energy_a4dd6c5ee_octoplus_saving_session_events", "deprecated saving-session entity"),
867+
("octopus_saving_session", saving_pattern, ["event.octopus_energy_a4dd6c5ee_octoplus_power_down_events"], "event.octopus_energy_a4dd6c5ee_octoplus_power_down_events", "new Power Down entity"),
868+
("octopus_saving_session", saving_pattern, ["event.octopus_energy_a4dd6c5ee_octoplus_power_up_events"], None, "Power Up entity must not match the saving-session/Power Down pattern"),
869+
("octopus_free_session", free_pattern, ["event.octopus_energy_a4dd6c5ee_octoplus_free_electricity_session_events"], "event.octopus_energy_a4dd6c5ee_octoplus_free_electricity_session_events", "deprecated free-electricity entity"),
870+
("octopus_free_session", free_pattern, ["event.octopus_energy_a4dd6c5ee_octoplus_power_up_events"], "event.octopus_energy_a4dd6c5ee_octoplus_power_up_events", "new Power Up entity"),
871+
("octopus_free_session", free_pattern, ["event.octopus_energy_a4dd6c5ee_octoplus_power_down_events"], None, "Power Down entity must not match the free-session/Power Up pattern"),
872+
]
873+
874+
for arg, pattern, state_keys, expected, description in cases:
875+
matched, resolved = my_predbat.resolve_arg_re(arg, pattern, state_keys)
876+
if expected is None:
877+
if matched:
878+
print(f"ERROR: {description} - expected no match, got {resolved}")
879+
failed = True
880+
else:
881+
print(f"PASS: {description} correctly did not match")
882+
else:
883+
if not matched or resolved != expected:
884+
print(f"ERROR: {description} - expected {expected}, got matched={matched} resolved={resolved}")
885+
failed = True
886+
else:
887+
print(f"PASS: {description} resolved to {resolved}")
888+
889+
return failed

apps/predbat/unit_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
test_saving_session_join_service_fallback,
7474
test_saving_session_auto_join_toggle,
7575
test_saving_session_custom_entity_no_rewrite_match,
76+
test_saving_session_entity_regex_power_rename,
7677
)
7778
from tests.test_secrets import run_secrets_tests
7879
from tests.test_ge_cloud import test_ge_cloud
@@ -447,6 +448,7 @@ def main():
447448
("saving_session_join_service_fallback", test_saving_session_join_service_fallback, "Saving session join service fallback test (issue #4548 point 3)", False),
448449
("saving_session_auto_join_toggle", test_saving_session_auto_join_toggle, "Saving session auto-join toggle test (issue #4120)", False),
449450
("saving_session_custom_entity_no_rewrite_match", test_saving_session_custom_entity_no_rewrite_match, "Saving session custom entity no rewrite match test (issue #4573)", False),
451+
("saving_session_entity_regex_power_rename", test_saving_session_entity_regex_power_rename, "Saving/free session entity regex Power Down/Up rename test (issue #4548 point 2)", False),
450452
("alert_feed", test_alert_feed, "Alert feed tests", False),
451453
("fox_api", run_fox_api_tests, "Fox API tests", False),
452454
("deye_const", run_deye_const_tests, "DEYE constants tests", False),

coverage/apps.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ pred_bat:
333333

334334
# Octopus free session points to the free session Sensor in the Octopus plugin
335335
# Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work
336-
#octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)'
336+
#octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_(free_electricity_session_events|power_up_events))'
337337
octopus_free_url: 'http://octopus.energy/free-electricity'
338338

339339
# Energy rates

docs/energy-rates.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,24 @@ if you don't want the standing charge (and only have consumption usage) to be in
143143
Note that this configuration option to suppress the standing charge only applies if you are using the Octopus Integration from Predbat.
144144
If you are using the Octopus Energy direct method of Predbat directly connecting to Octopus then the standing charge will always be included in the plan and charts.
145145

146-
### Octopus Saving sessions
146+
### Octopus Saving sessions (Power Down events)
147147

148-
Predbat can automatically join you to Octopus saving sessions and plan battery activity for the saving session period to maximise your income.
148+
Predbat can automatically join you to Octopus saving sessions - now called Power Down events - and plan battery activity for the session period to maximise your income.
149149

150-
Note: **You must have signed up to both the Octopus Octoplus and then the Saving Session schemes to benefit from these events**
150+
Note: **You must have signed up to both the Octopus Octoplus and then the Saving Session/Power Down schemes to benefit from these events**
151151

152152
For Predbat to automatically manage Octopus saving sessions the following additional configuration item in `apps.yaml` is used.
153153
Like the electricity rates, this is set in the `apps.yaml` template to a regular expression that should auto-discover the Octopus Energy integration.
154154

155-
- **octopus_saving_session** - Indicates if a saving session is active, should point to the sensor 'event.octopus_energy_ACCOUNT_ID_saving_session_event'.
155+
- **octopus_saving_session** - Indicates if a saving session/Power Down event is active, should point to the sensor 'event.octopus_energy_ACCOUNT_ID_octoplus_power_down_events'.
156+
157+
```yaml
158+
octopus_saving_session: 're:(event.octopus_energy([0-9a-z_]+|)_(saving_session_events?|power_down_events))'
159+
```
160+
161+
Octopus Energy integration v19.0.0 renamed this sensor from `..._octoplus_saving_session_events` to `..._octoplus_power_down_events`. The above pattern matches either name, so existing configurations keep working unchanged.
162+
The old sensor is retained by the integration until **January 2027**, after which only the Power Down naming will exist. The new sensor ships disabled by default in Home Assistant
163+
(`entity_registry_enabled_default: False`) - if Predbat's Octopus entity list does not show a Power Down sensor, [enable it in the entity registry first](https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/faq/#there-are-entities-that-are-disabled-why-are-they-disabled-and-how-do-i-enable-them), otherwise Predbat will keep silently using the old sensor with no visible warning.
156164

157165
When a saving session is available it will be automatically joined by Predbat and should then appear as a joined session within the next 30 minutes.
158166

@@ -180,9 +188,9 @@ If you do not have an export tariff then forced export will not apply and Predba
180188
If you do not want Predbat to automatically join Octopus saving sessions and manage your battery activity for the session,
181189
simply delete or comment out the **octopus_saving_session** entry in `apps.yaml`.
182190

183-
### Octopus free (power up) events
191+
### Octopus free (Power Up) events
184192

185-
Predbat can automatically detect Octopus free events and adjust your battery plan according. Note that this is derived from external sources, which do not verify your eligibility for free sessions.
193+
Predbat can automatically detect Octopus free events - now called Power Up events - and adjust your battery plan accordingly. Note that this is derived from external sources, which do not verify your eligibility for free sessions.
186194

187195
For Predbat to automatically manage Octopus free sessions the following additional configuration item in apps.yaml is used.
188196

@@ -194,10 +202,14 @@ Like the electricity rates, this is set in the apps.yaml template to a regular e
194202
all the free events.
195203

196204
```yaml
197-
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)'
205+
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_(free_electricity_session_events|power_up_events))'
198206
```
199207

200-
Note: **This event may need to be enabled in Home Assistant first** - see [How to Enable Octopus events](https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/faq/#there-are-entities-that-are-disabled-why-are-they-disabled-and-how-do-i-enable-them)
208+
Octopus Energy integration v19.0.0 renamed this sensor from `..._octoplus_free_electricity_session_events` to `..._octoplus_power_up_events`. The above pattern matches either name, so existing
209+
configurations keep working unchanged. The old sensor is retained by the integration until **January 2027**, after which only the Power Up naming will exist.
210+
211+
Note: **This event may need to be enabled in Home Assistant first** - the new Power Up sensor ships disabled by default (`entity_registry_enabled_default: False`), so if it is not appearing in
212+
Predbat's entity list, enable it in the entity registry - see [How to Enable Octopus events](https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/faq/#there-are-entities-that-are-disabled-why-are-they-disabled-and-how-do-i-enable-them)
201213

202214
If you normally increase your house usage during a free session then you can change **input_number.predbat_load_scaling_free** to allow Predbat to assume an energy
203215
increase in this period. E.g. setting to a value of 1.2 would indicate you will use 20% more energy than normal during this period. (Default is 1.2)

templates/enphase_cloud.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,12 @@ pred_bat:
184184

185185
# Octopus saving session points to the saving session Sensor in the Octopus plugin, when enabled saving sessions will be at the assumed
186186
# Rate is read automatically from the add-in and converted to pence using the conversion rate below (default is 8)
187-
octopus_saving_session: 're:(event.octopus_energy([0-9a-z_]+|)_saving_session_event(s|))'
187+
octopus_saving_session: 're:(event.octopus_energy([0-9a-z_]+|)_(saving_session_events?|power_down_events))'
188188
octopus_saving_session_octopoints_per_penny: 8
189189

190190
# Octopus free session points to the free session Sensor in the Octopus plugin
191191
# Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work
192-
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)'
192+
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_(free_electricity_session_events|power_up_events))'
193193

194194
# Alternative scraper from Octopus web site if the above is not working
195195
# octopus_free_url: 'http://octopus.energy/free-electricity'

templates/fox.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,12 @@ pred_bat:
275275

276276
# Octopus saving session points to the saving session Sensor in the Octopus plugin, when enabled saving sessions will be at the assumed
277277
# Rate is read automatically from the add-in and converted to pence using the conversion rate below (default is 8)
278-
octopus_saving_session: 're:(event.octopus_energy([0-9a-z_]+|)_saving_session_event(s|))'
278+
octopus_saving_session: 're:(event.octopus_energy([0-9a-z_]+|)_(saving_session_events?|power_down_events))'
279279
octopus_saving_session_octopoints_per_penny: 8
280280

281281
# Octopus free session points to the free session Sensor in the Octopus plugin
282282
# Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work
283-
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)'
283+
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_(free_electricity_session_events|power_up_events))'
284284

285285
# Energy rates
286286
# Please set one of these three, if multiple are set then Octopus is used first, second rates_import/rates_export and latest basic metric

templates/fox_cloud.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ pred_bat:
175175

176176
# Octopus saving session points to the saving session Sensor in the Octopus plugin, when enabled saving sessions will be at the assumed
177177
# Rate is read automatically from the add-in and converted to pence using the conversion rate below (default is 8)
178-
octopus_saving_session: 're:(event.octopus_energy([0-9a-z_]+|)_saving_session_event(s|))'
178+
octopus_saving_session: 're:(event.octopus_energy([0-9a-z_]+|)_(saving_session_events?|power_down_events))'
179179
octopus_saving_session_octopoints_per_penny: 8
180180

181181
# Octopus free session points to the free session Sensor in the Octopus plugin
182182
# Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work
183-
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)'
183+
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_(free_electricity_session_events|power_up_events))'
184184

185185
# Alternative scraper from Octopus web site if the above is not working
186186
# octopus_free_url: 'http://octopus.energy/free-electricity'

templates/fronius.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,12 @@ pred_bat:
328328

329329
# Octopus saving session points to the saving session Sensor in the Octopus plugin, when enabled saving sessions will be at the assumed
330330
# Rate is read automatically from the add-in and converted to pence using the conversion rate below (default is 8)
331-
octopus_saving_session: 're:(event.octopus_energy([0-9a-z_]+|)_saving_session_event(s|))'
331+
octopus_saving_session: 're:(event.octopus_energy([0-9a-z_]+|)_(saving_session_events?|power_down_events))'
332332
octopus_saving_session_octopoints_per_penny: 8
333333

334334
# Octopus free session points to the free session Sensor in the Octopus plugin
335335
# Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work
336-
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)'
336+
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_(free_electricity_session_events|power_up_events))'
337337

338338
# Energy rates
339339
# Please set one of these three, if multiple are set then Octopus is used first, second rates_import/rates_export and latest basic metric

templates/ginlong_solis.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,12 @@ pred_bat:
262262

263263
# Octopus saving session points to the saving session Sensor in the Octopus plugin, when enabled saving sessions will be at the assumed
264264
# Rate is read automatically from the add-in and converted to pence using the conversion rate below (default is 8)
265-
octopus_saving_session: 're:(event.octopus_energy([0-9a-z_]+|)_saving_session_event(s|))'
265+
octopus_saving_session: 're:(event.octopus_energy([0-9a-z_]+|)_(saving_session_events?|power_down_events))'
266266
octopus_saving_session_octopoints_per_penny: 8
267267

268268
# Octopus free session points to the free session Sensor in the Octopus plugin
269269
# Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work
270-
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)'
270+
octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_(free_electricity_session_events|power_up_events))'
271271

272272
# Energy rates
273273
# Please set one of these three, if multiple are set then Octopus is used first, second rates_import/rates_export and latest basic metric

0 commit comments

Comments
 (0)