Latest from YouTube Channel

GivEnergy Battery Automation for Demand Flexibility Service (DFS) Octopus Saving Sessions

December 10th, 2022
YouTube video

Have you been taking part in the Octopus Saving Sessions? Also known as DFS or Demand Flexibility Service, if you’re not with Octopus then your supplier might have a different name for it. I think Eon Next calls it Energy Shift and Ovo is calling it Power Move. Whatever it’s called, I have a problem, and that problem is my battery which has a tendency to run out of charge during the winter before these sessions begin. Well, I have a solution in the form of an automation of course!

Having a home battery like mine, which is an 8.2kWh GivEnergy one, is great. In theory during these Saving Sessions my battery should be able cover our use and we’d draw absolutely nothing from the grid at all for those periods. The problem is that my battery just doesn’t have enough capacity to get me through a full day during the Winter with its lack of sunshine. So by the time we get to the evening when the saving sessions normally take place, I’ve got no capacity left!

I found myself estimating how much capacity I’d need to get through the session, and then manually pausing the battery’s discharge before I got to that threshold. Just before the session begins I’d resume it again. This involved a lot of clock watching, and it got me thinking… can I automate this? Of course I can! I came up with an automation for Home Assistant, which I then turned into a blueprint to make it easier for anyone to install. It essentially watches your battery percentage to make sure it doesn’t drop below the percentage that you want reserved for the saving session. If it does drop too low, it’ll pause the discharge and resume it again just before the session starts to make sure you don’t draw anything from the grid.

I’m going to make a massive assumption here that you already have your GivEnergy battery connected to Home Assistant. If you don’t, then check out this article which will talk you through that whole process.

Create Helpers

You’re going to need to create some helpers before we can configure the blueprint.

  • The first helper is a date/time helper but set for date only. This will be used to store the date of the upcoming saving session.
  • The second and third helpers are also date/time helpers, but set for time only. One will store the start time of the saving session, the other is for the end time.
  • The fourth and final helper is an input_number helper. Set this to have a minimum value of 1, maximum value of 100, and the unit of measurement as percentage. You’ll use this helper to set how much battery capacity you wish to reserve per hour for the saving session.

Install the Blueprint

Now it’s time to install the blueprint. The easy way is to click the button below which should automatically download and install it for you, provided you have configured My Home Assistant correctly:

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

The harder manual method involves copying and pasting the below configuration into a text file named octopus_saving_session.yaml.

blueprint:
  name: Octopus Saving Session for GivEnergy
  description: Prevents the battery from discharging if theres not enough remaining charge for a scheduled Saving Session, and enables discharge again before the session begins.
  domain: automation
  input:
    battery_soc:
      name: Battery SOC sensor
      description: Live state of charge (percentage) of the battery (sensor entity)
      selector:
        entity:
          domain:
            - sensor
    octopus_saving_session_day:
      name: Octopus Saving Session Day
      description: The date of the scheduled Saving Session (input_datetime helper. Date only.)
      selector:
        entity:
          domain:
            - input_datetime
    octopus_saving_session_start_time:
      name: Octopus Saving Session Start Time
      description: What time does the Saving Session begin? (input_datetime helper. Time only.)
      selector:
        entity:
          domain:
            - input_datetime
    octopus_saving_session_end_time:
      name: Octopus Saving Session End Time
      description: What time does the Saving Session finish? (input_datetime helper. Time only.)
      selector:
        entity:
          domain:
            - input_datetime
    battery_percentage_per_hour:
      name: Battery Percentage Per Hour
      description: How much battery percentage, per hour, do you need to make sure is reserved? (input_number. limit 1-100)
      selector:
        entity:
          domain:
            - input_number
    battery_enable_discharge_switch:
      name: Enable battery discharge switch
      description: Switch which enables or disables the batterys ability to discharge. When on, discharge is possible. (switch)
      selector:
        entity:
          domain:
            - switch
    battery_mode:
      name: Battery Mode
      description: The current mode of the battery, so as we know whether its in eco mode or not (select)
      selector:
        entity:
          domain:
            - select

mode: single
max_exceeded: silent

variables:
  battery_soc: !input battery_soc
  octopus_saving_session_day: !input octopus_saving_session_day
  octopus_saving_session_start_time: !input octopus_saving_session_start_time
  octopus_saving_session_end_time: !input octopus_saving_session_end_time
  battery_percentage_per_hour: !input battery_percentage_per_hour

trigger:
  - platform: state
    alias: Trigger whenever the battery SOC changes
    entity_id:
      - !input battery_soc
    id: soc_change
  - platform: time_pattern
    minutes: /15
    id: check_the_time

condition:
  - alias: Only execute this automation on the saving session day
    condition: template
    value_template: >-
      {{ (now().date() + timedelta(days=0)) | string ==
      states(octopus_saving_session_day) }}
  - alias: Only run after 7am to avoid the battery charging hours
    condition: time
    after: "07:00:00"

