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