Automating Saving Session events into Predbat

5 comments started 2024-12-11 last 2025-01-23
Home AutomationHome Assistant
G
#1 geoffreycoan

I knocked up this quick solution tonight to automate saving sessions into Predbat as it appears that the Octopus saving session sensor that was being used last year doesn't appear to be populated for the saving sessions this year.

It heavily borrows/reuses the solution I put together for Free Electricity/Power Up events https://community.givenergy.cloud/d/3968-automating-octopus-power-up-events-into-predbat/56

The parts are as follows:

  1. Control variables:

Create a date/time helper called octopus_saving_session_date of type date, another called octopus_saving_session_start_time of type time, and a third called octopus_saving_session_end_time also of type time.

Create an input number helper called octopus_saving_session_amount. I made it an input field and with a maximum value of 400 (I wish)

These will hold the date, start time, end time and saving session amount for the event. These are all in the notification email from Octopus

  1. Script:

Create a script to send the event details to Predbat:

alias: Send Saving Session event to Predbat manual API
sequence:
  - action: select.select_option
    data:
      option: >-
        rates_export_override?date={{          
        states('input_datetime.octopus_saving_session_date')| as_timestamp |
        timestamp_custom('%Y-%m-%d') }}&start={{          
        states('input_datetime.octopus_saving_session_start_time')
        }}&end={{          
        states('input_datetime.octopus_saving_session_end_time')
        }}&rate_increment={{
        states('input_number.octopus_saving_session_amount')|int 
        }}&load_scaling={{
        states('input_number.predbat_load_scaling_saving')|float }}
    target:
      entity_id: select.predbat_manual_api
mode: single
description: ""

The script collects the above input variables and the existing Predbat saving session load scaling factor, and sends these to Predbat as an export rate override.

  1. Dashboard:

Either on the existing Power Up dashboard, or on a new one, create a control of type entities and paste the following in:

type: entities
entities:
  - entity: input_datetime.octopus_saving_session_date
  - entity: input_datetime.octopus_saving_session_start_time
  - entity: input_datetime.octopus_saving_session_end_time
  - entity: input_number.octopus_saving_session_amount
  - entity: input_number.predbat_load_scaling_saving
  - type: button
    name: Send Saving Session event to Predbat
    icon: mdi:script-text-play-outline
    action_name: Execute
    tap_action:
      action: perform-action
      perform_action: script.send_saving_session_event_to_predbat_manual_api

In use the dashboard looks like this:

Simply enter the date, times, saving session amount and how much you will reduce your house load during the saving session. In my example, I've said its 10% of my current load.

Then click Execute and it will send the event to predbat and you'll get something like this *:

G
#2 geoffreycoan

There is a caveat to the above, including the load_scaling factor crashes my version of Predbat with the following errors:

2024-12-11 18:39:28.913696: Error: Exception raised can't multiply sequence by non-int of type 'float'
2024-12-11 18:39:28.917517: Error: Traceback (most recent call last):
  File "/config/predbat.py", line 10901, in update_time_loop
    self.update_pred(scheduled=False)
  File "/config/predbat.py", line 9707, in update_pred
    recompute = self.calculate_plan(recompute=recompute)
  File "/config/predbat.py", line 7844, in calculate_plan
    load_minutes_step = self.step_data_history(
  File "/config/predbat.py", line 1891, in step_data_history
    values[minute] = self.dp4((value + load_extra) * scaling_dynamic * scale_today * scale_fixed)
TypeError: can't multiply sequence by non-int of type 'float'

2024-12-11 18:39:28.949677: Info: record_status Error: Exception raised can't multiply sequence by non-int of type 'float'
2024-12-11 18:39:28.949823: Error: can't multiply sequence by non-int of type 'float'

I think this is a core Predbat bug not just me running an old version of Predbat, so at the moment change the script to:

alias: Send Saving Session event to Predbat manual API
sequence:
  - action: select.select_option
    data:
      option: >-
        rates_export_override?date={{          
        states('input_datetime.octopus_saving_session_date')| as_timestamp |
        timestamp_custom('%Y-%m-%d') }}&start={{          
        states('input_datetime.octopus_saving_session_start_time')
        }}&end={{          
        states('input_datetime.octopus_saving_session_end_time')
        }}&rate_increment={{
        states('input_number.octopus_saving_session_amount')|int 
        }}
    target:
      entity_id: select.predbat_manual_api
mode: single
description: ""

And I'll raise a Github issue for this

G
#4 geoffreycoan

Update: Trefor fixed the bug I mentioned above so you can now use load_scaling with the predbat manual API, and Octopus have now got the saving session API working so Predbat will now auto-detect and auto-join saving sessions.

As it stands therefore this dashboard and script isn’t now needed for saving sessions, BUT can be adapted for other purposes …..

G
#5 geoffreycoan

One of the things that others have requested and I know I would find useful is a way to adjust Predbat’s load prediction, e.g. if you know you will be having a big load of washing done, cooking a roast dinner, or when the Agile rates are very high, you turn the heat pump off or down.

There isn’t an easy way of doing this, but as I have mentioned before the Predbat manual API can be used, and I’ve now adapted the DFS dashboard and script to make this easy to do.

The solution builds upon and extends the method of injecting DFS saving sessions into Predbat described above, so not going to repeat that in detail.

  1. Create new control variable as described above

  2. New version of the script that can now send either a DFS saving sessions OR an adjusted load period into Predbat:

alias: Send Saving Session event to Predbat manual API
sequence:
  - action: select.select_option
    data:
      option: >-
        {% set x=states('input_number.octopus_saving_session_amount')|int %}
        rates_export_override?date={{          
        states('input_datetime.octopus_saving_session_date')| as_timestamp |
        timestamp_custom('%Y-%m-%d') }}&start={{          
        states('input_datetime.octopus_saving_session_start_time') }}&end={{
        states('input_datetime.octopus_saving_session_end_time') }}{% if x>0
        %}&rate_increment={{ x }}{% endif %}&load_scaling={{
        states('input_number.predbat_load_scaling_saving')|float }}
    target:
      entity_id: select.predbat_manual_api
mode: single
description: ""
  1. Tiny update to the dashboard (just changing the name of one of the dashboard entities):
type: entities
entities:
  - entity: input_datetime.octopus_saving_session_date
  - entity: input_datetime.octopus_saving_session_start_time
  - entity: input_datetime.octopus_saving_session_end_time
  - entity: input_number.octopus_saving_session_amount
  - entity: input_number.predbat_load_scaling_saving
    name: Octopus Saving Session Amount (use 0 to just adjust load)
  - type: button
    name: Send Saving Session event to Predbat
    icon: mdi:script-text-play-outline
    action_name: Execute
    tap_action:
      action: perform-action
      perform_action: script.send_saving_session_event_to_predbat_manual_api

To use:

You can either use the dashboard as before to send DFS saving session details into Predbat. Enter on the dashboard the date, start and end times, saving saving session amount and load scaling factor for the DFS session, then click ‘execute’ and the script will send everything to Predbat using select.predbat_manual_api

OR (new functionality)

If you want to change the predicted load for a specific time period, enter the date, start and end times and load scaling factor in the dashboard and set the saving session amount to zero.
Again the Predbat manual API is instructed by the automation script but only the predicted house load is adjusted.

The load scaling figure is a scaling factor of Predbat’s predicted house load. So 0.5 is that the house load will be 50% of the normal prediction, and 2.0 will be that the house load will be doubled.

Here’s what it looks like in practice, I have set two one hour ‘events’ through to Predbat, the first being a pretend DFS saving session worth 10p where I expect to drop the house load to 10% of normal predicted amount from 21:00-22:00, and the second being just a change of house load to 10% of normal predicted amount from 20:00-21:00.

Note the changed house load, export rate, and the +- symbol next to the export rate indicating its been overwritten.

Here’s what it looks like in the select.predbat_manual_api

After the ‘event’ is over its worth setting hte select to ‘off’ just to clear it of old entries which over time will accumulate as they don’t auto-expire.

Enjoy !