batmon-ha icon indicating copy to clipboard operation
batmon-ha copied to clipboard

Docker container

Open yue31 opened this issue 3 years ago • 3 comments

Installation requires HA addons. My HA system uses Docker container and it is impossible to use Addons installation. Could you provide instructions on installation with Docker system?

yue31 avatar Oct 22 '22 20:10 yue31

Do you want to run it standalone (without Docker or Home Assistant)? https://github.com/fl4p/batmon-ha/blob/master/doc/Standalone.md

fl4p avatar Oct 24 '22 20:10 fl4p

I tested standalone and it did work. Cell voltages are showing up on screen now. I'll need to figure out how to integrate into docker home assistant. Great work and thank you very much!

yue31 avatar Oct 29 '22 23:10 yue31

Just let you know everything works great with standalone setup and docker HA!

Edit: I did experience the issue of bluetooth lost after a long-lasting connection with daly bms. The issue seems to be disappeared or minimized after setting timeout to 30s and sampling time to 60s.

yue31 avatar Nov 06 '22 01:11 yue31

@fl4p could you please explain how you build docker container? Especially what is base image (BUILD_FROM). I see it requires alpine, s6 and bashio which is pretty specific requirement (do you really need all that?) and I don't see any "official" image with all that onboard . Thanks in advance.

rromrrom avatar Dec 21 '22 07:12 rromrrom

@fl4p ah, sorry, now I got all details. I've been assuming before that this is generic docker image, but not homeassistant specific. All clear now, thanks.

rromrrom avatar Dec 21 '22 09:12 rromrrom

@rromrrom So a docker container cant be built from this repository? I am not using home assistant OS so I cannot use the traditional add-on method, I dont think.

robwolff3 avatar Jan 23 '23 17:01 robwolff3

@robwolff3 I did like this:

  1. go to batmon-ha sources folder
  2. docker build --build-arg BUILD_FROM=homeassistant/aarch64-base:latest -f Dockerfile .

Basically you can do without homeassistant/aarch64-base and use whatever base you want, but you need a bit manual adjustments in Dockerfile

rromrrom avatar Jan 23 '23 17:01 rromrrom

I'm running docker on a amd64 architecture computer. The following worked for me:

  1. Change the first line in run.sh to #!/bin/sh
  2. docker build --build-arg BUILD_FROM=alpine -f Dockerfile -t batmon-ha .

and then I ran it in docker compose with:

  batmon-ha:
    container_name: batmon-ha
    image: batmon-ha
    restart: unless-stopped
    privileged: true
    volumes:
      - ${CONFIGDIR}/batmon-ha/options.json:/app/options.json
      - /var/run/dbus/:/var/run/dbus/:z

robwolff3 avatar Jan 23 '23 19:01 robwolff3

Thanks, I'll reference this in the Standalone readme

fl4p avatar Feb 25 '23 13:02 fl4p

I'm running docker on a amd64 architecture computer. The following worked for me:

1. Change the first line in run.sh to `#!/bin/sh`

2. `docker build --build-arg BUILD_FROM=alpine -f Dockerfile -t batmon-ha .`

and then I ran it in docker compose with:

  batmon-ha:
    container_name: batmon-ha
    image: batmon-ha
    restart: unless-stopped
    privileged: true
    volumes:
      - ${CONFIGDIR}/batmon-ha/options.json:/app/options.json
      - /var/run/dbus/:/var/run/dbus/:z

run.sh has bin renamed to addon_main.sh

Sayrin avatar Dec 14 '23 09:12 Sayrin

Apparently the errors:

fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/edge/main: temporary error (try again later)

require this for raspberrypi

wget http://ftp.de.debian.org/debian/pool/main/libs/libseccomp/libseccomp2_2.5.4-2+b1_armhf.deb
dpkg -i libseccomp2_2.5.4-2+b1_armhf.deb

Dukat-Gul avatar Jan 01 '24 11:01 Dukat-Gul

I just went through the process as well and created a somewhat cleaner setup which avoids the extra install_bleak.py step currently pointing at an old version patched for windows (?). It also sets environment variables through docker-compose instead of addon_main.sh. Finally, it avoids running the container in privileged mode.

I'm running this on a Raspberry Pi (i.e. Linux Debian), but I don't think it matters much.

./services/batmon/Dockerfile:

FROM alpine

WORKDIR /app

RUN apk update \
  && apk add --no-cache \
    python3 \
    bluez \
    py-pip \
    git

RUN rm /usr/lib/python3.11/EXTERNALLY-MANAGED

COPY ./requirements.txt requirements.txt
RUN pip3 install -r requirements.txt

./services/batmon/requirements.txt

bleak==0.20.2
paho-mqtt>=2.0.0
backoff
crcmod

./docker-compose.yml

  batmon:
    container_name: batmon
    build:
      context: ./services/batmon
    restart: unless-stopped
    environment:
      MQTT_HOST: "mosquitto"
      MQTT_USER: ""
      MQTT_PASSWORD: ""
    volumes:
      - /run/dbus:/run/dbus:ro
      - ./volumes/batmon-ha/:/app # Clone the repo in ./volumes/batmon-ha
    command: ["/bin/sh", "-c", "python3 ./main.py"]

coconup avatar Feb 19 '24 13:02 coconup

It would be really nice, if there would be a official maintained container on docker-hub or so. I also dot use HASS OS and also cant use HA addons the normal way. Currently I have no BMS to monitor, but I am planning to buy and found this very interesting integration for HA.

ThomasCr avatar Jul 18 '24 19:07 ThomasCr