Raspberry Pi Installation

_To install on Raspberry Pi, you need a 64bit OS, as [Prisma.io](https://prisma.io) does not support 32bit._

1. Open the terminal on your Raspberry Pi and install the Github Client:

curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list & /dev/null sudo apt update sudo apt install gh

2. Clone this project into a suitable directory, ie `/var/www/homeanalytics`

3. Install Node.js:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - sudo apt-get install -y nodejs
4. Install Node.js dependencies:
cd /[PROJECT_PATH]/app/web npm i

5. Initialize the Prisma client by running `npx prisma generate`

6. Install Python dependencies:

cd /[PROJECT_PATH]/app/tasks pip3 install -r ./requirements.txt

7. Set the DB path as an environment variable:

echo "export HA_DB_URL=/[PROJECT_PATH]/db/prod.db" >> ~/.profile

8. Set up the cron tasks - adapt `example-crontab.txt` to your project paths and copy the content into the crontab editor (`crontab -e`) 9. Run the Web UI in the background using [PM2](https://pm2.keymetrics.io/)

sudo npm install -g pm2 pm2 start "cd /[PROJECT_PATH]/app/web/; npm run dev" pm2 save

10. You should now be able to access your installation on your local network at the Pi's IP address, for example `http://10.0.0.5:3000`

Pi Kiosk Display

If you want to connect your Pi to a display ([as demonstrated here](https://medium.com/electric-sheep-energy/building-a-diy-energy-monitor-with-a-raspberry-pi-a5ae40c1a2a6)), you can set up Chrome to run in 'kiosk mode'. To do this, log into your Pi directly or via VNC (the Chrome command **will fail** via SSH), and launch the terminal window.

First of all, disable screensaver and power-saving settings:

sudo nano /etc/xdg/lxsession/LXDE/autostart

Comment out the line:

`@xscreensaver -no-splash`

And add these lines:

@xset s off @xset -dpms @xset s noblank

You may need to disable screen blanking in raspi-config too:

sudo raspi-config

Navigate to **Display Options**, find **Screen Blanking** and turn it off. You will need to restart your Pi for changes to take effect.

Finally run the following command from a VNC terminal window to launch a full screen instance of Chrome:

chromium-browser --noerrdialogs --disable-infobars --kiosk http://localhost:3000/pi &

You can then safely exit the VNC session.