Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone and Add-on merge #334

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
03562b8
init standalone and addon merge
GeoDerp Aug 2, 2024
c31c71d
Fix check_def_loads
GeoDerp Aug 5, 2024
d1f728a
init merge config_emhass.yaml and options.json to config.json
GeoDerp Aug 18, 2024
09a33af
Configuration page init
GeoDerp Aug 27, 2024
24191d1
tweaked python test action
GeoDerp Aug 27, 2024
3910c7d
Move required data files
GeoDerp Aug 28, 2024
93d33a4
Scripts add new config.json support
GeoDerp Aug 28, 2024
fd05d0a
unitest bug fixes
GeoDerp Aug 29, 2024
e1df786
modified: .vscode/launch.json
GeoDerp Aug 29, 2024
a4cf845
Updated github actions
GeoDerp Aug 30, 2024
507f92c
Publish_docker with lowercase job
GeoDerp Aug 30, 2024
6eebe91
Fixed some pr bugs
GeoDerp Aug 30, 2024
ceb8c95
remove missed loggers
GeoDerp Aug 30, 2024
de6b929
Config.json removed most list dictionaries
GeoDerp Aug 30, 2024
c1d0a30
fix missing files in package and docker
GeoDerp Aug 31, 2024
c0284fa
adjusted share data directory
GeoDerp Aug 31, 2024
5ac3bc4
Fix some small mistakes
GeoDerp Aug 31, 2024
81d0182
Some addon specific bugs
GeoDerp Sep 1, 2024
6998a60
Some addon specific bugs
GeoDerp Sep 1, 2024
60931e1
Add yaml button in configuration page and fix web bugs
GeoDerp Sep 3, 2024
c0b2dd3
support yaml conversion of legacy and add button Tooltips
GeoDerp Sep 3, 2024
d6a3a77
support yaml conversion of legacy and add button Tooltips
GeoDerp Sep 3, 2024
998c576
Add PR comments and error handling. Add server_ip
GeoDerp Sep 7, 2024
e8f044e
Edit PR error handling, Fix bugs.
GeoDerp Sep 8, 2024
eff21b1
test_optimization adjust import
GeoDerp Sep 8, 2024
e7b2761
fix some param bugs
GeoDerp Sep 22, 2024
ead69c2
add vscode launch method to test emhass-add-on
GeoDerp Sep 23, 2024
2fd98ec
Fix continual publish and param save bugs
GeoDerp Sep 24, 2024
da00471
Docs, replace parameter names to suit
GeoDerp Oct 23, 2024
a4344a5
Docs adjust to match new methods
GeoDerp Oct 23, 2024
073e4ad
Merge branch 'master' into enhass-standalone-addon-merge
GeoDerp Oct 23, 2024
3099fd7
Docs and definitions fix small errors, update merge #335
GeoDerp Oct 23, 2024
776cb2f
Dev Container comment out podman commands
GeoDerp Oct 25, 2024
98d90c6
requirements patch fix pytz, command_line check optimization_time_ste…
GeoDerp Oct 25, 2024
cca79a1
requirement.txt revert pytz requirement change
GeoDerp Oct 25, 2024
f754cf9
forecast temp fix DST issue
GeoDerp Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .devcontainer/Dockerfile

This file was deleted.

31 changes: 15 additions & 16 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
{
"name": "EMHASS",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
"dockerfile": "../Dockerfile",
"context": "../",
"args": { "TARGETARCH": "amd64"}
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "true",
"configureZshAsDefaultShell": "true",
"installOhMyZsh": "false",
"installOhMyZshConfig": "false",
"upgradePackages": "true"
},
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
},
//"appPort": ["5000:5000"] //used to access app from external device (User discretion advised)
Expand All @@ -17,17 +25,8 @@
// Add the IDs of extensions you want installed when the container is created.
"extensions": ["ms-python.debugpy", "ms-python.python"]
}
}


// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
},

"postCreateCommand": ["pip3", "install", "requests-mock", "--break-system-packages"]

}
27 changes: 0 additions & 27 deletions .devcontainer/setup.sh

This file was deleted.

29 changes: 4 additions & 25 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,11 @@
],
"justMyCode": true,
"env": {
"CONFIG_PATH": "/workspaces/emhass/config_emhass.yaml",
"OPTIONS_PATH": "/workspaces/emhass/options.json",
"SECRETS_PATH": "/workspaces/emhass/secrets_emhass.yaml",
"DATA_PATH": "/workspaces/emhass/data/",
"LOGGING_LEVEL": "DEBUG"
}
},
{
"name": "EMHASS run ADDON",
"type": "debugpy",
"request": "launch",
"module": "emhass.web_server",
"console": "integratedTerminal",
"args": [
"--addon",
"true",
"--no_response",
"true"
],
"purpose": [
"debug-in-terminal"
],
"justMyCode": true,
"env": {
"CONFIG_PATH": "/workspaces/emhass/config_emhass.yaml",
"LEGACY_CONFIG_PATH": "/workspaces/emhass/config_emhass.yaml",
"CONFIG_PATH": "/workspaces/emhass/config.json",
"OPTIONS_PATH": "/workspaces/emhass/options.json",
"DEFAULTS_PATH": "/workspaces/emhass/data/config_defaults.json",
"ASSOCIATIONS_PATH": "/workspaces/emhass/data/associations.csv",
"SECRETS_PATH": "/workspaces/emhass/secrets_emhass.yaml",
"DATA_PATH": "/workspaces/emhass/data/",
"EMHASS_URL": "http://HAIPHERE:8123/", //change
Expand Down
3 changes: 2 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"install",
"--no-deps",
"--force-reinstall",
"--break-system-packages",
"--editable",
"."
],
Expand All @@ -29,7 +30,7 @@
"isDefault": true
},
"args": [
"install", "--force-reinstall", "."
"install", "--break-system-packages", "--force-reinstall", "."
],
"presentation": {
"echo": true,
Expand Down
94 changes: 13 additions & 81 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
## EMHASS Docker
## Docker run addon testing example:
## docker build -t emhass/docker --build-arg build_version=addon-local .
## docker build -t emhass/docker
## docker run -it -p 5000:5000 --name emhass-container -e LAT="45.83" -e LON="6.86" -e ALT="4807.8" -e TIME_ZONE="Europe/Paris" emhass/docker --url YOURHAURLHERE --key YOURHAKEYHERE
## Docker run standalone example:
## docker build -t emhass/docker --build-arg build_version=standalone .
## docker run -it -p 5000:5000 --name emhass-container -v $(pwd)/config_emhass.yaml:/app/config_emhass.yaml -v $(pwd)/secrets_emhass.yaml:/app/secrets_emhass.yaml emhass/docker

#build_version options are: addon, addon-pip, addon-git, addon-local, standalone (default)
ARG build_version=standalone


#armhf,amd64,armv7,aarch64
ARG TARGETARCH
#armhf=raspbian, amd64,armv7,aarch64=debian
ARG os_version=debian

Expand Down Expand Up @@ -74,98 +69,35 @@ RUN apt-get purge -y --auto-remove \
libnetcdf-dev \
&& rm -rf /var/lib/apt/lists/*

#copy config file
COPY config_emhass.yaml /app/
#copy default parameters
COPY config.json /app/

#make sure data directory exists
RUN mkdir -p /app/data/

#-------------------------
##EMHASS-Add-on default (this has no emhass package)
FROM base as addon

LABEL \
io.hass.name="emhass" \
io.hass.description="EMHASS: Energy Management for Home Assistant" \
io.hass.version=${BUILD_VERSION} \
io.hass.type="addon" \
io.hass.arch="aarch64|amd64|armhf|armv7"

#-----------
#EMHASS-ADD-ON testing with pip emhass (EMHASS-Add-on testing reference)
FROM addon as addon-pip
#set build arg for pip version
ARG build_pip_version=""
RUN pip3 install --no-cache-dir --break-system-packages --upgrade --force-reinstall --no-deps --upgrade-strategy=only-if-needed -U emhass${build_pip_version}

COPY options.json /app/

ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True", "--no_response", "True"]

#-----------
#EMHASS-Add-on testing from local files
FROM addon as addon-local
#copy required EMHASS files
COPY src/emhass/ /app/src/emhass/
COPY src/emhass/templates/ /app/src/emhass/templates/
COPY src/emhass/static/ /app/src/emhass/static/
COPY src/emhass/static/img/ /app/src/emhass/static/img/
COPY src/emhass/data/ /app/src/emhass/data/
COPY data/opt_res_latest.csv /app/data/
#add options.json, this otherwise would be generated via HA
COPY options.json /app/
COPY README.md /app/
COPY setup.py /app/
#compile EMHASS locally
RUN pip3 install --no-cache-dir --break-system-packages --no-deps --force-reinstall .
ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True" , "--no_response", "True"]


#-----------
#EMHASS-Add-on testing with git
FROM addon as addon-git
ARG build_repo=https://github.com/davidusb-geek/emhass.git
ARG build_branch=master
WORKDIR /tmp/
#Repo
RUN git clone $build_repo
WORKDIR /tmp/emhass
#Branch
RUN git checkout $build_branch
RUN mkdir -p /app/src/emhass/data/
RUN cp -r /tmp/emhass/src/emhass/. /app/src/emhass/
RUN cp /tmp/emhass/src/emhass/data/* /app/src/emhass/data/
RUN cp /tmp/emhass/data/opt_res_latest.csv /app/data/
RUN cp /tmp/emhass/setup.py /app/
RUN cp /tmp/emhass/README.md /app/
#add options.json, this otherwise would be generated via HA
RUN cp /tmp/emhass/options.json /app/
WORKDIR /app
RUN pip3 install --no-cache-dir --break-system-packages --no-deps --force-reinstall .
ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True" , "--no_response", "True"]

#-------------------------
#EMHASS standalone
FROM base as standalone

COPY src/emhass/ /app/src/emhass/
COPY src/emhass/templates/ /app/src/emhass/templates/
COPY src/emhass/static/ /app/src/emhass/static/
COPY src/emhass/static/img/ /app/src/emhass/static/img/
COPY src/emhass/data/ /app/src/emhass/data/
COPY data/opt_res_latest.csv /app/data/
COPY README.md /app/
COPY setup.py /app/
#secrets file can be copied manually at docker run

#set python env variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

LABEL \
io.hass.name="emhass" \
io.hass.description="EMHASS: Energy Management for Home Assistant" \
io.hass.version=${BUILD_VERSION} \
io.hass.type="addon" \
io.hass.arch="aarch64|amd64|armhf|armv7"

#build EMHASS
RUN pip3 install --no-cache-dir --break-system-packages --no-deps --force-reinstall .
ENTRYPOINT [ "python3", "-m", "emhass.web_server"]
#-------------------------


#check build arguments and build
FROM ${build_version} AS final
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,13 @@ In `automations.yaml`:
```
in configuration page/`config_emhass.yaml`
```json
"method_ts_round": "first"
"continual_publish": true
'method_ts_round': "first"
'continual_publish': true
```
In this automation, the day-ahead optimization is performed once a day, every day at 5:30am.
If the `freq` parameter is set to `30` *(default)* in the configuration, the results of the day-ahead optimization will generate 48 values *(for each entity)*, a value for every 30 minutes in a day *(i.e. 24 hrs x 2)*.

Setting the parameter `continual_publish` to `true` in the configuration page will allow EMHASS to store the optimization results as entities/sensors into separate json files. `continual_publish` will periodically (every `freq` amount of minutes) run a publish, and publish the optimization results of each generated entities/sensors to Home Assistant. The current state of the sensor/entity being updated every time publish runs, selecting one of the 48 stored values, by comparing the stored values' timestamps, the current timestamp and [`"method_ts_round": "first"`](#the-publish-data-specificities) to select the optimal stored value for the current state.
Setting the parameter `continual_publish` to `true` in the configuration page will allow EMHASS to store the optimization results as entities/sensors into separate json files. `continual_publish` will periodically (every `freq` amount of minutes) run a publish, and publish the optimization results of each generated entities/sensors to Home Assistant. The current state of the sensor/entity being updated every time publish runs, selecting one of the 48 stored values, by comparing the stored values' timestamps, the current timestamp and [`'method_ts_round': "first"`](#the-publish-data-specificities) to select the optimal stored value for the current state.

option 1 and 2 are very similar, however, option 2 (`continual_publish`) will require a CPU thread to constantly be run inside of EMHASS, lowering efficiency. The reason why you may pick one over the other is explained in more detail below in [continual_publish](#continual_publish-emhass-automation).

Expand Down Expand Up @@ -406,7 +406,7 @@ For users that wish to run multiple different optimizations, you can set the run
# RUN dayahead, with freq=30 (default), prefix=dh_
curl -i -H 'Content-Type:application/json' -X POST -d '{"publish_prefix":"dh_"}' http://localhost:5000/action/dayahead-optim
# RUN MPC, with freq=5, prefix=mpc_
curl -i -H 'Content-Type:application/json' -X POST -d '{"freq":5,"publish_prefix":"mpc_"}' http://localhost:5000/action/naive-mpc-optim
curl -i -H 'Content-Type:application/json' -X POST -d '{'optimization_time_step':5,"publish_prefix":"mpc_"}' http://localhost:5000/action/naive-mpc-optim
```
This will tell continual_publish to loop every 5 minutes based on the freq passed in MPC. All entities from the output of dayahead "dh_" and MPC "mpc_" will be published every 5 minutes.

Expand All @@ -416,13 +416,13 @@ This will tell continual_publish to loop every 5 minutes based on the freq passe

#### Mixture of continual_publish and manual *(Home Assistant Automation for Publish)*

You can choose to save one optimization for continual_publish and bypass another optimization by setting `"continual_publish":false` runtime parameter:
You can choose to save one optimization for continual_publish and bypass another optimization by setting `'continual_publish':false` runtime parameter:
```bash
# RUN dayahead, with freq=30 (default), prefix=dh_, included into continual_publish
curl -i -H 'Content-Type:application/json' -X POST -d '{"publish_prefix":"dh_"}' http://localhost:5000/action/dayahead-optim

# RUN MPC, with freq=5, prefix=mpc_, Manually publish, excluded from continual_publish loop
curl -i -H 'Content-Type:application/json' -X POST -d '{"continual_publish":false,"freq":5,"publish_prefix":"mpc_"}' http://localhost:5000/action/naive-mpc-optim
curl -i -H 'Content-Type:application/json' -X POST -d '{'continual_publish':false,'optimization_time_step':5,"publish_prefix":"mpc_"}' http://localhost:5000/action/naive-mpc-optim
# Publish MPC output
curl -i -H 'Content-Type:application/json' -X POST -d {} http://localhost:5000/action/publish-data
```
Expand All @@ -434,14 +434,14 @@ For users who wish to have full control of exactly when they would like to run a

in configuration page/`config_emhass.yaml` :
```json
"continual_publish": false
'continual_publish': false
```
POST action :
```bash
# RUN dayahead, with freq=30 (default), prefix=dh_, save entity
curl -i -H 'Content-Type:application/json' -X POST -d '{"entity_save": true, "publish_prefix":"dh_"}' http://localhost:5000/action/dayahead-optim
# RUN MPC, with freq=5, prefix=mpc_, save entity
curl -i -H 'Content-Type:application/json' -X POST -d '{"entity_save": true", "freq":5,"publish_prefix":"mpc_"}' http://localhost:5000/action/naive-mpc-optim
curl -i -H 'Content-Type:application/json' -X POST -d '{"entity_save": true", 'optimization_time_step':5,"publish_prefix":"mpc_"}' http://localhost:5000/action/naive-mpc-optim
```
You can then reference these .json saved entities via their `publish_prefix`. Include the same `publish_prefix` in the `publish_data` action:
```bash
Expand Down Expand Up @@ -554,7 +554,7 @@ curl -i -H 'Content-Type:application/json' -X POST -d '{"pv_power_forecast":[0,
```
*Example with :`def_total_hours`, `def_start_timestep`, `def_end_timestep`.*
```bash
curl -i -H 'Content-Type:application/json' -X POST -d '{"pv_power_forecast":[0, 70, 141.22, 246.18, 513.5, 753.27, 1049.89, 1797.93, 1697.3, 3078.93], "prediction_horizon":10, "soc_init":0.5,"soc_final":0.6,"def_total_hours":[1,3],"def_start_timestep":[0,3],"def_end_timestep":[0,6]}' http://localhost:5000/action/naive-mpc-optim
curl -i -H 'Content-Type:application/json' -X POST -d '{"pv_power_forecast":[0, 70, 141.22, 246.18, 513.5, 753.27, 1049.89, 1797.93, 1697.3, 3078.93], "prediction_horizon":10, "soc_init":0.5,"soc_final":0.6,'operating_hours_of_each_deferrable_load':[1,3],'start_timesteps_of_each_deferrable_load':[0,3],'end_timesteps_of_each_deferrable_load':[0,6]}' http://localhost:5000/action/naive-mpc-optim
```

## A machine learning forecaster
Expand Down
Loading
Loading