Skip to content

Instantly share code, notes, and snippets.

@antpk
Last active September 21, 2025 14:44
Show Gist options
  • Select an option

  • Save antpk/a3bdf6047c1f64af1bfc4f9337ae657e to your computer and use it in GitHub Desktop.

Select an option

Save antpk/a3bdf6047c1f64af1bfc4f9337ae657e to your computer and use it in GitHub Desktop.
Home Assistant Setup for Tesla Powerwall & Intelligent Octopus Go

Home Assistant Setup for Tesla Powerwall & Intelligent Octopus Go

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.

Prerequisites

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.

Step 1: Create the Timer Helpers

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".

  1. Navigate to Settings > Devices & Services > Helpers.
  2. 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.
  3. Click Create.
  4. Create a second Timer helper.
    • Name: Octopus Slot Off Stability
    • Duration: 00:05:00 (5 minutes).

Step 2: Create the Automations

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.

Automation 1: System Watcher

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: single

Automation 2: Act on Stable 'On' State

Purpose: 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: single

Automation 3: Act on Stable 'Off' State

Purpose: 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: single

Automation 4: Set Nightly Reserve Floor

Purpose: 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: single

Automation 5: Manage Morning Transition Slots

Purpose: 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: single

How It All Works Together

This 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.
@antpk
Copy link
Author

antpk commented Sep 21, 2025

site_mode can also be Time-Based Control

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment