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
13 changes: 9 additions & 4 deletions predbat/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,22 @@ Predbat can be run on a seperate machine also, you will need a MacOS with Python

* Download the contents of 'https://github.com/springfall2008/predbat_addon/tree/main/predbat' onto your machine
* You should see Dockerfile.standalone and rootfs directories
* Download predbat.py from Predbat repo (https://github.com/springfall2008/batpred/blob/main/apps/predbat/predbat.py) and place it into rootfs
* Download apps.yaml from Predbat repo (https://github.com/springfall2008/batpred/blob/main/apps/predbat/config/apps.yaml), place it into rootfs and edit it as per the Predbat documentation.
* Download apps.yaml from Predbat repo (https://github.com/springfall2008/batpred/blob/main/apps/predbat/config/apps.yaml), place it into config directory somewhere in the host machine and edit it as per the Predbat documentation. this config directory will be mounted on the docker container.
* 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

* Build and run your docker as follows:
* Build your docker as follows:

```
docker build . -t predbat -f ./Dockerfile.standalone
docker run docker.io/library/predbat
```
* Modify the docker compose file compose-standalone.yaml to add the config directory by replacing the string "/wkspace/homeassistant/predbat"

* Run container:

```
docker-compose -f compose-standalone.yaml up
```

Look into the docker under /config/predbat.log for the logfiles
Expand Down
12 changes: 8 additions & 4 deletions predbat/Dockerfile.standalone
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ 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
RUN apt-get install -y python3-aiohttp
RUN apt-get install -y python3-tz
RUN apt-get install -y vim wget zip

WORKDIR /config
COPY rootfs /config
WORKDIR /wkspace
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of the wkspace?

Copy link
Author

@rsarwar87 rsarwar87 Sep 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where all the downloaded zip files and extraction takes place. also stores the hass.py etc.. in order to keep the config directory clean. been using it for a while with no problem

COPY rootfs /wkspace
RUN wget https://codeload.github.com/springfall2008/batpred/zip/refs/heads/main -O main.zip
RUN unzip main.zip
RUN cp batpred-main/apps/predbat/*py .

#COPY requirements.txt /tmp/
#RUN pip3 install -r /tmp/requirements.txt
Expand Down
80 changes: 80 additions & 0 deletions predbat/compose-standalone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
services:
eager_sammet:

cap_drop:
- "AUDIT_CONTROL"
- "BLOCK_SUSPEND"
- "DAC_READ_SEARCH"
- "IPC_LOCK"
- "IPC_OWNER"
- "LEASE"
- "LINUX_IMMUTABLE"
- "MAC_ADMIN"
- "MAC_OVERRIDE"
- "NET_ADMIN"
- "NET_BROADCAST"
- "SYSLOG"
- "SYS_ADMIN"
- "SYS_BOOT"
- "SYS_MODULE"
- "SYS_NICE"
- "SYS_PACCT"
- "SYS_PTRACE"
- "SYS_RAWIO"
- "SYS_RESOURCE"
- "SYS_TIME"
- "SYS_TTY_CONFIG"
- "WAKE_ALARM"

command:
- "csh"
- "-f"
- "run.csh"

container_name: "eager_sammet"

environment:
- "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

hostname: "948b22e2f2d0"

image: "docker.io/library/predbat:latest"

ipc: "private"

labels:
io.hass.arch: ""
io.hass.description: ""
io.hass.name: ""
io.hass.type: "addon"
io.hass.version: ""
maintainer: "springfall2008 (https://github.com/springfall2008)"
org.opencontainers.image.authors: "springfall2008 (https://github.com/springfall2008)"
org.opencontainers.image.created: ""
org.opencontainers.image.description: ""
org.opencontainers.image.documentation: "https://github.com//blob/main/README.md"
org.opencontainers.image.licenses: "MIT"
org.opencontainers.image.ref.name: "ubuntu"
org.opencontainers.image.revision: ""
org.opencontainers.image.source: "https://github.com/"
org.opencontainers.image.title: ""
org.opencontainers.image.url: "https://github.com/springfall2008"
org.opencontainers.image.vendor: "Springfall2008"
org.opencontainers.image.version: ""

logging:
driver: "json-file"
options: {}

network_mode: "host"

ports:
- "5052:5052/tcp"

volumes:
- "/etc/localtime:/etc/localtime:ro"
- "/wkspace/homeassistant/predbat:/config"

working_dir: "/wkspace"

version: "3.6"
12 changes: 6 additions & 6 deletions predbat/rootfs/hass.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ async def main():
return

# Find all .py files in the directory hierarchy
py_files = []
py_files = ['/config/apps.yaml']
for root, dirs, files in os.walk("."):
for file in files:
if (file.endswith(".py") or file == "apps.yaml") and not file.startswith("."):
if (file.endswith(".py")) and not file.startswith("."):
py_files.append(os.path.join(root, file))
print("Watching {} for changes".format(py_files))

Expand Down Expand Up @@ -91,8 +91,8 @@ def log(self, msg, quiet=True):
log_size = self.logfile.tell()
if log_size > 10000000:
self.logfile.close()
os.rename("predbat.log", "predbat.log.1")
self.logfile = open("predbat.log", "w")
os.rename("/config/predbat.log", "/config/predbat.log.1")
self.logfile = open("/config/predbat.log", "w")

async def run_in_executor(self, callback, *args):
"""
Expand Down Expand Up @@ -143,11 +143,11 @@ def __init__(self):
self.run_list = []
self.threads = []

self.logfile = open("predbat.log", "a")
self.logfile = open("/config/predbat.log", "a")

# Open YAML file apps.yaml and read it
self.log("Loading apps.yaml", quiet=False)
with io.open("apps.yaml", "r") as stream:
with io.open("/config/apps.yaml", "r") as stream:
try:
config = yaml.safe_load(stream)
self.args = config["pred_bat"]
Expand Down
4 changes: 2 additions & 2 deletions predbat/rootfs/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import time
print("Bootstrap Predbat")

root = "/config"
root = "/wkspace"

# Check if config exists, if not run locally
if not os.path.exists(root):
root = "./"

# Download the latest Predbat release from Github
if not os.path.exists(root + "/apps.yaml"):
if not os.path.exists("/config/apps.yaml"):
url = "https://api.github.com/repos/springfall2008/batpred/releases"
print("Download Predbat release list from {}".format(url))
try:
Expand Down