Having done a few automations for my solar & battery setup (Solax X1 Hybrid G4 (local & cloud API)) last year, I’ve set myself another challenge: Octopus Saving Sessions.
What’s important this year, we can also get rewarded for exported electricity rather than just reducing import. With that in mind, I successfully supported the first 4 sessions by manually following all the steps:
- Joining the session
- Pre-charging or topping up the battery (if required)
- Enabling second charging period
- Updating the forced charge stop to just before the Saving Session start time
- Forcing discharge
- Setting inverter to Manual mode
- Setting the Manual mode behaviour to Forced Discharge
- Re-setting back to normal operation
- Disabling the second charging period
- Setting the interter back to Self Use mode
Having confidence these steps had the expected effect, it was time to automate!
I’m sharing this so that you can use these automations as is or try to improve them further, as I’m sure there is probably an easier and better way to achieve this.
Screenshots
Waiting for a session:
Upcoming session:
Duing a session:
After a session
Design
Before jumping into describing each of the automations, I want to first explain the concepts and thinking behind this.
Assuming a Saving Session has already been joined, the next thing is to determine if there is a session later in the day - this is required to top up the battery ahead of the session start.
In addition, a number of other automations get enabled:
- Start watching for session start
- Start watching battery % (SOC) and inverter mode - one of the triggers to resume normal operation once battery has discharged
The two helper fields (Saving Session Start
time and the Saving Session Today
are not only to help with automations, but also provide ability to overide these values manually if required.
Configuration files
For all my setup, including the configs and automations used in this article, please see my github repo .
Automations
Joining a session
Luckily, there is a great HACS integration for Octopus: GitHub - BottlecapDave/HomeAssistant-OctopusEnergy: Unofficial Home Assistant integration for interacting with Octopus Energy, with an automation for joining Saving Sessions: Services - Home Assistant Octopus Energy, so that’s step 1 done!
Is there a Saving Session today?
To simplify my automations, I’m consolidating the Current joined event start
and Next joined event start
from the mentioned HACS integration into a single datetime value (current with fallback to next). I’m doing this because once the session becomes active, the Next joined event start
turns null. If both are null, I’m assuming a week from now so that there is alreays a datetime available. This is stored in input_datetime.saving_session_start
.
Then I check if the session starts later the same day (using day number to compare datetimes) and store the result in input_select.saving_session_today
:
{{ 'yes' if (upcoming_event != None and upcoming_event.strftime('%j') == now().strftime('%j')) else 'no' }}
I use this flag to drive forced charging ahead of the session start.
Configuring battery top-up (forced charge)
This automation configures the second charge/discharge period (specific to Solax) so not to mess up your main settings (in my case aligned with Octopus Intelligent Go off-peak). I have the forced charge start
set to 13:00, while the forced charge end
is being set dynamically to one minute before the session start. This tries to align with a typical early afternoon dip in demand for electricity.
- service: rest_command.solax_local_set_period2_enable
data:
# 1 = enabled, 0 = disabled
enabled: >
{{ 1 }}
- service: rest_command.solax_local_set_forced_charge_stop2
data:
# Switch off forced charge 1 minute before session start
value: >-
{% set end_time = as_datetime(state_attr('input_datetime.saving_session_start', 'timestamp') - 60) %}
{{ end_time.hour + end_time.minute * 256 }}
The second charge/discharge period is then switched off at the end of the day.
Set manual mode and forced discharge
This automation runs every minute (when enabled) and checks for the following condition:
{{ states('input_select.saving_session_today') == 'yes' and as_datetime(states('input_datetime.saving_session_start')).timestamp() < now().timestamp() }}
and if this evaluates to true, inverter settings are updated to start forced export:
- service: rest_command.solax_local_set_inverter_mode
data:
# 0: self use, 1: feed in priority, 2: back up, 3: manual
value: >
{{ 3 }}
- service: rest_command.solax_local_set_manual_mode_behaviour
data:
# 0: do nothing, 1: forced charge, 2: forced discharge
value: >
{{ 2 }}
Return to normal operation
Once the battery is at 10% for a few minutes, the automation sets the inverter back to Self Use
mode:
trigger:
- platform: numeric_state
entity_id: sensor.solax_local_battery_soc
below: 11
for:
hours: 0
minutes: 5
seconds: 0
- platform: state
entity_id:
- binary_sensor.octopus_energy_a_5790678f_octoplus_saving_sessions
from: "on"
to: "off"
for:
hours: 0
minutes: 1
seconds: 0
condition:
- condition: template
value_template: >-
{{ (states('sensor.solax_local_inverter_mode') == 'Manual' or states('sensor.solax_local_battery_chd2_enabled')|bool==true) }}
action:
- repeat:
sequence:
- service: rest_command.solax_local_set_inverter_mode
data:
# 0: self use, 1: feed in priority, 2: back up, 3: manual
value: >
{{ 0 }}
- delay:
hours: 0
minutes: 0
seconds: 15
milliseconds: 0
- service: rest_command.solax_local_set_period2_enable
data:
# 1 = enabled, 0 = disabled
enabled: >
{{ 0 }}
- delay:
hours: 0
minutes: 0
seconds: 15
milliseconds: 0
- service: homeassistant.update_entity
entity_id: sensor.solax_rest_local_settings
until:
- condition: template
# Try up to 3 times if the updated setting doen't reflect the target
value_template: >-
{{ (states('sensor.solax_local_battery_chd2_enabled')|bool==false and states('sensor.solax_local_inverter_mode') == 'Self Use') or repeat.index == 3 }}
Summary
I’ve yet to test this fully during upcoming Saving Sessions, but sharing this early to get feedback and allow you to do something similar if you wish. Any thoughts or comments will be hugely appreciated.
UPDATE 19/12/2023: All automations worked as expected and no manual input was required I’ve also made some further improvements and simplifications so the screenshots will need updating.