Skip to content

Commit d617a49

Browse files
authored
Evcc opt wrapper (#138)
* first working draft of second source for optimization - evcc opt * feat: update README and configuration for EOS server source and port settings - fixes eos intrerface tests * feat: update README and UI to support evcc optimization backend and display experimental mode banner * refactor: remove hardcoded base URL for EVCC optimization request * feat: Add OptimizationInterface for backend optimization management - Introduced OptimizationInterface class to serve as an abstraction layer for interacting with EOS and EVCC Opt optimization backends. - Implemented methods for optimization, control data examination, and scheduling management. - Added functionality to calculate the next optimal run time and retrieve EOS version from the backend. - Created unit tests for OptimizationInterface, covering backend selection, response handling, and error management. - Included a dummy backend for testing integration without actual backend dependencies. * refactor: remove obsolete test module for EosInterface scheduling algorithm
1 parent ff06c12 commit d617a49

File tree

13 files changed

+1560
-880
lines changed

13 files changed

+1560
-880
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
__pycache__/
55
src/config.bak.yaml
66
src/config.yaml
7-
src/json/optimize_request.json
8-
src/json/optimize_response.json
7+
src/json/*.json
98
src/interfaces/__pycache__
109
src/interfaces/config/battery_config.json
1110
src/interfaces/config/timeofuse_config.json

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# EOS Connect
22

33
**EOS Connect** is an open-source tool for intelligent energy management and optimization.
4-
It connects to various smart home platforms (like Home Assistant and OpenHAB) to monitor, forecast, and control your energy flows.
5-
EOS Connect fetches real-time and forecast data (PV, load, prices), processes it via the [EOS (Energy Optimization System)](https://github.com/Akkudoktor-EOS/EOS), and automatically controls devices (such as Fronius inverters or batteries supported by [evcc](https://docs.evcc.io/docs/devices/meters)) to optimize your energy usage and costs.
4+
It supports two optimization backends: the full-featured Akkudoktor EOS (default) and the lightweight EVCC Opt (optional, very fast).
5+
EOS Connect fetches real-time and forecast data, processes it via your chosen optimizer, and controls devices to optimize your energy usage and costs.
66

77
**Key Features:**
88
- **Automated Energy Optimization:**
@@ -159,8 +159,10 @@ Get up and running with EOS Connect in just a few steps!
159159
### 2. Install via Home Assistant Add-on
160160

161161
- Add the [ohAnd/ha_addons](https://github.com/ohAnd/ha_addons) repository to your Home Assistant add-on store.
162-
- [if needed] Add the [Duetting/ha_eos_addon](https://github.com/Duetting/ha_eos_addon) (or [thecem/ha_eos_addon](https://github.com/thecem/ha_eos_addon)) repository to your Home Assistant add-on store.
163-
- Install both the **EOS Add-on** and the **EOS Connect Add-on**.
162+
- select your preferred optimization backend:
163+
- [if needed] Add the [Duetting/ha_eos_addon](https://github.com/Duetting/ha_eos_addon) (or [thecem/ha_eos_addon](https://github.com/thecem/ha_eos_addon)) repository to your Home Assistant add-on store.
164+
- [if needed] Add [thecem/hassio-evopt](https://github.com/thecem/hassio-evopt) repository to your Home Assistant add-on store. ([found here](https://github.com/evcc-io/evcc/discussions/23213#3-optimizer-im-home-assistant-ha-addon-nutzen))
165+
- Install both the **EOS Add-on** (or **evcc opt**) and the **EOS Connect Add-on**.
164166
- Configure both add-ons via the Home Assistant UI.
165167
- Start both add-ons.
166168
The EOS Connect web dashboard will be available at [http://homeassistant.local:8081](http://homeassistant.local:8081) (or your HA IP).

src/CONFIG_README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,14 @@ A default config file will be created with the first start, if there is no `conf
7777

7878
### EOS Server Configuration
7979

80+
- **`eos.source`**:
81+
EOS server source - eos_server, evcc_opt, default (default uses eos_server)
82+
8083
- **`eos.server`**:
81-
EOS server address (e.g., `192.168.1.94`). (Mandatory)
84+
EOS or evcc opt server address (e.g., `192.168.1.94`). (Mandatory)
8285

8386
- **`eos.port`**:
84-
Port for the EOS server. Default: `8503`. (Mandatory)
87+
port for EOS server (8503) or evcc opt server (7050) - default: `8503` (Mandatory)
8588

8689
- **`timeout`**:
8790
Timeout for EOS optimization requests, in seconds. Default: `180`. (Mandatory)
@@ -389,6 +392,7 @@ load:
389392
additional_load_1_consumption: 1500 # consumption for additional load 1 in Wh - default: 0 (If not needed set to `additional_load_1_sensor: ""`)
390393
# EOS server configuration
391394
eos:
395+
source: eos_server # EOS server source - eos_server, evcc_opt, default (default uses eos_server)
392396
server: 192.168.1.94 # EOS server address
393397
port: 8503 # port for EOS server - default: 8503
394398
timeout: 180 # timeout for EOS optimize request in seconds - default: 180
@@ -470,6 +474,7 @@ load:
470474
car_charge_load_sensor: Wallbox_Power # item / entity for wallbox power data in watts. (If not needed, set to `load.car_charge_load_sensor: ""`)
471475
# EOS server configuration
472476
eos:
477+
source: eos_server # EOS server source - eos_server, evcc_opt, default (default uses eos_server)
473478
server: 192.168.1.94 # EOS server address
474479
port: 8503 # port for EOS server - default: 8503
475480
timeout: 180 # timeout for EOS optimize request in seconds - default: 180

src/config.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ def create_default_config(self):
5555
),
5656
"eos": CommentedMap(
5757
{
58-
"server": "192.168.100.100", # Default EOS server address
59-
"port": 8503, # Default port for EOS server
58+
"source": "default", # EOS server source - eos_server, evcc_opt, default
59+
"server": "192.168.100.100", # EOS or evcc opt server address
60+
"port": 8503, # port for EOS server (8503) or evcc opt server (7050) - default: 8503
6061
"timeout": 180, # Default timeout for EOS optimize request
6162
}
6263
),
@@ -194,9 +195,14 @@ def create_default_config(self):
194195
config.yaml_set_comment_before_after_key(
195196
"eos", before="EOS server configuration"
196197
)
197-
config["eos"].yaml_add_eol_comment("EOS server address", "server")
198198
config["eos"].yaml_add_eol_comment(
199-
"port for EOS server - default: 8503", "port"
199+
"EOS server source - eos_server, evcc_opt, default (default uses eos_server)",
200+
"source",
201+
)
202+
config["eos"].yaml_add_eol_comment("EOS or evcc opt server address", "server")
203+
config["eos"].yaml_add_eol_comment(
204+
"port for EOS server (8503) or evcc opt server (7050) - default: 8503",
205+
"port",
200206
)
201207
config["eos"].yaml_add_eol_comment(
202208
"timeout for EOS optimize request in seconds - default: 180", "timeout"

src/eos_connect.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from interfaces.inverter_fronius import FroniusWR
2323
from interfaces.inverter_fronius_v2 import FroniusWRV2
2424
from interfaces.evcc_interface import EvccInterface
25-
from interfaces.eos_interface import EosInterface
25+
from interfaces.optimization_interface import OptimizationInterface
2626
from interfaces.price_interface import PriceInterface
2727
from interfaces.mqtt_interface import MqttInterface
2828
from interfaces.pv_interface import PvInterface
@@ -106,11 +106,11 @@ def formatTime(self, record, datefmt=None):
106106
LOGLEVEL,
107107
)
108108
# initialize eos interface
109-
eos_interface = EosInterface(
110-
eos_server=config_manager.config["eos"]["server"],
111-
eos_port=config_manager.config["eos"]["port"],
109+
eos_interface = OptimizationInterface(
110+
config=config_manager.config["eos"],
112111
timezone=time_zone,
113112
)
113+
114114
# initialize base control
115115
base_control = BaseControl(config_manager.config, time_zone)
116116
# initialize the inverter interface
@@ -747,7 +747,7 @@ def __run_optimization_loop(self):
747747
mqtt_interface.update_publish_topics(
748748
{"optimization/state": {"value": self.get_current_state()["request_state"]}}
749749
)
750-
optimized_response, avg_runtime = eos_interface.eos_set_optimize_request(
750+
optimized_response, avg_runtime = eos_interface.optimize(
751751
json_optimize_input, config_manager.config["eos"]["timeout"]
752752
)
753753
# Store the runtime for use in sleep calculation
@@ -1364,6 +1364,9 @@ def get_controls():
13641364
"currency_minor_unit": currency_minor_unit,
13651365
},
13661366
"state": optimization_scheduler.get_current_state(),
1367+
"used_optimization_source": config_manager.config.get("eos", {}).get(
1368+
"source", "eos_server"
1369+
),
13671370
"eos_connect_version": __version__,
13681371
"timestamp": datetime.now(time_zone).isoformat(),
13691372
"api_version": "0.0.2",

0 commit comments

Comments
 (0)