Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions predbat/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ docker run docker.io/library/predbat

Look into the docker under /config/predbat.log for the logfiles

## Running with docker compose

* Download the contents of 'https://github.com/springfall2008/predbat_addon/tree/main/predbat' onto your machine
* Go the the predbat/standalone directory
* Update location for apps.yaml, dashboard.yaml and log files in the docker-compose (/config volume inside the container):
```
- /path/to/predbat/files:/config
```
* Download apps.yaml from Predbat repo (https://github.com/springfall2008/batpred/blob/main/apps/predbat/config/apps.yaml) to location set above, and edit it as per the Predbat documentation.
* Add ha_url / ha_key settings into apps.yaml.
* The ha_url must be your Home Assistant machine e.g. http://homeassistant.local:8123
* The ha_key must be the persistant key you can generate in Home Assistant in your user/security section


* Start the container as follows:

```
docker compose up -d
```

When editing apps.yaml, remember to restart the container.

## Copyright

```text
Expand Down
2 changes: 1 addition & 1 deletion predbat/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pytz
requests
pyyaml
asyncio
aiohttp==3.8.6
aiohttp>=3.8.6
11 changes: 5 additions & 6 deletions predbat/rootfs/startup.py → predbat/rootfs/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
root = "./"

# Download the latest Predbat release from Github
if not os.path.exists(root + "/apps.yaml"):
if not os.path.exists(root + "/predbat.py"):
url = "https://api.github.com/repos/springfall2008/batpred/releases"
print("Download Predbat release list from {}".format(url))
try:
Expand Down Expand Up @@ -60,16 +60,15 @@
shutil.unpack_archive(save_path, unzip_path)
unzip_path = unzip_path + "/batpred-" + tag_name.replace("v", "")
os.system("cp {}/apps/predbat/* {}".format(unzip_path, root))
os.system("cp {}/apps/predbat/config/* {}".format(unzip_path, root))
if not os.path.exists(root + "/apps.yaml"):
print("No apps.yaml found - extracting default.")
os.system("cp {}/apps/predbat/config/* {}".format(unzip_path, root))
else:
print("Error: Unable to find a valid Predbat release")
print("Sleep 5 minutes before restarting")
time.sleep(5*60)
sys.exit(1)


print("Startup")
os.system("cd " + root + "; python3 hass.py")
print("Bootstrapped!")

print("Shutdown, sleeping 30 seconds before restarting")
time.sleep(30)
35 changes: 31 additions & 4 deletions predbat/rootfs/run.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
echo "Running Predbat inside Add-on"
echo "Your API key is: $SUPERVISOR_TOKEN"
#!/bin/bash

ROOT_DIR="/config"
[[ -d ${ROOT_DIR} ]] || ROOT_DIR="./"

if [[ -n ${SUPERVISOR_TOKEN} ]]; then
echo "Running Predbat inside Add-on"
echo "Your API key is: ${SUPERVISOR_TOKEN}"
fi

if [ -f /config/dev ]; then
echo "Dev mode enabled, not copying hass.py"
else
cp /hass.py /config/hass.py
[[ ! -f ${ROOT_DIR}/hass.py ]] && cp /hass.py ${ROOT_DIR}/hass.py
fi

## Bootstrap predbat
python3 /bootstrap.py

## Run
if [[ $? -eq 0 ]]; then
echo "Starting Predbat..."
## Loop if running in HA otherwise let container properties deal with restart
if [[ -n ${SUPERVISOR_TOKEN} ]]; then
while true; do
cd ${ROOT_DIR} && python3 hass.py
echo "Predbat crashed. Restarting in 5 seconds..."
sleep 5
done
else
cd ${ROOT_DIR} && python3 hass.py
fi
else
echo "Bootstrap failed"
fi
python3 /startup.py $SUPERVISOR_TOKEN
32 changes: 8 additions & 24 deletions predbat/Dockerfile.standalone → predbat/standalone/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
#install python en pip
FROM ubuntu:noble
FROM python:3-slim-bookworm

# Set shell
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
WORKDIR /
COPY /rootfs /
COPY requirements.txt /

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get dist-upgrade -y
RUN apt-get install -y python3
RUN apt-get install -y python3-pip
RUN apt-get install -y python3-venv
RUN apt-get install -y python3-requests
RUN apt-get install -y python3-yaml
#RUN apt-get install -y python3-asyncio
RUN apt-get install -y python3-aiohttp
RUN apt-get install csh
RUN apt-get install -y python3-tz

WORKDIR /config
COPY rootfs /config

#COPY requirements.txt /tmp/
#RUN pip3 install -r /tmp/requirements.txt
# Install dependencies
RUN pip3 --no-cache-dir install -r /requirements.txt

# Start app
RUN chmod a+x run.csh
RUN chmod a+x run.sh

ARG BUILD_ARCH
ARG BUILD_DATE
Expand Down Expand Up @@ -52,4 +36,4 @@ LABEL \
org.opencontainers.image.revision=${BUILD_REF} \
org.opencontainers.image.version=${BUILD_VERSION}

CMD [ "csh", "-f", "run.csh"]
ENTRYPOINT /run.sh
14 changes: 14 additions & 0 deletions predbat/standalone/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Small container to run predbat
services:
predbat:
container_name: predbat
image: predbat:latest
build:
context: ../
dockerfile: ./standalone/Dockerfile
environment:
TZ: 'Europe/London'
volumes:
- /path/to/predbat/files:/config
restart: unless-stopped