This guide provides the complete YAML code and setup instructions for a robust system to manage your Tesla Powerwall charging with an Intelligent Octopus Go tariff in Home Assistant.
The goal is to charge the Powerwall from the grid during bonus cheap rates, while intelligently handling transition periods and preventing API spam from rapid sensor state changes.
Before you begin, ensure you have the following set up in Home Assistant:
- Octopus Energy Integration: The custom integration that provides the binary_sensor for intelligent dispatching.
- Tesla Powerwall Integration: An integration that allows you to view and control your Powerwall's mode and reserve percentage.
You must identify the following entity IDs from your system. You can find them under Settings > Devices & Services > Entities.
- Octopus Intelligent Dispatching Sensor: (e.g., binary_sensor.octopus_energy_intelligent_dispatching)
- Powerwall Operation Mode Select: (e.g., select.teslapowerwall_site_mode)
- Powerwall Backup Reserve Number: (e.g., number.teslapowerwall_backup_reserve)
- Powerwall Charge Sensor: (e.g., sensor.powerwall_charge)
You will need to replace the placeholder entity IDs in the code below with your own.
These timers are essential for the debounce logic. They ensure we only act on a cheap slot starting or stopping after its state has been stable for a few minutes, preventing reactions to sensor "flapping".
- Navigate to Settings > Devices & Services > Helpers.
- Click Create Helper and choose Timer.
- Name: Octopus Slot On Stability
- Duration: 00:05:00 (5 minutes). You can adjust this time if you wish.
- Click Create.
- Create a second Timer helper.
- Name: Octopus Slot Off Stability
- Duration: 00:05:00 (5 minutes).
You will create five automations in total. For each one, go to Settings > Automations & Scenes, click Create Automation, select Create new automation, then click the three-dots menu in the top-right and select Edit in YAML.
Purpose: This automation's only job is to watch the raw Octopus sensor. When the sensor's state changes, this automation starts the relevant 5-minute stability timer and cancels the other one.
alias: 'System: Watch Octopus Sensor State'
description: 'Starts and stops stability timers based on the raw sensor state.'
trigger:
- platform: state
entity_id: binary_sensor.octopus_energy_intelligent_dispatching
action:
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.octopus_energy_intelligent_dispatching
state: 'on'
sequence:
- service: timer.start
target:
entity_id: timer.octopus_slot_on_stability
- service: timer.cancel
target:
entity_id: timer.octopus_slot_off_stability
- conditions:
- condition: state
entity_id: binary_sensor.octopus_energy_intelligent_dispatching
state: 'off'
sequence:
- service: timer.start
target:
entity_id: timer.octopus_slot_off_stability
- service: timer.cancel
target:
entity_id: timer.octopus_slot_on_stability
mode: singlePurpose: This automation runs only after the "On Stability" timer has finished. It confirms the cheap slot is still active and then sets the Powerwall reserve to 100%.
alias: 'Powerwall: Act on Stable On State'
description: 'When the ON timer finishes, confirms the state and sets reserve to 100%.'
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.octopus_slot_on_stability
condition:
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.octopus_energy_intelligent_dispatching
state: 'on'
- condition: time
after: '05:30:00'
before: '23:30:00'
- condition: state
entity_id: select.teslapowerwall_site_mode
state: 'backup'
- condition: not
conditions:
- condition: template
value_template: "{{ states('number.teslapowerwall_backup_reserve') | int == 100 }}"
action:
- service: number.set_value
target:
entity_id: number.teslapowerwall_backup_reserve
data:
value: 100
mode: singlePurpose: This automation runs only after the "Off Stability" timer has finished. It confirms the cheap slot is still over and then sets the Powerwall reserve back to your 20% floor.
alias: 'Powerwall: Act on Stable Off State'
description: 'When the OFF timer finishes, confirms the state and sets reserve to 20%.'
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.octopus_slot_off_stability
condition:
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.octopus_energy_intelligent_dispatching
state: 'off'
- condition: state
entity_id: select.teslapowerwall_site_mode
state: 'backup'
- condition: not
conditions:
- condition: template
value_template: "{{ states('number.teslapowerwall_backup_reserve') | int == 20 }}"
action:
- service: number.set_value
target:
entity_id: number.teslapowerwall_backup_reserve
data:
value: 20
mode: singlePurpose: This handles the evening edge case. It runs instantly at 23:30 and, if a cheap slot is active at that moment, it lowers the reserve to 20% to allow Tesla's native logic to take over charging.
alias: 'Powerwall: Set Nightly Reserve Floor (Only if Slot is Active)'
description: >-
If a cheap slot is active at 23:30, ensures the backup reserve is set to 20%.
trigger:
- platform: time
at: '23:30:00'
condition:
- condition: and
conditions:
- condition: state
entity_id: select.teslapowerwall_site_mode
state: 'backup'
- condition: state
entity_id: binary_sensor.octopus_energy_intelligent_dispatching
state: 'on'
- condition: not
conditions:
- condition: template
value_template: "{{ states('number.teslapowerwall_backup_reserve') | int == 20 }}"
action:
- service: number.set_value
target:
entity_id: number.teslapowerwall_backup_reserve
data:
value: 20
mode: singlePurpose: This handles the morning edge case. It runs instantly at 05:30 and, if a cheap slot that started overnight is still active, it captures the Powerwall's current charge level and sets that as the new reserve target.
alias: 'Powerwall: Manage Morning Transition Slots'
description: >-
If a cheap slot is active at 05:30, sets reserve to the current charge level.
trigger:
- platform: time
at: '05:30:00'
condition:
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.octopus_energy_intelligent_dispatching
state: 'on'
- condition: state
entity_id: select.teslapowerwall_site_mode
state: 'backup'
action:
- service: number.set_value
target:
entity_id: number.teslapowerwall_backup_reserve
data:
value: "{{ states('sensor.powerwall_charge') | int }}"
mode: singleThis complete system provides robust and intelligent control:
- The Watcher automation observes the sensor and starts timers, ignoring brief changes.
- The Stable State automations act on the timers, ensuring API calls are only made for legitimate, sustained state changes.
- The Time-Based automations handle the critical transitions between daytime and nighttime schedules instantly, ensuring there are no conflicts with the Powerwall's native logic.
site_mode can also be Time-Based Control