### Configure Service API Charge Start Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md Example configuration for triggering a Home Assistant service when charging starts. ```yaml charge_start_service: service: switch.turn_off entity_id: "switch.sunsynk_inverter_use_timer" ``` -------------------------------- ### Configure Kraken in apps.yaml Source: https://github.com/springfall2008/batpred/blob/main/docs/components.md Examples for configuring different authentication methods and account setups for EDF and E.ON Next. ```yaml kraken_provider: edf kraken_account_id: A-12345678 kraken_auth_method: api_key kraken_key: !secret kraken_key ``` ```yaml kraken_provider: eon kraken_account_id: A-12345678 kraken_auth_method: email kraken_email: myemail@example.com kraken_password: !secret kraken_password ``` ```yaml kraken_provider: eon kraken_account_id: A-12345678 # import account kraken_export_account_id: A-87654321 # export account (different number) kraken_auth_method: email kraken_email: myemail@example.com kraken_password: !secret kraken_password ``` -------------------------------- ### Configure MCP Server Client in VSCode Source: https://github.com/springfall2008/batpred/blob/main/docs/components.md Example JSON configuration for connecting to the Predbat MCP server from VSCode. Ensure the URL and Bearer token match your Predbat setup. ```json { "servers": { "predbat-mcp": { "url": "http://homeassistant.local:8199/mcp", "type": "http", "description": "Predbat Model Context Protocol Server", "headers": { "Authorization" : "Bearer predbat_mcp_secret", }, } }, "inputs": [] } ``` -------------------------------- ### Example: Setting an Export Rate Override Source: https://github.com/springfall2008/batpred/blob/main/docs/manual-api.md This example demonstrates how to set a specific export rate override using the manual API. The format is similar to URL query parameters. ```text rates_export_override?start=17:00:00&end=19:00:00&rate=0 ``` -------------------------------- ### List Configuration Example Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md Demonstrates how to configure a list of values, such as for `car_charging_now_response`. Each item in the list must be indented correctly. ```yaml car_charging_now_response: - 'yes' - 'on' ``` -------------------------------- ### Car Charging Automation Example Source: https://context7.com/springfall2008/batpred/llms.txt Example Home Assistant automation to control EV charging based on Predbat slots. ```APIDOC ## Car Charging Automation Example Automation to control EV charging based on Predbat slots. ```yaml alias: Car Charging Control description: "Start/stop car charging based on Predbat slots" triggers: - trigger: state entity_id: - binary_sensor.predbat_car_charging_slot actions: - choose: - conditions: - condition: state entity_id: binary_sensor.predbat_car_charging_slot state: "on" sequence: - service: select.select_option data: option: Eco+ target: entity_id: select.myenergi_zappi_charge_mode - conditions: - condition: state entity_id: binary_sensor.predbat_car_charging_slot state: "off" sequence: - service: select.select_option data: option: Stopped target: entity_id: select.myenergi_zappi_charge_mode mode: single ``` ``` -------------------------------- ### Configure days_previous for weekly average Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md Example configuration to average house load over the last week. ```yaml days_previous: - 2 - 3 - 4 - 5 - 6 - 7 - 8 ``` -------------------------------- ### Serve MkDocs Documentation Source: https://github.com/springfall2008/batpred/blob/main/CLAUDE.md Command to start a local live preview server for the project's documentation, typically accessible at http://localhost:8000. ```bash mkdocs serve ``` -------------------------------- ### Monitor ML Training Logs Source: https://github.com/springfall2008/batpred/blob/main/docs/load-ml.md Example output from the Predbat logs showing the initial training sequence and validation metrics. ```text ML Component: Starting initial training ML Predictor: Curriculum training - 4 passes, window 7.0→10.0 days + final full pass (full period) ML Predictor: Training complete, final val_mae=0.0051 kWh val_bias=+0.0010 kWh (+2.0%) ML Predictor: AR rollout over holdout: ar_mae=0.0135 kWh ar_bias=-0.0030 kWh (-6.2%) [drift vs teacher-forced: +0.0031 kWh] ML Component: Initial training completed, validation MAE=0.0051 kWh ``` -------------------------------- ### Configure Car Charging Parameters Source: https://github.com/springfall2008/batpred/blob/main/docs/car-charging.md Example configuration for car battery size, charge limit, and state-of-charge sensors in apps.yaml. ```yaml #car_charging_battery_size: # - 75 #car_charging_limit: # - 're:number.tsunami_charge_limit' #car_charging_soc: # - 're:sensor.tsunami_battery' ``` -------------------------------- ### Example: Disabling All Overrides Source: https://github.com/springfall2008/batpred/blob/main/docs/manual-api.md To clear all active overrides and revert to default settings, use the 'off' command. ```text off ``` -------------------------------- ### Configure days_previous for two-day lookback Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md Example configuration using historical data from two days prior. ```yaml days_previous: - 2 ``` -------------------------------- ### Example: Overriding a Single Inverter Limit Entry Source: https://github.com/springfall2008/batpred/blob/main/docs/manual-api.md This example shows how to override a specific item within a list, such as the inverter limit at index 0. To disable this specific override, enclose it in square brackets. ```text inverter_limit(0)=4000 ``` ```text [inverter_limit(0)=4000] ``` -------------------------------- ### Timezone Configuration Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md Example of setting the timezone for Predbat. Ensure the timezone value is valid for your system. ```yaml timezone: Europe/London ``` -------------------------------- ### Configure days_previous for multi-day averaging Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md Example configuration for averaging historical load from the same day over the last two weeks. ```yaml days_previous: - 7 - 14 ``` -------------------------------- ### Workaround for select/select_option data failed warning Source: https://github.com/springfall2008/batpred/blob/main/docs/faq.md Add a dummy selector to configuration.yaml to resolve 'select/select_option data failed' warnings when Predbat starts before actual selectors are available. This ensures the service call has a valid entity to interact with. ```yaml template: - select: - name: "simple_select" state: "{{ states('input_select.my_input') }}" # Current value options: "{{ ['Option 1', 'Option 2', 'Option 3'] }}" # Available options select_option: - service: input_select.select_option target: entity_id: input_select.my_input data: option: "{{ option }}" ``` -------------------------------- ### Run Predbat Tests Source: https://github.com/springfall2008/batpred/blob/main/CLAUDE.md Scripts for setting up the environment and running all tests, including options for quick runs, specific tests, keyword filtering, and listing available tests. Also includes coverage analysis. ```bash cd coverage source setup.csh ``` ```bash ./run_all ``` ```bash ./run_all --quick ``` ```bash ./run_all --test basic_rates ``` ```bash ./run_all --test basic_rates --test units ``` ```bash ./run_all -k octopus_ ``` ```bash ./run_all --list ``` ```bash ./run_cov --quick # Then open htmlcov/index.html ``` -------------------------------- ### Example GivEnergy Battery Charge Curve Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md An example of a manually configured battery charge power curve for a GivEnergy 9.5kWh battery, showing reduced charging rate at higher SoC percentages. ```yaml battery_charge_power_curve: 91 : 0.91 92 : 0.81 ``` -------------------------------- ### GET /api/state Source: https://github.com/springfall2008/batpred/blob/main/docs/rest_api.md Retrieves the state of a specified entity or all entities if none is specified. ```APIDOC ## GET /api/state ### Description Retrieves the state of a specified entity. If no entity_id is provided, all entities are returned. ### Method GET ### Endpoint /api/state ### Query Parameters - **entity_id** (string) - Optional - The specific entity to get the state for. ### Response #### Success Response (200) - **state** (string) - The current state of the entity. - **attributes** (object) - A JSON object containing attributes of the entity, such as `friendly_name`, `detail`, `icon`, and `last_updated`. #### Response Example ```json { "state": "Demand", "attributes": {"friendly_name": "Status", "detail": "", "icon": "mdi:information", "last_updated": "2025-02-23 20:49:57.855074"} } ``` ``` -------------------------------- ### Create a Custom Predbat Plugin Source: https://context7.com/springfall2008/batpred/llms.txt Demonstrates the structure for a custom plugin by inheriting from PredBatPlugin and implementing lifecycle hooks. ```python # Example plugin: plugins/metrics_plugin.py from plugin_system import PredBatPlugin class MetricsPlugin(PredBatPlugin): """Custom metrics collector plugin.""" def on_init(self, predbat): """Called when plugin system initializes.""" self.predbat = predbat self.log("Metrics plugin initialized") def on_update(self, predbat): """Called during each update cycle.""" status = predbat.get_state("predbat.status") soc = predbat.get_state("predbat.soc_kw_best") # Send to external metrics system self.send_metrics(status, soc) def on_web_start(self, predbat, app): """Called when web interface starts - register endpoints.""" @app.route('/metrics') def metrics_endpoint(): return self.get_prometheus_metrics() def on_shutdown(self, predbat): """Called during graceful shutdown.""" self.log("Metrics plugin shutting down") ``` -------------------------------- ### Define battery_discharge_power_curve_default in apps.yaml Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md Example of a fallback discharging curve used when auto-detection fails or is unavailable. ```yaml battery_discharge_power_curve_default: 10 : 0.85 9 : 0.75 8 : 0.65 7 : 0.55 6 : 0.45 5 : 0.35 4 : 0.25 3 : 0.15 2 : 0.10 1 : 0.05 ``` -------------------------------- ### Define battery_charge_power_curve_default in apps.yaml Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md Example of a fallback charging curve used when auto-detection fails or is unavailable. ```yaml battery_charge_power_curve_default: 91 : 0.91 92 : 0.81 93 : 0.71 94 : 0.62 95 : 0.52 96 : 0.43 97 : 0.33 98 : 0.24 99 : 0.24 100 : 0.24 ``` -------------------------------- ### Basic Predbat Configuration Source: https://context7.com/springfall2008/batpred/llms.txt Defines core Predbat settings including timezone, currency, Home Assistant connection, forecast duration, and historical data usage for plan calculations. Ensure YAML indentation is exactly 2 spaces. ```yaml pred_bat: module: predbat class: PredBat # Basic settings prefix: predbat timezone: Europe/London currency_symbols: - '£' - 'p' # Home Assistant connection (for Docker deployments) ha_url: 'http://homeassistant.local:8123' ha_key: !secret ha_key # Forecast duration forecast_hours: 48 # Historical load days to average days_previous: - 2 - 3 - 4 - 5 - 6 - 7 - 8 # Threading for plan calculations threads: auto ``` -------------------------------- ### Manual API Overrides Source: https://context7.com/springfall2008/batpred/llms.txt Demonstrates how to dynamically override apps.yaml settings using Home Assistant service calls. ```yaml # Service call to set rate override action: select.select_option target: entity_id: select.predbat_manual_api data: option: "rates_export_override?start=17:00:00&end=19:00:00&rate=0" # Override inverter limit action: select.select_option target: entity_id: select.predbat_manual_api data: option: "inverter_limit(0)=4000" # Override load scaling for a period action: select.select_option target: entity_id: select.predbat_manual_api data: option: "rates_import_override?date=2024-01-21&start=17:30:00&end=18:30:00&load_scaling=0.8" # Disable specific override (square brackets) action: select.select_option target: entity_id: select.predbat_manual_api data: option: "[inverter_limit(0)=4000]" # Clear all overrides action: select.select_option target: entity_id: select.predbat_manual_api data: option: "off" ``` -------------------------------- ### Retrieve entity state via GET Source: https://github.com/springfall2008/batpred/blob/main/docs/rest_api.md Fetches the state and attributes of a specific entity or all entities. ```json { "state": "Demand", "attributes": {"friendly_name": "Status", "detail": "", "icon": "mdi:information", "last_updated": "2025-02-23 20:49:57.855074"} } ``` -------------------------------- ### Enable Template Mode Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md Initially set to `true`, this prevents Predbat from operating until configuration is complete. Delete or comment out this line once `apps.yaml` is fully configured. ```yaml template: true ``` -------------------------------- ### Custom Service Definition with Parameters Source: https://github.com/springfall2008/batpred/blob/main/docs/inverter-setup.md Defines a Home Assistant service with specific parameters. Use placeholders like `{device_id}` and `{power}` which Predbat will populate. This allows for fine-grained control over service calls. ```yaml charge_start_service: - service: my_charge_start_service device_id: "{device_id}" power: "{power}" soc: "{target_soc}" charge_start_time: "{charge_start_time}" charge_end_time: "{charge_end_time}" ``` -------------------------------- ### Predbat Module Definition Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md This is the mandatory module definition at the start of the `apps.yaml` file. It specifies the module and class Predbat will use. ```yaml pred_bat: module: predbat class: PredBat ``` -------------------------------- ### Configure LuxPower Integration for Freeze Charging Source: https://github.com/springfall2008/batpred/blob/main/docs/inverter-setup.md Modify your `apps.yaml` to enable `support_charge_freeze` and uncomment `charge_freeze_service` for Predbat to control LuxPower inverters during freeze charging. ```yaml support_charge_freeze: True charge_freeze_service: - automation.turn_on target: entity_id: automation.luxpower_freeze_charge ``` -------------------------------- ### Configure Open-Meteo Forecast Integration Source: https://github.com/springfall2008/batpred/blob/main/docs/install.md Integrate Predbat with Open-Meteo for free, open-source solar irradiance forecasts. Configure array details including KWP, declination, azimuth, and efficiency. `open_meteo_forecast_max_age` controls data update frequency. ```yaml open_meteo_forecast: - postcode: SW1A 2AB kwp: 3.5 declination: 35 azimuth: 180 efficiency: 0.95 open_meteo_forecast_max_age: 4.0 ``` -------------------------------- ### Automate Predbat Debug Mode Shutdown Source: https://github.com/springfall2008/batpred/blob/main/docs/customisation.md An automation example that automatically disables the debug switch after 10 minutes of being enabled. ```yaml alias: "Predbat: Auto turn-off debug mode" description: "" triggers: - trigger: state entity_id: - switch.predbat_debug_enable to: "on" for: minutes: 10 conditions: [] actions: - action: script.notify_all_devices metadata: {} data: title: "INFO: Turned off Predbat debug after 10 minutes" critical: "N" url: "" message: switch.predbat_debug_enable turned off - action: switch.turn_off target: entity_id: switch.predbat_debug_enable data: {} mode: single ``` -------------------------------- ### Define Predbat Ready Toggle Helper Source: https://github.com/springfall2008/batpred/blob/main/docs/inverter-setup.md Create this input_boolean helper to prevent automation actions until LuxPower entities are fully initialized. ```yaml name: Predbat Ready entity_id: input_boolean.predbat_ready ``` -------------------------------- ### Configure Solcast API Key in apps.yaml Source: https://github.com/springfall2008/batpred/blob/main/docs/install.md Uncomment and set your Solcast API key and host in the apps.yaml file to enable direct solar forecast retrieval by Predbat. Note that this method prevents including solar production in the Home Assistant Energy dashboard. ```yaml solcast_host: 'https://api.solcast.com.au/' solcast_api_key: 'xxxx' solcast_poll_hours: 8 ``` -------------------------------- ### Configure Home Assistant Input Select and Number Entities Source: https://github.com/springfall2008/batpred/blob/main/docs/inverter-setup.md These configurations are necessary for Predbat integration and should be added to Home Assistant's configuration.yaml or set via the UI. They define user-selectable modes and adjustable rates for battery charging and discharging. ```yaml input_select: predbat_requested_mode: name: "Predbat Requested Mode" options: - "Demand" - "Charging" - "Freeze Charging" - "Discharging" - "Freeze Discharging" initial: "Demand" icon: mdi:battery-unknown input_number: charge_rate: name: Battery charge rate initial: 6950 min: 0 max: 20000 step: 1 mode: box unit_of_measurement: W discharge_rate: name: Battery discharge rate initial: 8000 min: 0 max: 20000 step: 1 mode: box unit_of_measurement: W ``` -------------------------------- ### Configure Inverter Clock Skew Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md Adjusts charge and discharge slot register settings relative to predicted start and end times. ```yaml inverter_clock_skew_start: minutes inverter_clock_skew_end: minutes ``` ```yaml inverter_clock_skew_discharge_start: minutes inverter_clock_skew_discharge_end: minutes ``` -------------------------------- ### Configure Multiple Electric Car Sensors Source: https://github.com/springfall2008/batpred/blob/main/docs/car-charging.md Example configuration for specifying multiple state-of-charge sensors when managing more than one electric vehicle. ```yaml car_charging_soc: - 'sensor.tsunami_battery' - 'sensor.toyota_XXX_battery_level' ``` -------------------------------- ### Car Charging Automation Source: https://context7.com/springfall2008/batpred/llms.txt Example Home Assistant automation that toggles EV charger modes based on Predbat charging slots. ```yaml alias: Car Charging Control description: "Start/stop car charging based on Predbat slots" triggers: - trigger: state entity_id: - binary_sensor.predbat_car_charging_slot actions: - choose: - conditions: - condition: state entity_id: binary_sensor.predbat_car_charging_slot state: "on" sequence: - service: select.select_option data: option: Eco+ target: entity_id: select.myenergi_zappi_charge_mode - conditions: - condition: state entity_id: binary_sensor.predbat_car_charging_slot state: "off" sequence: - service: select.select_option data: option: Stopped target: entity_id: select.myenergi_zappi_charge_mode mode: single ``` -------------------------------- ### Create Daily Utility Meters Source: https://github.com/springfall2008/batpred/blob/main/docs/inverter-setup.md Configures utility meter helpers to track daily energy consumption and production. Adjust source sensors based on your specific integration entities. ```yaml utility_meter: daily_home_energy_use: source: sensor.solarnet_energy_consumed name: Daily Home Energy Use cycle: daily daily_grid_draw_energy: source: sensor.solarnet_energy_real_consumed name: Daily Grid Draw Energy cycle: daily daily_grid_feed_in_energy: source: sensor.solarnet_energy_real_produced name: Daily Grid Feed-in Energy cycle: daily daily_solar_energy: source: sensor.solarnet_energy_year name: Daily Solar Energy cycle: daily ``` -------------------------------- ### Configure Solis Cloud Integration Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md Add these parameters to apps.yaml to enable the Solis Cloud integration. ```yaml solis_api_key: !secret solis_api_key solis_api_secret: !secret solis_api_secret solis_automatic: true solis_control_enable: true solis_cloud_pv_load_ignore: false ``` -------------------------------- ### Configure Predbat Load Power Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md Sets the load_power sensor in apps.yaml with a dummy '0' to satisfy validation requirements for multi-inverter setups. ```yaml load_power: - house_load_power - 0 ``` -------------------------------- ### Configure Ohme charger direct integration Source: https://github.com/springfall2008/batpred/blob/main/docs/car-charging.md Enable direct communication with Ohme chargers by providing account credentials in apps.yaml. ```yaml ohme_login: "user@domain" ohme_password: "xxxxxxxxx" ohme_automatic_octopus_intelligent: true ``` -------------------------------- ### Configure Energidataservice Integration Source: https://github.com/springfall2008/batpred/blob/main/docs/energy-rates.md Specify these in apps.yaml to enable Predbat to fetch real-time and future electricity pricing data from the Energidataservice. Point to the correct sensors for import and export rates. ```yaml metric_energidataservice_import: sensor.energi_data_service metric_energidataservice_export: sensor.energi_data_service_export ``` -------------------------------- ### Nested List Configuration Source: https://github.com/springfall2008/batpred/blob/main/docs/apps-yaml.md Example of a nested configuration item, `rates_import_override`, which is a list of dictionaries. Pay close attention to indentation for nested structures. ```yaml rates_import_override: - start: '13:00:00' end: '14:00:00' rate: 0 ```