โ ๏ธ DEVELOPMENT STATUS This custom component is currently under active development and has not been fully tested in production environments. Use at your own risk and please report any issues you encounter.
A comprehensive Home Assistant integration for intelligent battery management and energy trading optimization. Automatically buy energy when prices are low, sell when prices are high, and maximize solar energy utilization.
- Arbitrage Detection - Automatically identifies profitable buy-low, sell-high opportunities
- Dynamic Pricing - Integrates with Nord Pool (or any price sensor) for real-time price tracking
- 15-Minute Slot Support - Works with modern 15-minute energy markets
- Profit Optimization - Calculates optimal charging and discharging schedules
- Optional Force Charging - Toggle automatic charging during cheap hours (disabled by default for solar-only setups)
- Smart Discharging - Sells excess solar/battery during highest-price 15-min slots (enabled by default)
- Battery Protection - Respects minimum battery levels
- Solar Override - Allows discharge even at low battery when solar is generating
- Designed for Solar Users - Default settings prioritize selling excess solar, not grid charging
- Peak Price Selling - Automatically exports during high-price periods
- Flexible Modes - Toggle charging/discharging independently via switches
- Minimum Battery Levels - Prevents over-discharge
- Price Thresholds - Won't sell at a loss
- Export Management - Smart grid export based on profitability
- Automation-Friendly Switches - Full control via Home Assistant automations
- Energy Cost Optimization - Reduce electricity bills by buying at cheapest times
- Revenue Generation - Earn money by selling energy at peak prices
- Battery Longevity - Smart charging/discharging patterns extend battery life
- Solar Maximization - Optimizes solar energy usage and storage
- Grid Independence - Reduces reliance on grid during expensive periods
Required:
- Nord Pool Integration - This integration requires the Nord Pool integration to be installed and configured first
- Install via HACS or manually
- Must have at least one Nord Pool price sensor with
raw_todayattribute
Optional but Recommended:
- Sungrow Integration - For automatic inverter detection and configuration
- Install Nord Pool integration first (if not already installed)
- In HACS โ Integrations โ Search for "nordpool"
- Install and configure with your electricity area
- Click the badge above to add this repository to HACS, OR manually add it:
- Open HACS in Home Assistant
- Click on
Integrations - Click the three dots in the top right corner
- Select
Custom repositories - Add this repository URL:
https://github.com/Tsopic/battery_energy_trading - Select category:
Integration - Click
Add
- Click
+ Explore & Download Repositories - Search for
Battery Energy Trading - Click
Download - Restart Home Assistant
- Ensure Nord Pool integration is installed first
- Download the latest release
- Extract and copy
custom_components/battery_energy_tradingto your Home Assistantcustom_componentsdirectory - Restart Home Assistant
- Go to
SettingsโDevices & Services - Click
+ Add Integration - Search for
Battery Energy Trading - If Nord Pool is not detected, setup will be blocked with an error message - install Nord Pool first
๐ Automatic Sungrow Detection: If you have the Sungrow integration installed, the setup will:
- Automatically detect your Sungrow inverter model (SH5.0RT, SH10RT, etc.)
- Auto-configure charge/discharge rates based on inverter specifications
- Pre-fill battery level, capacity, and solar power entities
- Just confirm the detected settings and you're done!
Manual Configuration: 4. Configure the required entities:
- Nord Pool Entity - Your electricity price sensor (e.g.,
sensor.nordpool_kwh_ee_eur_3_10_022) - Battery Level Entity - Battery charge percentage (e.g.,
sensor.battery_level) - Battery Capacity Entity - Battery capacity in kWh (e.g.,
sensor.battery_capacity) - Solar Power Entity (optional) - Current solar production (e.g.,
sensor.power_production_now)
After setup, configure the following parameters via the dashboard or pre-built dashboard:
| Parameter | Description | Default | Range |
|---|---|---|---|
| Forced Discharge Hours | Max hours to discharge (0=unlimited) | 2 | 0-24 hours |
| Minimum Export Price | Minimum price to allow export | 0.0125 EUR | -0.3 to 0.1 EUR |
| Minimum Forced Sell Price | Minimum price for forced discharge | 0.3 EUR | 0 to 0.5 EUR |
| Maximum Force Charge Price | Maximum price for forced charging | 0.0 EUR | -0.5 to 0.2 EUR |
| Force Charging Hours | Number of cheapest hours to charge | 1 | 0-24 hours |
| Force Charge Target | Target battery % for force charging | 70% | 0-100% |
| Minimum Battery Level | Minimum battery % for discharge | 25% | 10-50% |
| Minimum Solar Threshold | Solar power to override battery limits | 500 W | 0-5000 W |
| Battery Discharge Rate | Max discharge power (auto-detected) | 5 kW | 1-20 kW |
| Battery Charge Rate | Max charge power (auto-detected) | 5 kW | 1-20 kW |
The integration provides the following entities for your dashboard:
- Enable Forced Charging - Toggle automatic grid charging (default: OFF)
- Enable Forced Discharge - Toggle peak-time selling (default: ON)
- Enable Export Management - Toggle smart export control (default: ON)
- Discharge Time Slots - Selected 15-min slots with energy amounts and prices
- Shows:
17:00-17:15 (1.2kWh @โฌ0.452), 18:00-18:15 (1.2kWh @โฌ0.428) - Attributes:
slot_count,total_energy_kwh,estimated_revenue_eur, detailedslotsarray
- Shows:
- Charging Time Slots - Cheapest 15-min slots for charging (if enabled)
- Shows energy amounts, prices, and estimated costs
- Arbitrage Opportunities - Profitable charge/discharge windows with profit calculations
- Automation Status - Real-time automation execution status
- States:
Idle,Active - Discharging,Active - Charging,Unknown - Attributes:
last_action,last_action_time,next_scheduled_action
- States:
- Forced Discharge Active - Currently selling at peak prices
- Cheapest Hours Active - Currently in cheap charging period (only if charging enabled)
- Low Price Mode - Price below export threshold
- Export Profitable - Exporting would be profitable
- Battery Below 15% - Low battery warning
- Solar Power Available - Sufficient solar production (>500W)
- Forced Discharge Hours - Max hours to discharge (0-24, default: 2)
- 0 = Unlimited: Sell during ALL profitable peak slots
- 1-24: Limit discharge to X hours at highest prices
- Minimum Export Price - Minimum to allow export (default: โฌ0.0125)
- Minimum Forced Sell Price - Minimum for discharge (default: โฌ0.30)
- Maximum Force Charge Price - Maximum for charging (default: โฌ0.00)
- Force Charging Hours - How many slots to charge (0-24, default: 1)
- Force Charge Target - Target battery % (0-100%, default: 70%)
- Minimum Battery Level - Min % for discharge (10-50%, default: 25%)
- Minimum Solar Threshold - Solar power override (0-5000W, default: 500W)
- Battery Discharge Rate - Max discharge power (1-20kW, auto-detected for Sungrow)
- Battery Charge Rate - Max charge power (1-20kW, auto-detected for Sungrow)
This integration is designed to work with:
- Nord Pool Integration - Or any electricity price sensor
- Battery Systems - SolarEdge, Huawei, Tesla, Sungrow, etc.
- Solar Inverters - Any system providing power production data
- Home Assistant Automations - Full automation support
Automatic setup for Sungrow SHx Modbus Integration!
โจ One-Click Auto-Configuration
If you have the Sungrow integration already installed:
- Add Battery Energy Trading integration
- Auto-detection will identify:
- Your inverter model (SH5.0RT, SH6.0RT, SH8.0RT, SH10RT, etc.)
- Optimal charge/discharge rates for your specific model
- Battery level, capacity (read dynamically), and solar power sensors
- Click "Use Auto-Detection" - that's it!
The integration dynamically reads your actual battery capacity from the Sungrow system, so it works with any Sungrow-compatible battery configuration.
Services:
# Manually re-sync Sungrow parameters if you upgrade your inverter
service: battery_energy_trading.sync_sungrow_parameters
# Generate ready-to-use automation scripts for your configuration
service: battery_energy_trading.generate_automation_scripts
# Force immediate recalculation of charge/discharge slots
service: battery_energy_trading.force_refresh๐ Full Sungrow Integration Guide - Complete setup with automation examples
๐ค Automatic Trading Setup Guide - One-click automation generation
Solar-Only Mode (Default): Sell excess solar at peak prices, never charge from grid:
# Forced Charging is OFF by default
# Forced Discharge is ON by default
# Just let the integration manage discharge automaticallyEnable Grid Charging During Cheap Hours:
automation:
- alias: "Enable Charging in Winter"
trigger:
- platform: template
value_template: "{{ now().month in [11, 12, 1, 2] }}"
action:
- service: switch.turn_on
target:
entity_id: switch.battery_energy_trading_enable_forced_chargingDisable Discharge on Cloudy Days:
automation:
- alias: "Disable Discharge When Cloudy"
trigger:
- platform: numeric_state
entity_id: sensor.solar_forecast_today
below: 10 # kWh
action:
- service: switch.turn_off
target:
entity_id: switch.battery_energy_trading_enable_forced_dischargeNotification When Selling:
automation:
- alias: "Notify High Price Period"
trigger:
- platform: state
entity_id: binary_sensor.battery_energy_trading_forced_discharge
to: 'on'
action:
- service: notify.mobile_app
data:
title: "Energy Trading"
message: "High price period - selling energy now!"A complete dashboard is included in the dashboards/ directory!
- Go to Settings โ Dashboards
- Click + ADD DASHBOARD
- Choose New dashboard from scratch
- Click โ๏ธ Edit โ โฎ โ Raw configuration editor
- Copy contents from
dashboards/battery_energy_trading_dashboard.yaml - Paste and SAVE
The pre-built dashboard includes:
๐ 13 Organized Sections:
- Current operation status
- Automation status and management
- Operation mode controls (switches)
- Discharge schedule with revenue estimates
- Charging schedule with cost estimates
- Arbitrage opportunities
- Price threshold configuration
- Battery protection settings
- Charging configuration
- Solar override settings
- Discharge configuration
- Battery health monitoring
- Quick-action service buttons
See dashboards/README.md for full documentation and customization guide.
# Quick preview card
type: entities
title: Battery Energy Trading
entities:
- entity: sensor.battery_energy_trading_discharge_time_slots
- entity: binary_sensor.battery_energy_trading_forced_discharge
- entity: switch.battery_energy_trading_enable_forced_discharge
- entity: number.battery_energy_trading_min_forced_sell_price- Price Analysis - Monitors Nord Pool prices throughout the day
- Opportunity Detection - Identifies price spreads > 100 points (configurable)
- Optimal Scheduling - Calculates best 2-hour charging and 1-hour discharge windows
- Execution - Automatically triggers charge/discharge based on schedule
- Never discharges below configured minimum level (default 25%)
- Solar override allows discharge when solar > 500W (configurable)
- Emergency charge triggers below 15% battery
- Blocks export when price < minimum threshold
- Automatically enables export during profitable periods
- Prevents selling at a loss
- Complete Documentation - Full documentation index
- ๐ค Automatic Trading Setup - One-click automation generation
- Sungrow Integration Guide - Sungrow inverter setup and automations
- Dashboard Guide - Pre-built dashboard setup
- Development Guide - Architecture and contributing
- Testing Guide - Running and writing tests
- Changelog - Version history
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Originally inspired by battery management and energy trading automation patterns.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Home Assistant Community: Community Forum
If you find this integration useful, consider:
