- Platform information:
- Hardware: Celeron® CPU J3455/4GB RAM/ > 100 GB SSD
- OS: Debian GNU/Linux 10 (buster) / Docker
- Java Runtime Environment: Java 11, Whatever comes with the Docker Image
- openHAB version: openhab/openhab:3.0.0
I am using Grafana to display various Graphs in Openhab. I always had/have the problem that the timestamps displayed in Grafana does not match the real time. (Analyse bellow) Since I spent the last 2-3 week updating my installation I decided to have a deeper look in this issue and tried to fix it.
I figured out that the issue is, that Openhab stores the timestamps without any timezone information in the database, but Grafana assumes that the timestamps are UTC. Reading the documentation for the persistance configuration and a similar problem in the forum, I thought I can come over this issue.
I ended up with the following configuration in services/jdbc.cfg:
url=jdbc:postgresql://postgres:5432/openhab
user=openhab
password=dbpass
sqltype.tablePrimaryKey=TIMESTAMP WITH TIME ZONE
I migrated all my existing itemXXXX tables with to the new format:
alter table <itemtable> alter column time type timestamp with time zone using time at time zone 'Europe/Berlin';
After that, I thought I overcome the problem:
- Since Openhab uses
now()
for inserting rows into the database they are inserted timezone aware. - Grafana now have timestamps in UTC format and the graphs are displayed correctly.
I few days later I realized that the graphs of the new MainUI are off by 1h. After some thoughts, I think the Graphs in the MainUI do not consider the timestamp awareness of the database.
I would like to use Graphs from both sources (Grafana and MainUI). After several hours/days of testing I feel stuck between the 2 formats and don’t see a easy solution to that.
Some Ideas:
- Openhab uses timezone aware timestamp format: Requires changes in the Openhab implementation. Imo this would be the cleanest solution, but may break a lot of different things. I am not able to do that.
- Somhow make the jdbc configuration aware of the timezone Backend: Also requires changes in the Openhab implementation
- Some kind of SQL-View to provide both timezone formats, to provide Grafana a timezone aware table.
This MAY correlate with following [jdbc] Consider local timezone to create time filter by cweitkamp · Pull Request #9445 · openhab/openhab-addons · GitHub
Does somebody have the same issues and solved it somehow? Does somebody see another approach to use Grafana and MainUI Graphs?