/homebase

Raspberry Pi based home monitoring dashboard

Primary LanguageJavaScriptMIT LicenseMIT

Homebase

Raspberry Pi based home monitoring dashboard

Run

docker compose up --build

Develop

Run scripts direclty:

cd ./databot
LOGLEVEL=DEBUG INFLUX_URL=http://localhost:8086 PIPENV_DOTENV_LOCATION=../.env pipenv run python3 render.py
cd ./databot
INFLUX_URL=http://localhost:8086 ts-node index.ts -c ../.env -d

For some reason the pipenv in the Docker environment won't work. Thus a requirements.txt file is used. To update it run pipenv run pip freeze > requirements.txt.

Commands

Migrate data

Although a migration is performed when smartmeter data is fetched the first time, you can trigger a manual migration with following command:

docker compose run --rm databot databot --migrate

Archive previous week charts

This task is performed automatically via a cron job

docker compose run --rm databot python3 render.py --archive

Flux queries

Query all data:

from(bucket: "smartmeter")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) =>
    r._measurement == "meteredValues" and
    r._field == "value"
  )

Split in 6h time windows:

from(bucket: "smartmeter")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) =>
    r._measurement == "meteredValues" and
    r._field == "value"
  )
  |> aggregateWindow(every: 6h, offset: -12h, fn: mean)
from(bucket: "smartmeter")
  |> range(start: time(v: "2022-07-10T23:45:00Z"), stop: time(v: "2022-07-18T00:00:00Z"))
  |> filter(fn: (r) =>
    r._measurement == "meteredValues" and
    r._field == "value"
  )
  //|> aggregateWindow(every: 6h, createEmpty: false, offset: -12h, fn: mean)
  //|> count()

Setup

Raspberry Pi

  1. Install Raspberry Pi OS Lite (64-Bit)

  2. Install Docker (see Install Docker Engine on Debian for latest instructions, at this time the Install using the convenience script section must be used for Raspberry Pi):

    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh
    
    # Let the logged-in user use `docker` without `sudo`
    sudo usermod -aG docker ${USER}
  3. (Optional) Make Raspian OS auto-update itself (confirm with Yes in the configuration)

    sudo apt-get install unattended-upgrades keychain # keychain for password protected ssh keys
    sudo dpkg-reconfigure -plow unattended-upgrades
  4. Prepare Kindle (see below)

  5. Setup USB network with Kindle (must be attached and prepared with USBNetwork)

    TODO: Makeifconfig usb0 ... better since it's always set in the cron job, maybe https://www.mobileread.com/forums/showthread.php?t=342904 helps.

    On the raspberry add the following with sudo nano /etc/dhcpcd.conf:

    # Kindle via USBNetwork
    interface usb0
    static ip_address=192.168.15.244/24
    static routers=192.168.15.1
    

    Then sudo reboot.

    Generate a ssh keypair with

    ssh-keygen -t ed25519
    

    If you're using a password you can add it to ssh-agent:

    ssh-add ~/.ssh/id_ed25519
    

    This key must be added to the Kindle (see below).

    Start the interface with (actually only needed if you want to manually ssh into the Kindle. It's handled by the cron job)

    sudo ifconfig usb0 192.168.15.201
    

    Make the the kindle cron script executable with chmod u+x <absolute path to clone git repot>/kindle_cron.sh add following cronjob with crontab -e:

    */15 * * * * <absolute path to clone git repot>/kindle_cron.sh
    

App

Clone this repo and create a ./.env in the app folder with following content:

USERNAME=...
PASSWORD=...
METER_ID=...
INFLUX_ORG=ulrichlehner
INFLUX_BUCKET=smartmeter
INFLUX_TOKEN=<genereate a secure token string>
TZ=Europe/Vienna
DOCKER_INFLUXDB_INIT_USERNAME=admin
DOCKER_INFLUXDB_INIT_PASSWORD=<generate a secure password>
DOCKER_INFLUXDB_INIT_ORG=ulrichlehner
DOCKER_INFLUXDB_INIT_BUCKET=smartmeter
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=<genereate a secure token string>

The variables INFLUX_BUCKET and DOCKER_INFLUXDB_INIT_BUCKET must have the same value, as well as INFLUX_TOKEN = DOCKER_INFLUXDB_INIT_ADMIN_TOKEN and INFLUX_ORG = DOCKER_INFLUXDB_INIT_ORG.

Kindle

Kindle Paperwhite 5th Generation (EY21) w/ firmware 5.6.1.1 jailbreak

These instructions are only tested with the software and hardware version as above! If you have a different hardware / software setup you'll have to find instructions for your case.

Setup

  • Apply following settings in KUAL / USBNetwork:

    Enable SSH at boot
    Make dropbear quiet
    Toggle USB Network
    
  • Add the Rasperry Pi's public SSH key to /mnt/us/etc/authorized_keys (the file must be created manually if it doesn't exist)

Useful links