action:
  - choose:
      - alias: >-
          When the battery SOC changes, check that we have enough reserve for
          the saver session and pause discharge if necessary
        conditions:
          - condition: trigger
            id: soc_change
          - alias: >-
              We are not within 15 minutes of the start time of the saving session
            condition: template
            value_template: >-
              {{ ((now().hour * 3600) + (now().minute * 60) + now().second )|int
              <
              (state_attr(octopus_saving_session_start_time,'timestamp')-(15*60))|int
              }}
          - alias: We dont have enough battery left (SOC < required power)
            condition: template
            value_template: >-
              {{ states(battery_soc)|int <
              (((state_attr(octopus_saving_session_end_time,'timestamp')
              -
              state_attr(octopus_saving_session_start_time,'timestamp'))/3600)*states(battery_percentage_per_hour)|int
              +
              states(battery_percentage_per_hour)|int)|int
              }}
          - alias: Battery is currently discharging
            condition: state
            entity_id: !input battery_mode
            state: Eco
        sequence:
          - alias: Disable the battery discharge to conserve it for the saver session
            service: homeassistant.turn_off
            data: {}
            target:
              entity_id: !input battery_enable_discharge_switch
          - service: notify.persistent_notification
            data:
              message: >-
                Battery SOC getting too low for scheduled saving session.
                Pausing discharge.
      - alias: >-
          If the battery is not in Eco mode 15 minutes before the Saving
          Session, Enable It!
        conditions:
          - condition: trigger
            id: check_the_time
          - alias: If the battery is not in eco mode
            condition: not
            conditions:
              - condition: state
                entity_id: !input battery_mode
                state: Eco
          - alias: >-
              Are we after 15 minutes before saving session starts, but before
              the actual start?
            condition: template
            value_template: >-
              {{ (((now().hour * 3600) + (now().minute * 60) + now().second
              )|int >=
              (state_attr(octopus_saving_session_start_time,'timestamp')-(15*60))|int)
              and (((now().hour * 3600) + (now().minute * 60) + now().second
              )|int <
              (state_attr(octopus_saving_session_start_time,'timestamp'))|int)
              }}
        sequence:
          - alias: Enable the battery discharge for the saving session
            service: homeassistant.turn_on
            data: {}
            target:
              entity_id: !input battery_enable_discharge_switch
          - service: notify.persistent_notification
            data:
              message: Battery was paused, resuming discharge for saving session

Make sure you have the File Editor add-on installed in Home Assistant. Open the add-on, then navigate to your config folder, the blueprints folder in there, and the automation folder in there. Click on the Upload File button at the top, choose the yaml file you saved previously and click on Ok to complete the import.

You’ll then need to reload your automations before it can be used by clicking on Developer Tools and selecting the ‘Automations’ link under YAML configuration reloading.

Create the Automation

Next we create the automation itself. Go to Settings, Automations, and click on the blue Create Automation button. We’re going to use a blueprint so choose “Octopus Saving Session for GivEnergy” from the drop-down list.

You’ll then be presented with a lot of drop-down boxes which I promise you is a lot easier to use than having to dive into the automation configuration manually to change all of the various entities I had set! I’m trying to be nice to you all here. Let’s go through these one by one.

First choose the entity that give you your current battery percentage. It might be called sensor.givtcp_soc or something similar.

Now choose the four helper entities that created earlier for Octopus Saving Session Day, Octopus Saving Session Start Time, Octopus Saving Session End Time and Octopus Saving Session Battery Percentage Per Hour.

We then need to tell the automation which switch entity controls the enabling and disabling of battery discharge. We’re looking for the one with “Enable Discharge” in the name.

And finally the automation needs to know which mode the battery is currently in. GivTCP provides a ‘select’ entity called ‘mode’ which we’ll use. Basically the automation will be checking to see if the battery is in Eco mode or not. Eco mode means that it’s discharging to your home so hopefully preventing you from drawing from the grid. Save the automation and give it a nice obvious name.

Dashboard

There’s one final step to get this working and that is adding those helpers you created to your dashboard for easy access. You can of course present these on your dashboard in any way you see fit. As an example, in the below screenshot I have simply added them to an ‘entities’ card.

Calculating how much energy you’ll need to get you through the saving session is a bit trickier. I guess the non-scientific way of doing this is by keeping an eye on your typical usage during the evenings. When I take part in the saving sessions I still try to shift the usage around a bit to minimise what I’m using then anyway in order to prevent any power spikes which would cause me to draw from the grid before the battery has had chance to ramp up. So I avoid using the oven, kettle, things like that. If you’d like to be a bit more scientific then I work on a background power of 600 watts during the session which is 0.6kWh per hour. My battery is 8.2kWh, but I reserve 10% of that in case of a power cut, which gives me 7.4kWh. 0.6kWh is just over 12% of that usable capacity. I err on the side of caution and set the battery percentage per hour slide to 15%.

Behind the scenes, the automation will work out how much is required for the saver session based on the length of that session. So if you have a one hour session scheduled, that would be 15% reserved, plus an extra 15% just in case, so it won’t let your battery drop below 30% before the session begins on that day. If you have a two hour session then that would 30% reserved plus an extra 15% just in case and your battery won’t be allowed to drop below 45% until the session begins.

  • As an Amazon Associate I earn from qualifying purchases.