Octopus Agile Automation

Post Reply
Steve1978
Posts: 5
Joined: Tue Feb 07, 2023 9:00 pm

Hi,
I have a Fox H1 5 inverter and 7 Fox batterys. I have just set up a modbus converter thanks to help from this forum. I have also set up HA and everything is showing up fine.

I am on Octopus Agile which as you know means that the price of electric changes every 30 minutes. I have integrated HA with Octopus Agile and it now knows that cost of my electric too. I have created a very simple dashboard that shows my current usage, current rate, battery SOC etc.

Now to take things to the next level, I would like to charge my battery’s when the rate is at its lowest each day, that might be 5 different times per day and each might be 30 minutes. At the moment I am doing this every day, manually logging in and setting the next charge times, it’s a right faff. Has anyone achieved this through automation?
Oberoy
Posts: 1
Joined: Tue Jan 02, 2024 8:13 pm

I'm in the very same position as you Steve, just been browsing the forum and saw the thread "[HA Integration] Energy Management". Looks like someone has made some of what maybe needed.
Watching to see if there is something out there that could be used.
Dave Foster
Posts: 824
Joined: Thu Oct 13, 2022 7:21 pm

It is possible, I don't use Agile myself so haven't yet written anything to handle that but all of the building blocks are there.

This one was written for the free power ups viewtopic.php?t=430 - and I know the Octopus Energy Integration provides lowest rate events so it's likely to be a combination of them.

I think one of the forum members is using agile this way i'll drop him a message and see if he can help.
Steve1978
Posts: 5
Joined: Tue Feb 07, 2023 9:00 pm

Thanks, my coding is zero but I’m capable of copying and pasting from multiple sources as long as the right track is there!
Dave Foster
Posts: 824
Joined: Thu Oct 13, 2022 7:21 pm

I've asked amongst a few people that use agile and they all seem to do things slightly differently depending on their individual circumstances, but the consensus semes to be around using the Octopus Energy Integration ( https://github.com/BottlecapDave/HomeAs ... opusEnergy ) to provide all of the rates and target sensors, and then to create an automation that triggers if the sensor.octopus_energy_electricity_xxxxxxxxxxxx_yyyyyyyyyyyy_current_rate sensor goes below a target rate that they set in a helper value.

When the target rate goes below that helper value, it checks the battery charge isn't currently on and if it isn't it sets a battery charge period.

Likewise when the current_rate sensor goes above the helper value it cancels the battery charge.

I don't use agile myself but have most of those components already written so can help you with coding if you need it, but I'll see if I can get somebody to share their current automation code.
chris01942
Posts: 15
Joined: Sun Nov 06, 2022 8:34 am

Hi all, I use Agile & have several automations that help me manage the Tariff. Bear with me as I am dyslexic & writing is not one of my strengths, but I'll do my best to explain what I've done & feel free to ask questions but I'm on a course this week (WC 8th Jan), so may not be able to answer straight away. Also, if you have any suggestions please feel free to mention them as I only know the basics around writing automation.

You'll need the FoxESS Modbus & Energy Management integrations installed as my automation targets some of the options contained in their code.

I've attached a screen shot of the main helpers I have on the dashboard to control the automation. For example, setting the target price to charge when below the price and time periods to boost the charge current when prices are low or negative. Rinse & repeat the automation & helpers on the time/max charge current if you want more periods where you charge higher than your usual charge amps.

It's a bit clunky & does require a little maths every day to work out how many 30-minute Agile segments to target that will charge the battery, taking into account how much charge is in the battery & how much solar charge you'll get the next day. I typically have my battery charging at 10 amps, but I have added a couple of time automations that can be used to ramp up the charge amps and then revert to whatever amps you want as a bulk charge. Useful when the price is very low or negative.

You'll need to know how to set up helpers (plenty of videos on YouTube that can help with that). Also, an integration that can import Agile prices. I use this one https://github.com/BottlecapDave/HomeAs ... opusEnergy

Below is the automation code that charges the battery when the current Agile price is below my maximum import/target price. Battery Disable Discharge is an automation that puts the inverter into Backup work mode. I add 12% to the highest 30-minute import price to account for charge/discharge losses. Meaning the system runs off the grid if it's cheaper than using the stored energy I paid to put into the battery (not perfect I know, but at least I'm not using the battery when it's more expensive than using the grid).

Code: Select all

alias: Agile Target Rate Charge
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.disable_agile_charging
  - platform: time_pattern
    minutes: /1
    enabled: true
condition: []
action:
  - if:
      - condition: and
        conditions:
          - condition: numeric_state
            entity_id: >-
              sensor.octopus_energy_electricity_22l3697115_1610010746750_current_rate
            below: input_number.target_rate
          - condition: state
            entity_id: binary_sensor.time_period_1_enable_force_charge
            state: "off"
          - condition: state
            entity_id: input_boolean.disable_agile_charging
            state: "off"
    then:
      - service: foxess_em.start_force_charge_now
        data: {}
      - service: logbook.log
        data:
          name: Agile Target Rate Charge
          message: Force Charge Now On Current Rate Below Target Rate
    else:
      - if:
          - condition: and
            conditions:
              - condition: state
                entity_id: binary_sensor.time_period_1_enable_charge_from_grid
                state: "on"
              - condition: numeric_state
                entity_id: >-
                  sensor.octopus_energy_electricity_22l3697115_1610010746750_current_rate
                above: input_number.target_rate
        then:
          - service: foxess_em.stop_force_charge
            data: {}
          - service: logbook.log
            data:
              name: Agile Target Rate Charge Current Rate Above Target
              message: Force Charge Now Off
        enabled: true
        else:
          - if:
              - condition: state
                entity_id: input_boolean.disable_agile_charging
                state: "on"
              - condition: state
                entity_id: binary_sensor.time_period_1_enable_force_charge
                state: "on"
                enabled: true
              - condition: state
                entity_id: binary_sensor.time_period_1_enable_charge_from_grid
                state: ""
            then:
              - service: foxess_em.stop_force_charge
                data: {}
              - service: logbook.log
                data:
                  name: Agile Target Rate Charge Disable Agile Target Charge
                  message: Force Charge Off by Disable Agile Charge
            enabled: true
mode: single
----------------------------------------------------------------------------------------------------------------------------------------------
The following line from the above code:
- input_boolean.disable_agile_charging
is a helper I use to stop the automation firing via a toggle switch on a dashboard for any reason I may want the automation off.
-----------------------------------------------------------------------------------------------------------------------------------------------
The following automation is for one of the time periods to start charging at a specific amperage.
Please ignore any Telegram Bot messages in my automations!

Code: Select all

alias: "Agile: Period 1 Max Charge Current Start"
description: ""
trigger:
  - platform: time
    at: input_datetime.agile_boost_current_period_1
condition:
  - condition: state
    entity_id: input_boolean.agile_disable_period_1
    state: "off"
action:
  - service: number.set_value
    data:
      value: "{{ states.input_number.agile_boost_max_current.state | int }}"
    target:
      entity_id:
        - number.max_charge_current
  - service: logbook.log
    data:
      name: "Agile: Period 1 Start"
      message: Max Current Now Set
mode: single
---------------------------------------------------------------------------------------------------------------------------------------------------------
The following automation is for one of the time periods to stop charging at a specific amperage & set a lower charge rate i.e. 10amps

Code: Select all

alias: "Agile: Period 1 Max Charge Current End"
description: ""
trigger:
  - platform: time
    at: input_datetime.agile_boost_time_period_1_end
condition:
  - condition: state
    entity_id: input_boolean.agile_disable_period_1
    state: "off"
action:
  - if:
      - condition: or
        conditions:
          - condition: numeric_state
            entity_id: number.max_charge_current
            above: input_number.agile_bulk_max_current
          - condition: numeric_state
            entity_id: number.max_charge_current
            below: input_number.agile_bulk_max_current
    then:
      - service: number.set_value
        data:
          value: "{{ states.input_number.agile_bulk_max_current.state | int }}"
        target:
          entity_id:
            - number.max_charge_current
      - service: logbook.log
        data:
          name: "Agile: Period 1 End"
          message: Bulk Current Set
      - service: input_boolean.turn_on
        data: {}
        target:
          entity_id: input_boolean.agile_disable_period_1
      - service: logbook.log
        data:
          name: Agile Period 1
          message: Disabled
      - service: telegram_bot.send_message
        data:
          message: Agile Period 1 bulk current set. Period 1 Disabled
mode: single
-------------------------------------------------------------------------------------------------------------------------------------------

The following code is for putting the inverter into Back Up when the current Agile price is lower than the charging target price +12% (to save using the battery when Agile is cheaper than the charging costs + losses)

Code: Select all

alias: Battery Discharge Current price vs Threshold Price
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.octopus_energy_electricity_22l3697115_1610010746750_current_rate
  - platform: state
    entity_id:
      - input_number.battery_disable_discharge_current_price_threshold
condition:
  - condition: state
    entity_id: input_boolean.automation_battery_discharge_current_price_v_threshold_price
    state: "on"
action:
  - if:
      - condition: numeric_state
        entity_id: >-
          sensor.octopus_energy_electricity_22l3697115_1610010746750_current_rate
        above: input_number.battery_disable_discharge_current_price_threshold
      - condition: not
        conditions:
          - condition: state
            entity_id: select.work_mode
            state: Self Use
    then:
      - device_id: 97512bfbff167a4c9ea078aa33a827f1
        domain: select
        entity_id: 2d41fcaed5ee6d2a7ef91e9731472bcd
        type: select_option
        option: Self Use
      - service: logbook.log
        data:
          name: Battery to Discharge via Self Use
          message: Current Price Above Discharge Threshold
      - service: telegram_bot.send_message
        data:
          message: Work Mode Self Use Current Price Above Threshold
    else:
      - if:
          - condition: numeric_state
            entity_id: >-
              sensor.octopus_energy_electricity_22l3697115_1610010746750_current_rate
            below: input_number.battery_disable_discharge_current_price_threshold
          - condition: state
            entity_id: select.work_mode
            state: Self Use
        then:
          - device_id: 97512bfbff167a4c9ea078aa33a827f1
            domain: select
            entity_id: 2d41fcaed5ee6d2a7ef91e9731472bcd
            type: select_option
            option: Back-up
          - service: logbook.log
            data:
              name: No Battery Discharge via Back UP
              message: Current Price Below Discharge Threshold
          - service: telegram_bot.send_message
            data:
              message: Work Mode Back Up Current Price Below Threshold
mode: single
Attachments
agile dashboard.png
chris01942
Posts: 15
Joined: Sun Nov 06, 2022 8:34 am

Hi, I've noticed the YAML code I've posted the spacing has been messed up, so if you copy & paste it into automations in YAML mode it won't work. Anyone know how to post code so the spacing is correct?
Dave Foster
Posts: 824
Joined: Thu Oct 13, 2022 7:21 pm

If you click the </> at the top of the post it will add this to your post [ code ][ /code ]

Then add you code within it and it will preserve the indentations.

[ code ]
My snippet of code
With spacing:
And indentations:
[ /code ]

Ends up looking like this -

Code: Select all

My snippet of code
   With spacing:
       And indentations:
I’ve modified your post so hopefully it looks correct now.
chris01942
Posts: 15
Joined: Sun Nov 06, 2022 8:34 am

Dave Foster wrote: Mon Jan 08, 2024 9:11 pm If you click the </> at the top of the post it will add this to your post [ code ][ /code ]

Then add you code within it and it will preserve the indentations.

[ code ]
My snippet of code
With spacing:
And indentations:
[ /code ]

Ends up looking like this -

Code: Select all

My snippet of code
   With spacing:
       And indentations:
I’ve modified your post so hopefully it looks correct now.

Thanks for that Dave 👍
Post Reply