openHABianPi Initial Setup

Tags: #<Tag:0x00007f7460dd1f40> #<Tag:0x00007f7460dd1e28> #<Tag:0x00007f7460dd1ce8>

After having fucked up my openHAB installation I had to set up my openHABianPi from scratch and took the opportunity to write down the necessary steps. Mainly for myself, so that next time I wouldn’t have to search for all the different tutorials, always hoping not to forget any of the options I deem necessary…
And perhaps some of you can use this guide in a similar situation - or just as inspiration which options might be useful.

Steps:

  • Installation
  • Configuration
  • SSD / Grafana / InfluxDB
  • Amanda-Backup
  • git
  • Decluttering the Log

Installation


Configuration

  • connect to your openHABianPi
    • connect via ssh: ssh openhabian@openhab
    • Password: openhabian
  • open openHABian Configuration Tool: sudo openhabian-config
    • Check for updates - run the following options
      • 01 | Update
      • 02 | Upgrade System
      • 10 | Apply Improvements
        • 11 | Packages
        • 12 | Bash&Vim Settings
        • 13 | System Tweaks
        • 14 | Fix Permissions
        • 15 | FireMotD
      • 30 | System Settings
        • 34 | Change Passwords
          • all: you should not use any of the default passwords - do not skip this step because you think you will take care of that one later…
          • test if the password change did work - somehow the Config Tool doesn’t work for me in regard to password changes. If you have the same trouble the following comands should do the trick for you:
            • Linux system: passwd
            • openHAB Console: sudo passwd openhab
            • Samba: sudo smbpasswd openhabian
            • Amanda backup: sudo passwd backup
        • 31 | Change Hostname - choose an individual hostname
          • remember to use the new hostname when you reconnect via ssh
        • 32 | Set System Locale
          • set if you want to change the system language, for example to display weekdays on your sitemaps in your local language
          • reboot
      • 40 | openHAB related
        • 42 Remote Console
          • enter the password for ‘openHAB Console’ you selected during the step ‘Change Passwords’
          • test from a different computer ( stands for the hostname selected in step ‘Change Hostname’): ssh -p 8101 openhab@<hostname>
  • Close openHAB config with ‘ESC’
  • reboot: sudo reboot

SSD / Grafana / InfluxDB

If you wish to use Grafana & InfluxDB to persist and display stuff, you might also wish to switch your openHAB system to an external USB drive both both to protect your SD card from wear by to many write cycles and a growing database…
Since USB sticks have the same limitations as SD cards you should choose an USB HDD or SSD. If you consider buying a new HDD / SSD for that purpose I recommend to research a bit in regard to how much power the Raspy can deliver vs what your device needs, if your Raspy is able to boot from USB, if the Raspy is able to boot from your specific HDD / SSD, …
In my case the Raspy is not able to boot from my SSD, so I boot from SD card and have everything else on my SSD.

  • Move root to an SSD
    • connect USB drive to your openHABianPi
    • open openHABian Configuration Tool: sudo openhabian-config
    • 30 | System Settings - 37 | Move root to USB
    • reboot
  • Install Grafana & InfluxDB
    • open openHABian Configuration Tool: sudo openhabian-config
    • 20 | Additional Components - 24 | InfluxDB+Grafana
    • reboot
    • Test Installation by visiting http://<hostname>:3000 and signing in with admin and your adminpwd
    • look into the log to to see if you get InfluxDB related error messages - if yes execute the following commands:
      • sudo chown -hR openhab:openhab /etc/openhab2
      • sudo chown openhab:openhabian /etc/openhab2/services/influxdb.cfg
      • influx -port 8086 -username admin -password myinfluxdbadminpwd -host localhost
      • CREATE DATABASE openhab_db
      • CREATE USER admin WITH PASSWORD 'myinfluxdbadminpwd' WITH ALL PRIVILEGES
      • CREATE USER openhab WITH PASSWORD 'myopenhabpassword'
      • CREATE USER grafana WITH PASSWORD 'mygrafanapassword'
      • GRANT ALL ON openhab_db TO openhab
      • GRANT READ ON openhab_db TO grafana
      • (Found at InfluxDB+Grafana persistence and graphing)
    • Guide for starting with InfluxDB, Grafana & openHAB: https://community.openhab.org/t/influxdb-grafana-persistence-and-graphing/

Amanda-Backup

Yes, you want an automated backup!

  • mount a backup drive
    • follow this guide: https://trendblog.net/how-to-mount-your-media-server-or-nas-drive-to-a-raspberry-pi/
    • example:
      • connect to your NAS via SSH (DSM):
      • sudo vim /etc/exports
      • mkdir /volume1/Backup/openHAB
      • append: /volume1/Backup/openHAB <hostname>(rw,async,no_wdelay,crossmnt,no_root_squash,insecure_locks,sec=sys,anonuid=1024,anongid=100)
        • the values for anonuid and anongid can be found under /etc/passwd for the System default user (admin:x:1024:100)
      • sudo exportfs -ra
    • do the following steps on your openHABianPi
      • sudo mkdir /mnt/backup
      • sudo vim /etc/fstab
        • press ‘i’ to insert text
        • Append the following line: <DNS name NAS>://volume1/Backup/openHAB /mnt/backup nfs nouser,atime,auto,rw,dev,exec,suid 0 0
        • press ‘ESC’
        • type ‘:wq’ and press ‘Enter’
      • sudo mount -a
      • sudo chmod 777 /mnt/backup
      • test the mounted folder by creating a file on your Pi and checking the file on your NAS. Than delete the file on your NAS and check on your Pi
  • set up amanda
    • follow this guide: https://github.com/openhab/openhabian/blob/master/docs/openhabian-amanda.md
      • sudo openhabian-config
        • 50 | Backup/Restore
        • 51 | Amanda Backup
          • backup location: /mnt/backup
          • Storage: 1024
    • configure additional folders to be backed up
      • switch to user backup: sudo su - backup
      • vim /etc/amanda/openhab-dir/disklist
      • add: <hostname> /etc/amanda/openhab-dir user-tar
    • test backup
      • currently no backup: amreport openhab-dir
      • run backup: amdump openhab-dir
      • backup report: amreport openhab-dir

git

See https://community.openhab.org/t/git-based-non-public-versioning-and-deploy-workflow/
My git setup is not traditional, but you should be able to tweak it for your purpose without to much trouble.


Decluttering the log

log4j2.appender.event.filter.ItemStateChangedEvent.type = RegexFilter
log4j2.appender.event.filter.ItemStateChangedEvent.regex = .* changed .*
log4j2.appender.event.filter.ItemStateChangedEvent.onMatch = DENY
log4j2.appender.event.filter.ItemStateChangedEvent.onMisMatch = ACCEPT

Feel free to add the steps for options you deem necessary or let me know about improvements for my post :slight_smile:

8 Likes

Nice!
One thing missing, though.
Add in a UPS and a driver to properly shutdown the Pi, to reduce the chances of SD card corruption.

1 Like

Add use of ZRAM (install option 38) to mitigate SD card corruption.

1 Like

nice job! Should be updated in the official wiki.

Anyone is free to edit it. :wink:

In the current form it’s more of a work log, I think for the wiki it would need a little bit more polish :thinking:
On the other hand I would appreciate it if someone would take this post as groundwork for a wiki entry :grinning: