Last active
January 24, 2025 06:43
-
-
Save ChrisWarwick/39eeae19f5990a2f42c17e8b5a405fb3 to your computer and use it in GitHub Desktop.
Home Assistant Automations to control battery charging and DFS Saving Sessions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Note: I have a SolarEdge setup, so all the sensors are specific to that system. | |
The "Join Saving Session" automation was converted from bottlecapdave's blueprint. | |
For the event-logging code, see: https://gist.github.com/ChrisWarwick/52af80db86bb4e7527e376e383a3096a | |
Automation: Set battery to charge during off-peak | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
alias: "House Battery: Set to charge during off-peak" | |
description: Set the house battery to charge at the start of an off-peak period | |
trigger: | |
- platform: state | |
entity_id: binary_sensor.octopus_energy_a_38c9a359_intelligent_dispatching | |
to: "on" | |
id: Electricity Meter Off-Peak On | |
action: | |
- service: notify.energygroup | |
data: | |
title: House Battery | |
message: Start of Intelligent Dispatching. Set house battery to Charge. | |
- service: number.set_value | |
target: | |
entity_id: number.solaredge_i1_storage_command_timeout | |
data: | |
value: "22200" | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 5 | |
milliseconds: 0 | |
- service: select.select_option | |
target: | |
entity_id: | |
- select.solaredge_i1_storage_command_mode | |
data: | |
option: Charge from Solar Power and Grid | |
mode: single | |
Automation: Set battery to normal operation at end of off-peak | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
alias: "House Battery: Set to Maximize Self-Consumption during peak rate" | |
description: Set the house battery to maximize self consumption during the peak period | |
trigger: | |
- platform: state | |
entity_id: binary_sensor.octopus_energy_a_38c9a359_intelligent_dispatching | |
to: "off" | |
id: Electricity Meter Off-Peak Off | |
condition: [] | |
action: | |
- service: notify.energygroup | |
data: | |
title: House Battery | |
message: End of Off-Peak. Set house battery to Maximize Self Consumption. | |
- service: number.set_value | |
target: | |
entity_id: number.solaredge_i1_storage_command_timeout | |
data: | |
value: "3600" | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 5 | |
milliseconds: 0 | |
- service: select.select_option | |
target: | |
entity_id: | |
- select.solaredge_i1_storage_command_mode | |
data: | |
option: Maximize Self Consumption | |
mode: single | |
Automation: ESO DFS Event notification, save battery charge | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
alias: Octopus ESO DFS Event Scheduling | |
description: Notify when ESO DFS event schedule opened | |
trigger: | |
- platform: state | |
entity_id: | |
- binary_sensor.grid_eso_dfs_feed_data_in_future | |
to: "on" | |
condition: [] | |
action: | |
- service: notify.allgroups | |
metadata: {} | |
data: | |
title: Electricity Systems Operator | |
message: ESO Demand Flexibility Session schedule open. Battery set to Solar Only. | |
data: | |
type: announce | |
- service: number.set_value | |
target: | |
entity_id: number.solaredge_i1_storage_command_timeout | |
data: | |
value: "21600" | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 5 | |
milliseconds: 0 | |
- service: select.select_option | |
target: | |
entity_id: | |
- select.solaredge_i1_storage_command_mode | |
data: | |
option: Charge from Clipped Solar Power | |
mode: single | |
Automation: Join Octopus Saving Session | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
alias: Octopus Energy - Automatically Join Saving Session | |
description: Automatically join Octopus Saving Sessions whenever available | |
trigger: | |
- platform: state | |
entity_id: event.octopus_energy_a_ffffffff_octoplus_saving_session_events | |
condition: | |
- condition: template | |
value_template: >- | |
{{ state_attr(saving_session_event_entity, 'available_events') | length > | |
0 }} | |
action: | |
- service: octopus_energy.join_octoplus_saving_session_event | |
data: | |
event_code: >- | |
{{ state_attr(saving_session_event_entity, | |
'available_events')[0]['code'] }} | |
target: | |
entity_id: event.octopus_energy_a_ffffffff_octoplus_saving_session_events | |
- service: notify.allgroups | |
data: | |
title: Joined Octopus Saving Sessions | |
data: | |
type: announce | |
message: > | |
{% set event_start = state_attr(saving_session_event_entity, | |
'available_events')[0]['start'] %} Joined a new Octopus Energy saving | |
session. It starts at {{ event_start.strftime('%H:%M') }} on {{ | |
event_start.day }}/{{ event_start.month }} | |
variables: | |
saving_session_event_entity: event.octopus_energy_a_ffffffff_octoplus_saving_session_events | |
mode: single | |
Automation: Force-discharge battery during saving sessions | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
alias: Octopus - Save and Export Power During DFS Saving Session | |
description: >- | |
Set inverter mode to "Discharge to Maximize Export"; turn off fridges/freezers | |
and other optional loads | |
trigger: | |
- platform: state | |
entity_id: | |
- binary_sensor.octopus_energy_a_ffffffff_octoplus_saving_sessions | |
from: "off" | |
to: "on" | |
condition: [] | |
action: | |
- service: select.select_option | |
target: | |
entity_id: select.solaredge_i1_storage_command_mode | |
data: | |
option: Discharge to Maximize Export | |
mode: single | |
configuration.yaml - define ESO DFS Feed | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Get ESO DFS Notifications | |
command_line: | |
- sensor: | |
command: "curl -L -s https://api.nationalgrideso.com/api/3/action/datastore_search_sql?sql=SELECT%20*%20FROM%20%20%2294b4d470-a54e-41d7-ae6e-be158db9b9d4%22%20ORDER%20BY%20%22_id%22%20ASC%20LIMIT%201 | jq .result.records[0]" | |
name: "Grid ESO DFS Feed" | |
unique_id: 3a6870d2-c170-44e2-b587-8bed5b5d1c87 | |
json_attributes: | |
- "Requirement For" | |
- "Requirement Type" | |
- "Notification Type" | |
- "Notification Issued Time" | |
- "Notification Issued Date" | |
scan_interval: 1200 | |
value_template: "(Attributes Only)" | |
Automation: Notify and log changes to the Inverter operation mode | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
alias: "House Battery: Command Mode change notification" | |
description: Sends a notification when the inverter command mode changes | |
trigger: | |
- platform: state | |
entity_id: | |
- select.solaredge_i1_storage_command_mode | |
action: | |
- service: notify.energygroup | |
data: | |
title: Inverter Mode Change | |
message: >- | |
The Inverter Mode is now "{{trigger.to_state.state}}", timeout | |
{{states('number.solaredge_i1_storage_command_timeout')}} seconds. | |
(Changed from {{trigger.from_state.state}}) | |
mode: single | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment