From 012f8f3eaf0ab7fff6b7fd17115818180049030b Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sat, 2 Mar 2024 11:26:28 +0000 Subject: [PATCH 01/23] Docker, added requirements_webserver to container, removed requirements_addon --- Dockerfile | 3 ++- docs/develop.md | 9 +++++++-- requirements_addon.txt | 18 ------------------ 3 files changed, 9 insertions(+), 21 deletions(-) delete mode 100644 requirements_addon.txt diff --git a/Dockerfile b/Dockerfile index 00b90e4d..ebc9d357 100644 --- a/Dockerfile +++ b/Dockerfile @@ -123,7 +123,8 @@ ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True" , "--no_resp #EMHASS STANDALONE FROM base as standalone -RUN pip3 install --extra-index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -U flask waitress plotly +COPY requirements_webserver.txt /app/ +RUN pip3 install --extra-index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -r requirements_webserver.txt COPY src/emhass/ /app/src/emhass/ COPY src/emhass/templates/ /app/src/emhass/templates/ diff --git a/docs/develop.md b/docs/develop.md index fe82a4fa..c962ebce 100644 --- a/docs/develop.md +++ b/docs/develop.md @@ -21,10 +21,15 @@ This method works well with standalone mode. _confirm terminal is in the root `emhass` directory before starting_ +**Install requirements** +```bash +python3 -m pip install --extra-index-url=https://www.piwheels.org/simple -r requirements_webserver.txt +``` + **Create a developer environment:** ```bash -python -m venv .venv +python3 -m venv .venv ``` **Activate the environment:** @@ -46,7 +51,7 @@ An IDE like VSCode should automatically catch that a new virtual env was created **Install the _emhass_ package in editable mode:** ```bash -python -m pip install -e . +python3 -m pip install -e . ``` **Set paths with environment variables:** diff --git a/requirements_addon.txt b/requirements_addon.txt deleted file mode 100644 index 7c690fe6..00000000 --- a/requirements_addon.txt +++ /dev/null @@ -1,18 +0,0 @@ -numpy<=1.26.0 -scipy<=1.11.3 -pandas<=2.0.3 -pvlib>=0.10.2 -protobuf>=3.0.0 -pytz>=2021.1 -requests>=2.25.1 -beautifulsoup4>=4.9.3 -h5py==3.10.0 -pulp>=2.4 -pyyaml>=5.4.1 -tables<=3.9.1 -skforecast==0.11.0 -flask>=2.0.3 -waitress>=2.1.1 -plotly>=5.6.0 -emhass==0.7.7 -#git+https://github.com/davidusb-geek/emhass \ No newline at end of file From e3358c7621425786456eba188b364721c31a72c1 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sat, 2 Mar 2024 12:27:56 +0000 Subject: [PATCH 02/23] merged requirement files --- .devcontainer/Dockerfile | 2 +- .devcontainer/setup.sh | 2 +- Dockerfile | 3 --- docs/develop.md | 2 +- requirements.txt | 6 +++++- requirements_webserver.txt | 4 ---- 6 files changed, 8 insertions(+), 11 deletions(-) delete mode 100644 requirements_webserver.txt diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 0c0a46ee..8e50c277 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,4 @@ FROM mcr.microsoft.com/devcontainers/python:0-3.11 # EXPOSE 5000:5000 -COPY .devcontainer/setup.sh requirements.txt requirements_webserver.txt ./ +COPY .devcontainer/setup.sh requirements.txt ./ RUN ./setup.sh diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 220c197c..2939a230 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -18,7 +18,7 @@ main() { export HDF5_DIR=/usr/include/hdf5 pip install netCDF4 - pip install -r requirements_webserver.txt + pip install -r requirements.txt pip install requests-mock rm -rf "$0" diff --git a/Dockerfile b/Dockerfile index ebc9d357..7dc80c82 100644 --- a/Dockerfile +++ b/Dockerfile @@ -123,9 +123,6 @@ ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True" , "--no_resp #EMHASS STANDALONE FROM base as standalone -COPY requirements_webserver.txt /app/ -RUN pip3 install --extra-index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -r requirements_webserver.txt - COPY src/emhass/ /app/src/emhass/ COPY src/emhass/templates/ /app/src/emhass/templates/ COPY src/emhass/static/ /app/src/emhass/static/ diff --git a/docs/develop.md b/docs/develop.md index c962ebce..50dbc6aa 100644 --- a/docs/develop.md +++ b/docs/develop.md @@ -23,7 +23,7 @@ _confirm terminal is in the root `emhass` directory before starting_ **Install requirements** ```bash -python3 -m pip install --extra-index-url=https://www.piwheels.org/simple -r requirements_webserver.txt +python3 -m pip install --extra-index-url=https://www.piwheels.org/simple -r requirements.txt ``` **Create a developer environment:** diff --git a/requirements.txt b/requirements.txt index 1a84a681..23f7cab0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,4 +11,8 @@ h5py==3.10.0 pulp>=2.4 pyyaml>=5.4.1 tables<=3.9.1 -skforecast==0.11.0 \ No newline at end of file +skforecast==0.11.0 +# web server packadges +flask>=2.0.3 +waitress>=2.1.1 +plotly>=5.6.0 diff --git a/requirements_webserver.txt b/requirements_webserver.txt deleted file mode 100644 index d5dfd368..00000000 --- a/requirements_webserver.txt +++ /dev/null @@ -1,4 +0,0 @@ --r requirements.txt -flask>=2.0.3 -waitress>=2.1.1 -plotly>=5.6.0 From d9d6669388d9c7c5e09f39b0988a3684f7a25b83 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sat, 2 Mar 2024 12:30:06 +0000 Subject: [PATCH 03/23] requirements fix typo --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 23f7cab0..2589b418 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ pulp>=2.4 pyyaml>=5.4.1 tables<=3.9.1 skforecast==0.11.0 -# web server packadges +# web server packages flask>=2.0.3 waitress>=2.1.1 plotly>=5.6.0 From a9572103c62f3516bc4edba1465d36c18301fca8 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sat, 2 Mar 2024 14:59:38 +0000 Subject: [PATCH 04/23] Docker and Requirements, test armhf suppport --- Dockerfile | 9 +++++++-- requirements.txt | 3 +-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7dc80c82..555edb2a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,19 +34,24 @@ RUN apt-get update \ netcdf-bin \ libnetcdf-dev \ pkg-config \ + ninja-build \ + patchelf \ gfortran \ libatlas-base-dev \ && ln -s /usr/include/hdf5/serial /usr/include/hdf5/include \ && export HDF5_DIR=/usr/include/hdf5 \ - && pip3 install --extra-index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -U setuptools wheel \ - && pip3 install --extra-index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -r requirements.txt \ + && pip3 install --no-cache-dir --break-system-packages -r requirements.txt \ && apt-get purge -y --auto-remove \ + ninja-build \ + patchelf \ gcc \ build-essential \ libhdf5-dev \ libhdf5-serial-dev \ pkg-config \ gfortran \ + netcdf-bin \ + libnetcdf-dev \ && rm -rf /var/lib/apt/lists/* diff --git a/requirements.txt b/requirements.txt index 2589b418..bfc9be75 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ -wheel -numpy<=1.26.0 +numpy<=1.26.2 scipy<=1.11.3 pandas<=2.0.3 pvlib>=0.10.2 From e9a9be74f6392de38dac9c9a9b1ac7b75c40ef28 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sun, 3 Mar 2024 12:55:24 +0000 Subject: [PATCH 05/23] OpenBLAS install --- Dockerfile | 45 ++++++++++++++++++++++++++++++++------------- requirements.txt | 4 ++-- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 555edb2a..e88d582f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,26 @@ -## EMHASS Docker +## EMHASS Docker +## ## Docker run ADD-ON testing example: -## docker build -t emhass/docker --build-arg build_version=addon-local . -## 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 build -t emhass/docker --build-arg build_version=addon-local . + ## 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 + ## 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 FROM ghcr.io/home-assistant/$TARGETARCH-base-debian:bookworm AS base +#check if TARGETARCH passed by build-arg +ARG TARGETARCH +ENV TARGETARCH=${TARGETARCH:?} + WORKDIR /app COPY requirements.txt /app/ -# Setup +#setup RUN apt-get update \ && apt-get install -y --no-install-recommends \ libffi-dev \ @@ -34,15 +39,29 @@ RUN apt-get update \ netcdf-bin \ libnetcdf-dev \ pkg-config \ + meson \ ninja-build \ patchelf \ gfortran \ - libatlas-base-dev \ - && ln -s /usr/include/hdf5/serial /usr/include/hdf5/include \ - && export HDF5_DIR=/usr/include/hdf5 \ - && pip3 install --no-cache-dir --break-system-packages -r requirements.txt \ + libatlas-base-dev +RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include +RUN export HDF5_DIR=/usr/include/hdf5 +#check if armhf (32bit) and build openblas for numpy and scipy +RUN [[ "${TARGETARCH}" == "armhf" ]] \ +&& git clone https://github.com/OpenMathLib/OpenBLAS.git \ +&& cd OpenBLAS \ +&& git checkout $(git describe --tags) \ +&& export TARGET=ARMV6 \ +&& make FC=gfortran \ +&& cd .. || echo "not armf" +#if not amdhf then install openblas via apt +RUN [[ ! "${TARGETARCH}" == "armhf" ]] \ +&& apt install -y libopenblas-dev || echo "armf" +#remove build only packadges +RUN pip3 install --no-cache-dir --break-system-packages -r requirements.txt \ && apt-get purge -y --auto-remove \ ninja-build \ + meson \ patchelf \ gcc \ build-essential \ @@ -58,7 +77,7 @@ RUN apt-get update \ #copy config file (on all builds) COPY config_emhass.yaml /app/ -# Make sure data directory exists +#make sure data directory exists RUN mkdir -p /app/data/ #------------------------- @@ -137,12 +156,12 @@ COPY README.md /app/ COPY setup.py /app/ #secrets file will need to be copied manually at docker run -# # set env variables +#set env variables ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 #build EMHASS -# RUN python3 setup.py install +#RUN python3 setup.py install RUN python3 -m pip install --no-cache-dir --break-system-packages -U . ENTRYPOINT [ "python3", "-m", "emhass.web_server"] #------------------------- diff --git a/requirements.txt b/requirements.txt index bfc9be75..0fd21bfb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -numpy<=1.26.2 -scipy<=1.11.3 +numpy==1.26.4 +scipy==1.12.0 pandas<=2.0.3 pvlib>=0.10.2 protobuf>=3.0.0 From 53cba27428090c49952f5b77be112bd698dfe74b Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Mon, 4 Mar 2024 01:28:54 +0000 Subject: [PATCH 06/23] replace package arch test --- .github/workflows/docker-build-test.yaml | 2 +- Dockerfile | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docker-build-test.yaml b/.github/workflows/docker-build-test.yaml index af5caf22..b0de0f86 100644 --- a/.github/workflows/docker-build-test.yaml +++ b/.github/workflows/docker-build-test.yaml @@ -17,7 +17,7 @@ jobs: platform: [ {buildx: linux/amd64, target_arch: amd64}, {buildx: linux/arm/v7, target_arch: armv7}, - {buildx: linux/arm/v7, target_arch: armhf}, + {buildx: linux/arm/v6, target_arch: armhf}, {buildx: linux/arm64, target_arch: aarch64} ] steps: diff --git a/Dockerfile b/Dockerfile index e88d582f..6d9d0c4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,11 @@ ENV TARGETARCH=${TARGETARCH:?} WORKDIR /app COPY requirements.txt /app/ +#if armhf remove armel and replace with armhf +RUN [[ "${TARGETARCH}" == "armhf" ]] \ +&& dpkg --add-architecture armhf \ +&& dpkg --remove-architecture armel || echo "not armf" + #setup RUN apt-get update \ && apt-get install -y --no-install-recommends \ @@ -38,6 +43,8 @@ RUN apt-get update \ libhdf5-serial-dev \ netcdf-bin \ libnetcdf-dev \ + libopenblas-dev \ + cmake \ pkg-config \ meson \ ninja-build \ @@ -46,21 +53,12 @@ RUN apt-get update \ libatlas-base-dev RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include RUN export HDF5_DIR=/usr/include/hdf5 -#check if armhf (32bit) and build openblas for numpy and scipy -RUN [[ "${TARGETARCH}" == "armhf" ]] \ -&& git clone https://github.com/OpenMathLib/OpenBLAS.git \ -&& cd OpenBLAS \ -&& git checkout $(git describe --tags) \ -&& export TARGET=ARMV6 \ -&& make FC=gfortran \ -&& cd .. || echo "not armf" -#if not amdhf then install openblas via apt -RUN [[ ! "${TARGETARCH}" == "armhf" ]] \ -&& apt install -y libopenblas-dev || echo "armf" + #remove build only packadges RUN pip3 install --no-cache-dir --break-system-packages -r requirements.txt \ && apt-get purge -y --auto-remove \ ninja-build \ + cmake \ meson \ patchelf \ gcc \ From 5e346ab66b70d3763c33a0f3f6067a30f94323f1 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Mon, 4 Mar 2024 01:29:35 +0000 Subject: [PATCH 07/23] tweak --- Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6d9d0c4d..7ac85551 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,9 +21,7 @@ WORKDIR /app COPY requirements.txt /app/ #if armhf remove armel and replace with armhf -RUN [[ "${TARGETARCH}" == "armhf" ]] \ -&& dpkg --add-architecture armhf \ -&& dpkg --remove-architecture armel || echo "not armf" +RUN [[ "${TARGETARCH}" == "armhf" ]] && dpkg --add-architecture armhf ; dpkg --remove-architecture armel || echo "not armf" #setup RUN apt-get update \ From 3dad0af1aeaf1fb4249384d4e30a85168c79aacc Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Mon, 4 Mar 2024 05:28:09 +0000 Subject: [PATCH 08/23] Docker, changed pip install repo based on arch, setup match requirements --- .github/workflows/publish_docker.yaml | 2 +- Dockerfile | 6 ++++-- setup.py | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish_docker.yaml b/.github/workflows/publish_docker.yaml index b87099c8..d765b6f3 100644 --- a/.github/workflows/publish_docker.yaml +++ b/.github/workflows/publish_docker.yaml @@ -15,7 +15,7 @@ jobs: platform: [ {buildx: linux/amd64, target_arch: amd64}, {buildx: linux/arm/v7, target_arch: armv7}, - {buildx: linux/arm/v7, target_arch: armhf}, + {buildx: linux/arm/v6, target_arch: armhf}, {buildx: linux/arm64, target_arch: aarch64} ] steps: diff --git a/Dockerfile b/Dockerfile index 7ac85551..fe32004b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,9 +52,11 @@ RUN apt-get update \ RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include RUN export HDF5_DIR=/usr/include/hdf5 +#install packadges from pip +RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && pip3 install --index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -r requirements.txt || pip3 install --no-cache-dir --break-system-packages -r requirements.txt + #remove build only packadges -RUN pip3 install --no-cache-dir --break-system-packages -r requirements.txt \ - && apt-get purge -y --auto-remove \ +RUN apt-get purge -y --auto-remove \ ninja-build \ cmake \ meson \ diff --git a/setup.py b/setup.py index 4f95666b..b3ac4541 100644 --- a/setup.py +++ b/setup.py @@ -40,8 +40,8 @@ python_requires='>=3.9, <3.12', install_requires=[ 'wheel', - 'numpy<=1.26', - 'scipy<=1.11.3', + 'numpy==1.26.4', + 'scipy==1.12.0', 'pandas<=2.0.3', 'pvlib>=0.10.2', 'protobuf>=3.0.0', From fc10602db5c727b5b44ac6394e4d1cd43718598c Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Mon, 4 Mar 2024 06:18:53 +0000 Subject: [PATCH 09/23] Docker neaten up, readme mpc typo --- Dockerfile | 8 +++----- README.md | 2 +- docs/develop.md | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index fe32004b..aed87264 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,7 @@ ## EMHASS Docker -## ## Docker run ADD-ON testing example: ## docker build -t emhass/docker --build-arg build_version=addon-local . ## 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 @@ -20,7 +18,7 @@ ENV TARGETARCH=${TARGETARCH:?} WORKDIR /app COPY requirements.txt /app/ -#if armhf remove armel and replace with armhf +#if arch is armhf replace armel package library with armhf RUN [[ "${TARGETARCH}" == "armhf" ]] && dpkg --add-architecture armhf ; dpkg --remove-architecture armel || echo "not armf" #setup @@ -52,10 +50,10 @@ RUN apt-get update \ RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include RUN export HDF5_DIR=/usr/include/hdf5 -#install packadges from pip +#install packages from pip, use piwheels if arm RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && pip3 install --index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -r requirements.txt || pip3 install --no-cache-dir --break-system-packages -r requirements.txt -#remove build only packadges +#remove build only packages RUN apt-get purge -y --auto-remove \ ninja-build \ cmake \ diff --git a/README.md b/README.md index 6cfa9f5a..40a767d9 100644 --- a/README.md +++ b/README.md @@ -420,7 +420,7 @@ When applying this controller, the following `runtimeparams` should be defined: A correct call for a MPC optimization should look like: ``` -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,"def_total_hours":[1,3],"def_start_timestep":[0,3],"def_end_timestep":[0,6]}' http://localhost:5000/action/naive-mpc-optim ``` ## A machine learning forecaster diff --git a/docs/develop.md b/docs/develop.md index 50dbc6aa..0dcabd56 100644 --- a/docs/develop.md +++ b/docs/develop.md @@ -23,7 +23,7 @@ _confirm terminal is in the root `emhass` directory before starting_ **Install requirements** ```bash -python3 -m pip install --extra-index-url=https://www.piwheels.org/simple -r requirements.txt +python3 -m pip install -r requirements.txt #if arm try setting --extra-index-url=https://www.piwheels.org/simple ``` **Create a developer environment:** From 12e221b04248e0ef65d452d31927d0fa5dc8d75e Mon Sep 17 00:00:00 2001 From: john whately <18461782+GeoDerp@users.noreply.github.com> Date: Tue, 5 Mar 2024 23:29:28 +1030 Subject: [PATCH 10/23] merged Docker testing with PR repo (#2) - added Raspbian - Dev Container actions better match Docker's EMHASS install and run - added --no-deps and --force-reinstall to emhass pip --- .github/workflows/docker-build-test.yaml | 9 ++-- .github/workflows/publish_docker.yaml | 9 ++-- .vscode/launch.json | 6 +-- .vscode/tasks.json | 4 +- Dockerfile | 60 +++++++++++------------- docs/develop.md | 10 ++++ requirements.txt | 2 +- src/emhass/web_server.py | 1 - 8 files changed, 53 insertions(+), 48 deletions(-) diff --git a/.github/workflows/docker-build-test.yaml b/.github/workflows/docker-build-test.yaml index b0de0f86..4da4c633 100644 --- a/.github/workflows/docker-build-test.yaml +++ b/.github/workflows/docker-build-test.yaml @@ -15,10 +15,10 @@ jobs: fail-fast: false matrix: platform: [ - {buildx: linux/amd64, target_arch: amd64}, - {buildx: linux/arm/v7, target_arch: armv7}, - {buildx: linux/arm/v6, target_arch: armhf}, - {buildx: linux/arm64, target_arch: aarch64} + {buildx: linux/amd64, target_arch: amd64, os_version: debian}, + {buildx: linux/arm/v7, target_arch: armv7, os_version: debian}, + {buildx: linux/arm/v7, target_arch: armhf, os_version: raspbian}, + {buildx: linux/arm64, target_arch: aarch64, os_version: debian} ] steps: - name: Checkout the repository @@ -36,6 +36,7 @@ jobs: build-args: | build_version=standalone TARGETARCH=${{ matrix.platform.target_arch }} + os_version=${{ matrix.platform.os_version }} tags: emhass/standalone-test load: true - name: Test #assume docker fail with FileNotFound secrets_emhass.yaml error diff --git a/.github/workflows/publish_docker.yaml b/.github/workflows/publish_docker.yaml index d765b6f3..a64cbe3b 100644 --- a/.github/workflows/publish_docker.yaml +++ b/.github/workflows/publish_docker.yaml @@ -13,10 +13,10 @@ jobs: fail-fast: false matrix: platform: [ - {buildx: linux/amd64, target_arch: amd64}, - {buildx: linux/arm/v7, target_arch: armv7}, - {buildx: linux/arm/v6, target_arch: armhf}, - {buildx: linux/arm64, target_arch: aarch64} + {buildx: linux/amd64, target_arch: amd64, os_version: debian}, + {buildx: linux/arm/v7, target_arch: armv7, os_version: debian}, + {buildx: linux/arm/v7, target_arch: armhf, os_version: raspbian}, + {buildx: linux/arm64, target_arch: aarch64, os_version: debian} ] steps: - name: Checkout the repository @@ -45,6 +45,7 @@ jobs: build-args: | build_version=standalone TARGETARCH=${{ matrix.platform.target_arch }} + os_version=${{ matrix.platform.os_version }} labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=${{ secrets.DOCKERHUB_USERNAME }}/emhass-docker-standalone,push-by-digest=true,name-canonical=true,push=true - name: Export digest diff --git a/.vscode/launch.json b/.vscode/launch.json index e3c4716d..10313c97 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,9 +12,8 @@ "name": "EMHASS run", "type": "debugpy", "request": "launch", - "program": "web_server.py", + "module": "emhass.web_server", "console": "integratedTerminal", - "cwd": "${workspaceFolder}/src/emhass/", "purpose":["debug-in-terminal"], "justMyCode": true, "env": { @@ -29,9 +28,8 @@ "name": "EMHASS run ADDON", "type": "debugpy", "request": "launch", - "program": "web_server.py", + "module": "emhass.web_server", "console": "integratedTerminal", - "cwd": "${workspaceFolder}/src/emhass/", "args": ["--addon", "true", "--no_response", "true"], "purpose":["debug-in-terminal"], "justMyCode": true, diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 5be6806e..11a92388 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -3,13 +3,13 @@ "tasks": [ { "label": "EMHASS install", - "command": "sudo", + "command": "pip3", "group": { "kind": "build", "isDefault": true }, "args": [ - "python3", "-m", "pip", "install", "." + "install", "--no-deps", "--force-reinstall", "." ], "presentation": { "echo": true, diff --git a/Dockerfile b/Dockerfile index aed87264..cae69552 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,13 @@ ## 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 +ARG build_version=standalone +#os_version +#armhf = raspbian +#amd64, armv7, aarch64 = debian +ARG os_version=debian -FROM ghcr.io/home-assistant/$TARGETARCH-base-debian:bookworm AS base +FROM ghcr.io/home-assistant/$TARGETARCH-base-$os_version:bookworm AS base #check if TARGETARCH passed by build-arg ARG TARGETARCH @@ -18,10 +22,6 @@ ENV TARGETARCH=${TARGETARCH:?} WORKDIR /app COPY requirements.txt /app/ -#if arch is armhf replace armel package library with armhf -RUN [[ "${TARGETARCH}" == "armhf" ]] && dpkg --add-architecture armhf ; dpkg --remove-architecture armel || echo "not armf" - -#setup RUN apt-get update \ && apt-get install -y --no-install-recommends \ libffi-dev \ @@ -29,40 +29,39 @@ RUN apt-get update \ python3-pip \ python3-dev \ git \ - build-essential \ gcc \ - coinor-cbc \ - coinor-libcbc-dev \ - libglpk-dev \ - glpk-utils \ - libhdf5-dev \ - libhdf5-serial-dev \ - netcdf-bin \ - libnetcdf-dev \ - libopenblas-dev \ + patchelf \ cmake \ - pkg-config \ meson \ ninja-build \ - patchelf \ + build-essential \ + libhdf5-dev \ + libhdf5-serial-dev \ + pkg-config \ gfortran \ - libatlas-base-dev + netcdf-bin \ + libnetcdf-dev \ + coinor-cbc \ + coinor-libcbc-dev \ + libglpk-dev \ + glpk-utils \ + libatlas-base-dev \ + libopenblas-dev RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include RUN export HDF5_DIR=/usr/include/hdf5 #install packages from pip, use piwheels if arm -RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && pip3 install --index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -r requirements.txt || pip3 install --no-cache-dir --break-system-packages -r requirements.txt +RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && pip3 install --index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -r requirements.txt || pip3 install --no-cache-dir --break-system-packages -r requirements.txt #remove build only packages RUN apt-get purge -y --auto-remove \ - ninja-build \ + git \ + gcc \ + patchelf \ cmake \ meson \ - patchelf \ - gcc \ + ninja-build \ build-essential \ - libhdf5-dev \ - libhdf5-serial-dev \ pkg-config \ gfortran \ netcdf-bin \ @@ -87,14 +86,12 @@ LABEL \ io.hass.type="addon" \ io.hass.arch="aarch64|amd64|armhf|armv7" -ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True", "--url", "http://supervisor/core/api"] - #----------- #EMHASS-ADD-ON Testing with pip emhass (closest 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 --upgrade-strategy=only-if-needed -U emhass${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/ @@ -113,7 +110,7 @@ COPY options.json /app/ COPY README.md /app/ COPY setup.py /app/ #compile EMHASS locally -RUN python3 -m pip install --no-cache-dir --break-system-packages -U . +RUN pip3 install --no-cache-dir --break-system-packages --no-deps --force-reinstall . ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True" , "--no_response", "True"] @@ -136,7 +133,7 @@ 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 python3 -m pip install --no-cache-dir --break-system-packages -U . +RUN pip3 install --no-cache-dir --break-system-packages --no-deps --force-reinstall . ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True" , "--no_response", "True"] #------------------------- @@ -157,8 +154,7 @@ ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 #build EMHASS -#RUN python3 setup.py install -RUN python3 -m pip install --no-cache-dir --break-system-packages -U . +RUN pip3 install --no-cache-dir --break-system-packages --no-deps --force-reinstall . ENTRYPOINT [ "python3", "-m", "emhass.web_server"] #------------------------- diff --git a/docs/develop.md b/docs/develop.md index 0dcabd56..c21e223a 100644 --- a/docs/develop.md +++ b/docs/develop.md @@ -221,6 +221,16 @@ For those who wish to mount/sync the local `data` folder with the data folder fr docker run ... -v $(pwd)/data/:/app/data ... ``` +#### Issue with TARGETARCH +If your docker build fails with an error related to `TARGETARCH`. It may be best to add your devices artitecture this in manually: + +Example with armhf architecture +```bash +docker build ... --build-arg TARGETARCH=armhf --build-arg os_version=raspbian ... +``` +*For `armhf` only, create a build-arg for `os_version=raspbian`* + + #### Delete built Docker image We can delete the Docker image and container via: diff --git a/requirements.txt b/requirements.txt index 0fd21bfb..22b18dfa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,4 +14,4 @@ skforecast==0.11.0 # web server packages flask>=2.0.3 waitress>=2.1.1 -plotly>=5.6.0 +plotly>=5.6.0 \ No newline at end of file diff --git a/src/emhass/web_server.py b/src/emhass/web_server.py index 027056f3..589a432f 100644 --- a/src/emhass/web_server.py +++ b/src/emhass/web_server.py @@ -9,7 +9,6 @@ from pathlib import Path import os, json, argparse, pickle, yaml, logging, re from distutils.util import strtobool -import pandas as pd from emhass.command_line import set_input_data_dict from emhass.command_line import perfect_forecast_optim, dayahead_forecast_optim, naive_mpc_optim From 1cbbab33ff824d604df3fa95c46d31fe29bbd183 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Wed, 6 Mar 2024 22:13:13 +1030 Subject: [PATCH 11/23] docker-build-test, small typo --- .github/workflows/docker-build-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-build-test.yaml b/.github/workflows/docker-build-test.yaml index 4da4c633..1317344a 100644 --- a/.github/workflows/docker-build-test.yaml +++ b/.github/workflows/docker-build-test.yaml @@ -1,5 +1,5 @@ #This action test builds EMHASS standalone Docker images, in each architecture. -name: "Test Docker Stanadlone" +name: "Test Docker Standalone" on: push: From 3fd9d42bb614d10b8a9749da42c4481b9e94cca5 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:56:23 +0000 Subject: [PATCH 12/23] Docker, cbc symlink --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index cae69552..ec90f7aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -69,6 +69,9 @@ RUN apt-get purge -y --auto-remove \ && rm -rf /var/lib/apt/lists/* +#try symlink cbc to python directory +RUN ln -sf /usr/bin/cbc /usr/local/lib/python3.11/dist-packages/pulp/solverdir/cbc/linux/32/cbc || echo "cbc link didnt work" + #copy config file (on all builds) COPY config_emhass.yaml /app/ From 0a36c68cad5f099b9828ccc6d1a57ab963401d11 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Wed, 6 Mar 2024 12:22:26 +0000 Subject: [PATCH 13/23] Docker symlink refine --- Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index ec90f7aa..ba076c57 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,8 +47,12 @@ RUN apt-get update \ glpk-utils \ libatlas-base-dev \ libopenblas-dev -RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include -RUN export HDF5_DIR=/usr/include/hdf5 +#specify hdf5 +RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include && export HDF5_DIR=/usr/include/hdf5 +#try symlink apt cbc to pulp python directory +RUN ln -sf /usr/bin/cbc /usr/local/lib/python3.11/dist-packages/pulp/solverdir/cbc/linux/32/cbc || echo "cbc link didnt work" + + #install packages from pip, use piwheels if arm RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && pip3 install --index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -r requirements.txt || pip3 install --no-cache-dir --break-system-packages -r requirements.txt @@ -68,10 +72,6 @@ RUN apt-get purge -y --auto-remove \ libnetcdf-dev \ && rm -rf /var/lib/apt/lists/* - -#try symlink cbc to python directory -RUN ln -sf /usr/bin/cbc /usr/local/lib/python3.11/dist-packages/pulp/solverdir/cbc/linux/32/cbc || echo "cbc link didnt work" - #copy config file (on all builds) COPY config_emhass.yaml /app/ From b6aaf55794bc358578f04b7926cba7f14808956c Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Thu, 7 Mar 2024 06:23:30 +0000 Subject: [PATCH 14/23] README, MPC extra example with/without time, syntax highlighting --- README.md | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 40a767d9..79773243 100644 --- a/README.md +++ b/README.md @@ -97,16 +97,16 @@ These architectures are supported: `amd64`, `armv7`, `armhf` and `aarch64`. ### Method 2) Using Docker in standalone mode You can also install EMHASS using docker. This can be in the same machine as Home Assistant (if using the supervised install method) or in a different distant machine. To install first pull the latest image from docker hub: -``` +```bash docker pull davidusb/emhass-docker-standalone ``` You can also build your image locally. For this clone this repository, setup your `config_emhass.yaml` file and use the provided make file with this command: -``` +```bash make -f deploy_docker.mk clean_deploy ``` Then load the image in the .tar file: -``` +```bash docker load -i .tar ``` Finally check your image tag with `docker images` and launch the docker itself: @@ -124,17 +124,17 @@ docker run -it --restart always -p 5000:5000 -e "LOCAL_COSTFUN=profit" -v $(pwd) With this method it is recommended to install on a virtual environment. For this you will need `virtualenv`, install it using: -``` +```bash sudo apt install python3-virtualenv ``` Then create and activate the virtual environment: -``` +```bash virtualenv -p /usr/bin/python3 emhassenv cd emhassenv source bin/activate ``` Install using the distribution files: -``` +```bash python3 -m pip install emhass ``` Clone this repository to obtain the example configuration files. @@ -145,7 +145,7 @@ We will suppose that this repository is cloned to: This will be the root path containing the yaml configuration files (`config_emhass.yaml` and `secrets_emhass.yaml`) and the different needed folders (a `data` folder to store the optimizations results and a `scripts` folder containing the bash scripts described further below). To upgrade the installation in the future just use: -``` +```bash python3 -m pip install --upgrade emhass ``` @@ -181,7 +181,7 @@ The available arguments are: - `--version`: Show the current version of EMHASS. For example, the following line command can be used to perform a day-ahead optimization task: -``` +```bash emhass --action 'dayahead-optim' --config '/home/user/emhass/config_emhass.yaml' --costfun 'profit' ``` Before running any valuable command you need to modify the `config_emhass.yaml` and `secrets_emhass.yaml` files. These files should contain the information adapted to your own system. To do this take a look at the special section for this in the [documentation](https://emhass.readthedocs.io/en/latest/config.html). @@ -195,7 +195,7 @@ Then additional optimization strategies were developed, that can be used in comb ### Dayahead Optimization - Method 1) Add-on and docker standalone In `configuration.yaml`: -``` +```yaml shell_command: dayahead_optim: "curl -i -H \"Content-Type:application/json\" -X POST -d '{}' http://localhost:5000/action/dayahead-optim" publish_data: "curl -i -H \"Content-Type:application/json\" -X POST -d '{}' http://localhost:5000/action/publish-data" @@ -203,25 +203,25 @@ shell_command: ### Dayahead Optimization - Method 2) Legacy method using a Python virtual environment In `configuration.yaml`: -``` +```yaml shell_command: dayahead_optim: /home/user/emhass/scripts/dayahead_optim.sh publish_data: /home/user/emhass/scripts/publish_data.sh ``` Create the file `dayahead_optim.sh` with the following content: -``` +```bash #!/bin/bash . /home/user/emhassenv/bin/activate emhass --action 'dayahead-optim' --config '/home/user/emhass/config_emhass.yaml' ``` And the file `publish_data.sh` with the following content: -``` +```bash #!/bin/bash . /home/user/emhassenv/bin/activate emhass --action 'publish-data' --config '/home/user/emhass/config_emhass.yaml' ``` Then specify user rights and make the files executables: -``` +```bash sudo chmod -R 755 /home/user/emhass/scripts/dayahead_optim.sh sudo chmod -R 755 /home/user/emhass/scripts/publish_data.sh sudo chmod +x /home/user/emhass/scripts/dayahead_optim.sh @@ -230,7 +230,7 @@ sudo chmod +x /home/user/emhass/scripts/publish_data.sh ### Common for any installation method In `automations.yaml`: -``` +```yaml - alias: EMHASS day-ahead optimization trigger: platform: time @@ -247,7 +247,7 @@ In `automations.yaml`: In these automations the day-ahead optimization is performed everyday at 5:30am and the data is published every 5 minutes. The final action will be to link a sensor value in Home Assistant to control the switch of a desired controllable load. For example imagine that I want to control my water heater and that the `publish-data` action is publishing the optimized value of a deferrable load that I want to be linked to my water heater desired behavior. In this case we could use an automation like this one below to control the desired real switch: -``` +```yaml automation: - alias: Water Heater Optimized ON trigger: @@ -262,7 +262,7 @@ automation: entity_id: switch.water_heater_switch ``` A second automation should be used to turn off the switch: -``` +```yaml automation: - alias: Water Heater Optimized OFF trigger: @@ -284,7 +284,7 @@ The `publish-data` command will push to Home Assistant the optimization results The `publish-data` command will also publish PV and load forecast data on sensors `p_pv_forecast` and `p_load_forecast`. If using a battery, then the battery optimized power and the SOC will be published on sensors `p_batt_forecast` and `soc_batt_forecast`. On these sensors the future values are passed as nested attributes. It is possible to provide custm sensor names for all the data exported by the `publish-data` command. For this, when using the `publish-data` endpoint just add some runtime parameters as dictionaries like this: -``` +```yaml shell_command: publish_data: "curl -i -H \"Content-Type:application/json\" -X POST -d '{\"custom_load_forecast_id\": {\"entity_id\": \"sensor.p_load_forecast\", \"unit_of_measurement\": \"W\", \"friendly_name\": \"Load Power Forecast\"}}' http://localhost:5000/action/publish-data" ``` @@ -292,7 +292,7 @@ shell_command: These keys are available to modify: `custom_pv_forecast_id`, `custom_load_forecast_id`, `custom_batt_forecast_id`, `custom_batt_soc_forecast_id`, `custom_grid_forecast_id`, `custom_cost_fun_id`, `custom_deferrable_forecast_id`, `custom_unit_load_cost_id` and `custom_unit_prod_price_id`. If you provide the `custom_deferrable_forecast_id` then the passed data should be a list of dictionaries, like this: -``` +```yaml shell_command: publish_data: "curl -i -H \"Content-Type:application/json\" -X POST -d '{\"custom_deferrable_forecast_id\": [{\"entity_id\": \"sensor.p_deferrable0\",\"unit_of_measurement\": \"W\", \"friendly_name\": \"Deferrable Load 0\"},{\"entity_id\": \"sensor.p_deferrable1\",\"unit_of_measurement\": \"W\", \"friendly_name\": \"Deferrable Load 1\"}]}' http://localhost:5000/action/publish-data" ``` @@ -342,11 +342,11 @@ The valid values to pass for both forecast data and MPC related data are explain It is possible to provide EMHASS with your own forecast data. For this just add the data as list of values to a data dictionary during the call to `emhass` using the `runtimeparams` option. For example if using the add-on or the standalone docker installation you can pass this data as list of values to the data dictionary during the `curl` POST: -``` +```bash curl -i -H 'Content-Type:application/json' -X POST -d '{"pv_power_forecast":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 141.22, 246.18, 513.5, 753.27, 1049.89, 1797.93, 1697.3, 3078.93, 1164.33, 1046.68, 1559.1, 2091.26, 1556.76, 1166.73, 1516.63, 1391.13, 1720.13, 820.75, 804.41, 251.63, 79.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}' http://localhost:5000/action/dayahead-optim ``` Or if using the legacy method using a Python virtual environment: -``` +```bash emhass --action 'dayahead-optim' --config '/home/user/emhass/config_emhass.yaml' --runtimeparams '{"pv_power_forecast":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 141.22, 246.18, 513.5, 753.27, 1049.89, 1797.93, 1697.3, 3078.93, 1164.33, 1046.68, 1559.1, 2091.26, 1556.76, 1166.73, 1516.63, 1391.13, 1720.13, 820.75, 804.41, 251.63, 79.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}' ``` @@ -419,10 +419,16 @@ When applying this controller, the following `runtimeparams` should be defined: A correct call for a MPC optimization should look like: +```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}' http://192.168.3.159:5000/action/naive-mpc-optim ``` +*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 ``` + + ## A machine learning forecaster Starting in v0.4.0 a new machine learning forecaster class was introduced. From 60f5f465551bc488ac133c2fb73b14f55050a8e0 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:55:16 +0000 Subject: [PATCH 15/23] Docker, adjusted cbc symlink --- Dockerfile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index ba076c57..e85e8ace 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,15 +48,14 @@ RUN apt-get update \ libatlas-base-dev \ libopenblas-dev #specify hdf5 -RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include && export HDF5_DIR=/usr/include/hdf5 -#try symlink apt cbc to pulp python directory -RUN ln -sf /usr/bin/cbc /usr/local/lib/python3.11/dist-packages/pulp/solverdir/cbc/linux/32/cbc || echo "cbc link didnt work" - - +RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include && export HDF5_DIR=/usr/include/hdf5 #install packages from pip, use piwheels if arm RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && pip3 install --index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -r requirements.txt || pip3 install --no-cache-dir --break-system-packages -r requirements.txt +#try symlink apt cbc to pulp cbc in python directory (for 32bit) +RUN [[ "${TARGETARCH}" == "armhf" ]] && ln -sf /usr/bin/cbc /usr/local/lib/python3.11/dist-packages/pulp/solverdir/cbc/linux/32/cbc || echo "cbc symlink didnt work/not required" + #remove build only packages RUN apt-get purge -y --auto-remove \ git \ @@ -79,7 +78,7 @@ COPY config_emhass.yaml /app/ RUN mkdir -p /app/data/ #------------------------- -#EMHASS-ADDON Default (this has no emhass packadge) +#EMHASS-ADDON Default (this has no emhass package) FROM base as addon LABEL \ From 0466746369cdde1ebacf141cc87f7e960f8dc660 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Fri, 8 Mar 2024 18:18:47 +1030 Subject: [PATCH 16/23] optimization.py, if COIN_CMD but lp_solver_path=empty, then set default --- src/emhass/optimization.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/emhass/optimization.py b/src/emhass/optimization.py index 0172463d..83306adf 100644 --- a/src/emhass/optimization.py +++ b/src/emhass/optimization.py @@ -85,6 +85,9 @@ def __init__(self, retrieve_hass_conf: dict, optim_conf: dict, plant_conf: dict, self.lp_solver_path = 'empty' if self.lp_solver != 'COIN_CMD' and self.lp_solver_path != 'empty': self.logger.error("Use COIN_CMD solver name if you want to set a path for the LP solver") + if self.lp_solver == 'COIN_CMD' and self.lp_solver_path == 'empty': #if COIN_CMD but lp_solver_path is empty + self.logger.warning("lp_solver=COIN_CMD but lp_solver_path=empty, attempting to use lp_solver_path=/usr/bin/cbc") + self.lp_solver_path = '/usr/bin/cbc' def perform_optimization(self, data_opt: pd.DataFrame, P_PV: np.array, P_load: np.array, unit_load_cost: np.array, unit_prod_price: np.array, From 352ab6a981908c6126cc82e096734c5117432f08 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Fri, 8 Mar 2024 20:33:13 +1030 Subject: [PATCH 17/23] Docker add armv7 back in cbc symlink as precaution --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e85e8ace..aaec6550 100644 --- a/Dockerfile +++ b/Dockerfile @@ -54,7 +54,7 @@ RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include && export HDF5_DIR= RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && pip3 install --index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -r requirements.txt || pip3 install --no-cache-dir --break-system-packages -r requirements.txt #try symlink apt cbc to pulp cbc in python directory (for 32bit) -RUN [[ "${TARGETARCH}" == "armhf" ]] && ln -sf /usr/bin/cbc /usr/local/lib/python3.11/dist-packages/pulp/solverdir/cbc/linux/32/cbc || echo "cbc symlink didnt work/not required" +RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && ln -sf /usr/bin/cbc /usr/local/lib/python3.11/dist-packages/pulp/solverdir/cbc/linux/32/cbc || echo "cbc symlink didnt work/not required" #remove build only packages RUN apt-get purge -y --auto-remove \ From 56826ec8c7456899a4f9cb48b3ce8a2bcb33ee6e Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sat, 9 Mar 2024 12:49:35 +1030 Subject: [PATCH 18/23] develop pipeline example, Dockerfile tweak --- Dockerfile | 2 +- docs/develop.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index aaec6550..277b0610 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,7 +50,7 @@ RUN apt-get update \ #specify hdf5 RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include && export HDF5_DIR=/usr/include/hdf5 -#install packages from pip, use piwheels if arm +#install packages from pip, use piwheels if arm 32bit RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && pip3 install --index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -r requirements.txt || pip3 install --no-cache-dir --break-system-packages -r requirements.txt #try symlink apt cbc to pulp cbc in python directory (for 32bit) diff --git a/docs/develop.md b/docs/develop.md index c21e223a..b299d75f 100644 --- a/docs/develop.md +++ b/docs/develop.md @@ -281,7 +281,66 @@ docker build -t emhass/docker --build-arg build_version=addon-local . docker run -it -p 5000:5000 --name emhass-container -e EMHASS_KEY -e EMHASS_URL -e TIME_ZONE -e LAT -e LON -e ALT emhass/docker ``` +### Example Docker testing pipeline +If you are wishing to test your changes compatibility, check out this example as a template: + +*Linux:* +*Assuming docker and git installed* +```bash +#setup environment variables for test +export repo=https://github.com/davidusb-geek/emhass.git +export branch=master +#Ex. HAURL=https://localhost:8123/ +export HAURL=HOMEASSISTANTURLHERE +export HAKEY=HOMEASSISTANTKEYHERE + +git clone $repo +cd emhass +git checkout $branch +``` +```bash +#testing addon (build and run) +docker build -t emhass/docker --build-arg build_version=addon-local . +docker run --rm -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 $HAURL --key $HAKEY +``` +```bash +#run actions on a separate terminal +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}' http://localhost:5000/action/naive-mpc-optim +curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/publish-data +curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/dayahead-optim +curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/forecast-model-fit +curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/forecast-model-predict +curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/forecast-model-tune +``` + +```bash +#testing standalone (build and run) +docker build -t emhass/docker --build-arg build_version=standalone . +#make secrets_emhass +cat <> secrets_emhass.yaml +hass_url: $HAURL +long_lived_token: $HAKEY +time_zone: Europe/Paris +lat: 45.83 +lon: 6.86 +alt: 4807.8 +EOT +docker run --rm -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 +``` +```bash +#run actions on a separate terminal +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}' http://localhost:5000/action/naive-mpc-optim +curl -i -H 'Content-Type:application/json' -X POST -d '{}' http://localhost:5000/action/publish-data +curl -i -H 'Content-Type:application/json' -X POST -d '{}' http://localhost:5000/action/dayahead-optim +curl -i -H 'Content-Type:application/json' -X POST -d '{}' http://localhost:5000/action/forecast-model-fit +curl -i -H 'Content-Type:application/json' -X POST -d '{}' http://localhost:5000/action/forecast-model-predict +curl -i -H 'Content-Type:application/json' -X POST -d '{}' http://localhost:5000/action/forecast-model-tune +``` + +User may wish to re-test with tweaked parameters such as `lp_solver` and `weather_forecast_method`, in `config_emhass.yaml` *(standalone)* or `options.json` *(addon)*, to broaden the testing scope. +*see [EMHASS & EMHASS-Add-on differences](https://emhass.readthedocs.io/en/latest/differences.html) for more information on how these config_emhass & options files differ* + ## Step 3 - Pull request Once developed, commit your code, and push to your fork. -Then submit a pull request with your fork to the [davidusb-geek/emhass@master](https://github.com/davidusb-geek/emhass) repository. +Then submit a pull request with your fork to the [davidusb-geek/emhass@master](https://github.com/davidusb-geek/emhass) repository. \ No newline at end of file From 522ce29efc0a8f2c2080d45898af9b9fe6b0c824 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sat, 9 Mar 2024 16:57:39 +1030 Subject: [PATCH 19/23] slight documentation tweaks --- config_emhass.yaml | 4 ++-- docs/develop.md | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config_emhass.yaml b/config_emhass.yaml index 1b29cc19..a9f51ce7 100644 --- a/config_emhass.yaml +++ b/config_emhass.yaml @@ -51,8 +51,8 @@ optim_conf: prod_price_forecast_method: 'constant' # options are 'constant' for constant fixed value or 'csv' to load custom price forecast from a CSV file prod_sell_price: 0.065 # power production selling price in €/kWh (only needed if prod_price_forecast_method='constant') set_total_pv_sell: False # consider that all PV power is injected to the grid (self-consumption with total sell) - lp_solver: 'default' # set the name of the linear programming solver that will be used - lp_solver_path: 'empty' # set the path to the LP solver + lp_solver: 'default' # set the name of the linear programming solver that will be used. Options are 'PULP_CBC_CMD', 'GLPK_CMD' and 'COIN_CMD' (default). + lp_solver_path: 'empty' # set the path to the LP solver, COIN_CMD default is /usr/bin/cbc set_nocharge_from_grid: False # avoid battery charging from the grid set_nodischarge_to_grid: True # avoid battery discharging to the grid set_battery_dynamic: False # add a constraint to limit the dynamic of the battery power in power per time unit diff --git a/docs/develop.md b/docs/develop.md index b299d75f..5396603b 100644 --- a/docs/develop.md +++ b/docs/develop.md @@ -301,7 +301,7 @@ git checkout $branch ```bash #testing addon (build and run) docker build -t emhass/docker --build-arg build_version=addon-local . -docker run --rm -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 $HAURL --key $HAKEY +docker run --rm -it -p 5000:5000 --name emhass-container -v $(pwd)/options.json:/app/options.json -e LAT="45.83" -e LON="6.86" -e ALT="4807.8" -e TIME_ZONE="Europe/Paris" emhass/docker --url $HAURL --key $HAKEY ``` ```bash #run actions on a separate terminal @@ -340,6 +340,8 @@ curl -i -H 'Content-Type:application/json' -X POST -d '{}' http://localhost:5000 User may wish to re-test with tweaked parameters such as `lp_solver` and `weather_forecast_method`, in `config_emhass.yaml` *(standalone)* or `options.json` *(addon)*, to broaden the testing scope. *see [EMHASS & EMHASS-Add-on differences](https://emhass.readthedocs.io/en/latest/differences.html) for more information on how these config_emhass & options files differ* +*Note: may need to set `--build-arg TARGETARCH=YOUR-ARCH` in docker build* + ## Step 3 - Pull request Once developed, commit your code, and push to your fork. From a5a49a9647a347c89829e45665ec86e66cf9fd2d Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sat, 9 Mar 2024 17:12:13 +1030 Subject: [PATCH 20/23] Dockerfile. if armv7 install libatomic1 --- Dockerfile | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 277b0610..be0b0f38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,17 @@ ## EMHASS Docker -## Docker run ADD-ON testing example: +## Docker run ADD-ON testing example: ## docker build -t emhass/docker --build-arg build_version=addon-local . ## 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 + ## 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 -#os_version +ARG build_version=standalone +#os_version #armhf = raspbian #amd64, armv7, aarch64 = debian -ARG os_version=debian +ARG os_version=debian FROM ghcr.io/home-assistant/$TARGETARCH-base-$os_version:bookworm AS base @@ -22,6 +22,7 @@ ENV TARGETARCH=${TARGETARCH:?} WORKDIR /app COPY requirements.txt /app/ +#apt package install RUN apt-get update \ && apt-get install -y --no-install-recommends \ libffi-dev \ @@ -46,9 +47,9 @@ RUN apt-get update \ libglpk-dev \ glpk-utils \ libatlas-base-dev \ - libopenblas-dev + libopenblas-dev #specify hdf5 -RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include && export HDF5_DIR=/usr/include/hdf5 +RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include && export HDF5_DIR=/usr/include/hdf5 #install packages from pip, use piwheels if arm 32bit RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && pip3 install --index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -r requirements.txt || pip3 install --no-cache-dir --break-system-packages -r requirements.txt @@ -56,6 +57,10 @@ RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && pip3 inst #try symlink apt cbc to pulp cbc in python directory (for 32bit) RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && ln -sf /usr/bin/cbc /usr/local/lib/python3.11/dist-packages/pulp/solverdir/cbc/linux/32/cbc || echo "cbc symlink didnt work/not required" +#if armv7 try install libatomic1 to fix scipy issue +RUN [[ "${TARGETARCH}" == "armv7" ]] && apt-get update && apt-get install libatomic1 || echo "libatomic1 cant be installed" + + #remove build only packages RUN apt-get purge -y --auto-remove \ git \ @@ -89,7 +94,7 @@ LABEL \ io.hass.arch="aarch64|amd64|armhf|armv7" #----------- -#EMHASS-ADD-ON Testing with pip emhass (closest testing reference) +#EMHASS-ADD-ON Testing with pip emhass (closest testing reference) FROM addon as addon-pip #set build arg for pip version ARG build_pip_version="" @@ -102,7 +107,7 @@ ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True", "--no_respo #----------- #EMHASS-ADD-ON Testing from local files FROM addon as addon-local -COPY src/emhass/ /app/src/emhass/ +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/ @@ -142,7 +147,7 @@ ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True" , "--no_resp #EMHASS STANDALONE FROM base as standalone -COPY src/emhass/ /app/src/emhass/ +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/ From fa299327d1672a5b2018b45664ff653fb1f07132 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sat, 9 Mar 2024 17:13:05 +1030 Subject: [PATCH 21/23] Documentation tweak --- config_emhass.yaml | 2 +- docs/develop.md | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/config_emhass.yaml b/config_emhass.yaml index a9f51ce7..07832780 100644 --- a/config_emhass.yaml +++ b/config_emhass.yaml @@ -51,7 +51,7 @@ optim_conf: prod_price_forecast_method: 'constant' # options are 'constant' for constant fixed value or 'csv' to load custom price forecast from a CSV file prod_sell_price: 0.065 # power production selling price in €/kWh (only needed if prod_price_forecast_method='constant') set_total_pv_sell: False # consider that all PV power is injected to the grid (self-consumption with total sell) - lp_solver: 'default' # set the name of the linear programming solver that will be used. Options are 'PULP_CBC_CMD', 'GLPK_CMD' and 'COIN_CMD' (default). + lp_solver: 'default' # set the name of the linear programming solver that will be used. Options are 'PULP_CBC_CMD', 'GLPK_CMD' and 'COIN_CMD'. lp_solver_path: 'empty' # set the path to the LP solver, COIN_CMD default is /usr/bin/cbc set_nocharge_from_grid: False # avoid battery charging from the grid set_nodischarge_to_grid: True # avoid battery discharging to the grid diff --git a/docs/develop.md b/docs/develop.md index 5396603b..3a8e8128 100644 --- a/docs/develop.md +++ b/docs/develop.md @@ -306,11 +306,12 @@ docker run --rm -it -p 5000:5000 --name emhass-container -v $(pwd)/options.json: ```bash #run actions on a separate terminal 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}' http://localhost:5000/action/naive-mpc-optim -curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/publish-data +curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/perfect-optim curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/dayahead-optim curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/forecast-model-fit curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/forecast-model-predict curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/forecast-model-tune +curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/publish-data ``` ```bash @@ -330,11 +331,12 @@ docker run --rm -it -p 5000:5000 --name emhass-container -v $(pwd)/config_emhass ```bash #run actions on a separate terminal 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}' http://localhost:5000/action/naive-mpc-optim -curl -i -H 'Content-Type:application/json' -X POST -d '{}' http://localhost:5000/action/publish-data -curl -i -H 'Content-Type:application/json' -X POST -d '{}' http://localhost:5000/action/dayahead-optim -curl -i -H 'Content-Type:application/json' -X POST -d '{}' http://localhost:5000/action/forecast-model-fit -curl -i -H 'Content-Type:application/json' -X POST -d '{}' http://localhost:5000/action/forecast-model-predict -curl -i -H 'Content-Type:application/json' -X POST -d '{}' http://localhost:5000/action/forecast-model-tune +curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/perfect-optim +curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/dayahead-optim +curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/forecast-model-fit +curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/forecast-model-predict +curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/forecast-model-tune +curl -i -H 'Content-Type:application/json' -X POST http://localhost:5000/action/publish-data ``` User may wish to re-test with tweaked parameters such as `lp_solver` and `weather_forecast_method`, in `config_emhass.yaml` *(standalone)* or `options.json` *(addon)*, to broaden the testing scope. From cc5d7fb79da8658f72ac54f2b3efb8ded2f93401 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sat, 9 Mar 2024 18:11:45 +1030 Subject: [PATCH 22/23] Dockerfile typos --- Dockerfile | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index be0b0f38..971504c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,21 @@ ## EMHASS Docker -## Docker run ADD-ON testing example: +## Docker run addon testing example: ## docker build -t emhass/docker --build-arg build_version=addon-local . ## 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 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 -#os_version -#armhf = raspbian -#amd64, armv7, aarch64 = debian + + +#armhf=raspbian, amd64,armv7,aarch64=debian ARG os_version=debian FROM ghcr.io/home-assistant/$TARGETARCH-base-$os_version:bookworm AS base -#check if TARGETARCH passed by build-arg +#check if TARGETARCH was passed by build-arg ARG TARGETARCH ENV TARGETARCH=${TARGETARCH:?} @@ -54,10 +54,10 @@ RUN ln -s /usr/include/hdf5/serial /usr/include/hdf5/include && export HDF5_DIR= #install packages from pip, use piwheels if arm 32bit RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && pip3 install --index-url=https://www.piwheels.org/simple --no-cache-dir --break-system-packages -r requirements.txt || pip3 install --no-cache-dir --break-system-packages -r requirements.txt -#try symlink apt cbc to pulp cbc in python directory (for 32bit) +#try, symlink apt cbc, to pulp cbc, in python directory (for 32bit) RUN [[ "${TARGETARCH}" == "armhf" || "${TARGETARCH}" == "armv7" ]] && ln -sf /usr/bin/cbc /usr/local/lib/python3.11/dist-packages/pulp/solverdir/cbc/linux/32/cbc || echo "cbc symlink didnt work/not required" -#if armv7 try install libatomic1 to fix scipy issue +#if armv7, try install libatomic1 to fix scipy issue RUN [[ "${TARGETARCH}" == "armv7" ]] && apt-get update && apt-get install libatomic1 || echo "libatomic1 cant be installed" @@ -76,7 +76,7 @@ RUN apt-get purge -y --auto-remove \ libnetcdf-dev \ && rm -rf /var/lib/apt/lists/* -#copy config file (on all builds) +#copy config file COPY config_emhass.yaml /app/ #make sure data directory exists @@ -94,7 +94,7 @@ LABEL \ io.hass.arch="aarch64|amd64|armhf|armv7" #----------- -#EMHASS-ADD-ON Testing with pip emhass (closest testing reference) +#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="" @@ -154,9 +154,9 @@ COPY src/emhass/static/img/ /app/src/emhass/static/img/ COPY data/opt_res_latest.csv /app/data/ COPY README.md /app/ COPY setup.py /app/ -#secrets file will need to be copied manually at docker run +#secrets file can be copied manually at docker run -#set env variables +#set python env variables ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 From 1a332c396c173486d1b583e9acf714b915225410 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sat, 9 Mar 2024 18:15:55 +1030 Subject: [PATCH 23/23] Dockerfile typos --- Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 971504c1..9eb1decf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -83,7 +83,7 @@ COPY config_emhass.yaml /app/ RUN mkdir -p /app/data/ #------------------------- -#EMHASS-ADDON Default (this has no emhass package) +##EMHASS-Add-on default (this has no emhass package) FROM base as addon LABEL \ @@ -94,7 +94,7 @@ LABEL \ io.hass.arch="aarch64|amd64|armhf|armv7" #----------- -#EMHASS-ADD-ON Testing with pip emhass (EMHASS-Add-on testing reference) +#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="" @@ -105,7 +105,7 @@ COPY options.json /app/ ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True", "--no_response", "True"] #----------- -#EMHASS-ADD-ON Testing from local files +#EMHASS-Add-on testing from local files FROM addon as addon-local COPY src/emhass/ /app/src/emhass/ COPY src/emhass/templates/ /app/src/emhass/templates/ @@ -122,7 +122,7 @@ ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True" , "--no_resp #----------- -#EMHASS-ADD-ON testing with git +#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 @@ -144,7 +144,7 @@ RUN pip3 install --no-cache-dir --break-system-packages --no-deps --force-reinst ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True" , "--no_response", "True"] #------------------------- -#EMHASS STANDALONE +#EMHASS stanalone FROM base as standalone COPY src/emhass/ /app/src/emhass/