diff --git a/Dockerfile b/Dockerfile index c7afc9a..8b29bca 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG BUILD_FROM +ARG BUILD_FROM=homeassistant/amd64-base:latest FROM $BUILD_FROM WORKDIR /app diff --git a/doc/Docker.md b/doc/Docker.md new file mode 100644 index 0000000..e043f32 --- /dev/null +++ b/doc/Docker.md @@ -0,0 +1,41 @@ +# Building and running `batmon-ha` via Docker + +## Step #1: Build the Docker image + +If you are building for a regular x86 ('amd64') architecture run: + + git clone https://github.com/fl4p/batmon-ha.git + cd batmon-ha + docker buildx build --build-arg BUILD_FROM=homeassistant/amd64-base:latest -t batmon-ha "." + + +If you're building `homeassistant/amd64-base:latest` with `homeassistant/aarch64-base:latest` if you're building for an Raspberry Pi. + + +## Step #2: Create the base configuration + +Create a `options.json` configuration file, i.e. in the `batmon-ha` folder. +Use the provided example `doc/options.json.template` and adjust as needed. +Refer to the configuration section in `README.md` for more information. + + cp doc/options.json.template options.json + nano options.json + + +### Step #3a: Run container manually + + docker run -d --privileged --restart unless-stopped --name batmon-ha -v /var/run/dbus/:/var/run/dbus/:z -v $PWD/options.json:/data/options.json:ro batmon-ha + +### Step #3b: Run via docker-compose + +You can also declare `batmon-ha` via an entry in your `docker-compose` file, i.e.: + + batmon-ha: + container_name: batmon-ha + image: batmon-ha + restart: unless-stopped + privileged: true + volumes: + - /path/tooptions.json:/app/options.json:ro + - /var/run/dbus/:/var/run/dbus/:z + diff --git a/doc/Standalone.md b/doc/Standalone.md index b3c6efd..5070e6a 100644 --- a/doc/Standalone.md +++ b/doc/Standalone.md @@ -7,45 +7,8 @@ cd batmon-ha pip3 install -r requirements.txt ``` -Create `options.json` within the `batmon-ha` directory. Use this as an example and adjust as needed: -``` -{ - "devices": [ - { - "address": "", - "type": "daly", - "alias": "daly1" - }, - { - "address": "", - "type": "jk", - "alias": "jk1" - }, - { - "address": "", - "type": "jbd", - "alias": "jbd1" - }, - { - "address": "", - "type": "victron", - "alias": "victron1", - "pin": "000000" - } - ], - "mqtt_broker": "homeassistant.local", - "mqtt_user": "pv", - "mqtt_password": "Offgrid", - "concurrent_sampling": false, - "keep_alive": true, - "sample_period": 1.0, - "publish_period": 1.0, - "invert_current": false, - "expire_values_after": 20, - "verbose_log": false, - "watchdog": false -} -``` +Create `options.json` within the `batmon-ha` directory. +Use the provided example `doc/options.json.template` and adjust as needed. Then start: ``` @@ -74,7 +37,3 @@ Place this file to `/etc/systemd/system/batmon.service` and enable to start on b systemctl enable batmon.service systemctl start batmon.service ``` - - -# Docker -Small modifications are needed to run this inside Docker, see https://github.com/fl4p/batmon-ha/issues/25#issuecomment-1400900525 \ No newline at end of file diff --git a/doc/options.json.template b/doc/options.json.template new file mode 100644 index 0000000..7c050a3 --- /dev/null +++ b/doc/options.json.template @@ -0,0 +1,36 @@ +{ + "devices": [ + { + "address": "", + "type": "", + "alias": "" + "pin": "" + }, + { + "address": "C8:47:8C:E4:55:E5", + "type": "jk", + "alias": "jk_bms1" + }, + { + "address": "C8:47:8C:E4:55:E5", + "type": "jk", + "alias": "jk_bms2" + }, + { + "address": "jk_bms1,jk_bms2", + "type": "group_parallel", + "alias": "jk_battery_group1" + } + ], + "mqtt_broker": "homeassistant.local", + "mqtt_user": "pv", + "mqtt_password": "Offgrid", + "concurrent_sampling": false, + "keep_alive": false, + "sample_period": 60.0, + "publish_period": 60.0, + "invert_current": false, + "expire_values_after": 120, + "verbose_log": false, + "watchdog": true +} \ No newline at end of file diff --git a/run.sh b/run.sh index afd8e20..56ab50d 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,4 @@ -#!/usr/bin/with-contenv bashio +#!/usr/bin/with-contenv /bin/bash python3 install_bleak.py python3 main.py