Grafana and InfluxDB

Installation and first use of OH4 Openhabian, InfluxDB and Grafana onto a RPi3. From a windows pc.

I created these steps for myself since I want to set up several RPis later. Hopefully others can find them useful.

This may seem repetitive with other online resources. The online docs are great but there are still ‘gotchas’ for a beginner like me. Specifically the permissions for influxDB seems like a step which should be automated if possible in future releases (or maybe I did something wrong – either way the steps below sorted it out). Improvements welcome.

  1. Format sd card in PC (with SD Card Formatter or similar)

  2. Use Raspberry Pi imager to save Openhabian for RPi 3 onto SD Card

  3. Without removing SD Card from pc, navigate to openhabian-config file on SDcard using File Explorer. Open with Notepad. Modify device name, wifi SSID and password if needed (or if using LAN connection, ignore). Don’t want multiple devices with same DNS name.

  4. Insert SD card into RPi, power up

  5. Wait for 20 minutes. This is while system boots up. I got errors in subsequent steps when I tried to rush through

  6. Lookup new IP address in router DHCP table; this is the IP of your new RPi installation

  7. Use PuTTy to navigate to this IP address as hostname. Port 22 using SSH.

  8. Console will appear. Username, pw, both “openhabian”

  9. Execute sudo openhabian-config

  10. Select “Upgrade System”. Expect to lose PuTTY connection somewhere along the line. Reconnect with PuTTY and sudo openhabian-config

  11. Apply improvements – Packages, Bash, System Tweaks, Fix permissions

  12. Apply System Settings – Use ZRam

  13. On pc File Explorer. Right click on ‘This pc’. Select ‘Map Network Drive’. In subsequent dialogue box, type in \\ipAddress of RPi, then click on ‘Browse’. Select ‘openhab-conf’ in the folder options

  14. Open Browser. Navigate to openhab in browser to ipaddress:8080. Create admin user and password.

  15. Go back to PuTTy. Apply Optional Components (Log Viewer, influxDB & Grafana)

  16. Influx and Grafana will require a series of arbitrary usernames and passwords to interact with InfluxDB. Importantly make sure that the usernames for Grafana (to read from InfluxDB) and Openhab (to read from and write to influxdb) are different

See https://community.openhab.org/t/13761/1 this is a more detailed guide

  1. To check that influxDB was installed on RPi correctly, in command line type “influx”. Should see message “InfluxDB shell version…”. We then need to check that your new users – particularly for Openhab user - have read and write privileges.
    Type:
    auth
    Input your Influxdb username and password.
    Type:
    grant all on “databasename” to “user”
    substituting in the correct text for databasename and user. You need to use the quotes.

  2. Check Grafana is working – on browser type ipAddressofRPi:3000

  3. Sign in. Use Grafana pw chosen earlier during installation (user is just ‘admin’)

  4. Select add first data source. Select influxdb. Under HTTP select http://ipAddressofRPi:8086. Ignore Auth. For InfluxDB Details: Input database name, user and pw. Click ‘test’

  5. Openhab will have created its own datasource in Grafana called “openhab_home”. Can use this instead of creating your own.

  6. To confirm which database your Openhab system is using: in browser go to ipAddress:8080, then settings>AddonSettings>InfluxDBPersistence and check that the database and login credentials are as you expected. Thes setttings can be changed here or in the text config file (see two steps below)

  7. Persistence service still needs to be activated : in openhab in browser go to ipaddress:8080, then settings>SystemSettings>Persistence and check the radio button. Don’t forget to save

  8. In text config files, go to services/influxdb.cfg: check that username and password are the ones for Openhab to use Influxdb and that it’s the one you granted read and write access to (“grant all”).

  9. Create a file in your persistence folder in the mounted network drive. Call it influxdb.persist

  10. Illustrative .persist file contents for a shelly switch (choose any Item that is registering changes, as a test)

Strategies {
    everyMinute : "0 * * * * ?"
    everyHour   : "0 0 * * * ?"
    everyDay    : "0 0 0 * * ?"
}

Items {
	Shelly_Pump_Switch_Last_Power_1	: strategy = everyChange
}
  1. In browser, in Grafana, in ‘new visualization’, the button “select measurement” should be clickable and show your Items – pick one to get a graph.

  2. if all working, fine. if not, stop and restart openhabian: in PuTTY, just to be safe:

sudo systemctl stop openhab.service
sudo openhab-cli clean-cache
sudo systemctl start openhab.service

Please be aware that persistence configuration does not need to be done via text files in openHAB4, you can do it via UI. In OH4.0, navigate to the persistence addon and show details. There is a tiny blue gear far right from the “remove” button, all settings are hidden there :slight_smile:
In OH4.1, there should be a link to the persistence settings in the right column under settings.

I am wondering if with openhabian for OH4.0 it is still needed to install influxdb+grafana via openhabian menu 24
or if it is enough just to install the Addon for InfluxDB Persistence (does this include grafana? If no, how can it be setuped via UI?)

InfluxDB as well as Grafana is 3rd party software, so yes, absolutely, if you want to use Grafana with InfluxDB, you’ll have to install it first.

The addons in openHAB are “adapters” to use non-openHAB stuff, it about translating protocols.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.