This module generates charts based on OpenHab items data using Mysql and Python. This allows you far more advanced charts then OpenHAB will allow. You can have multi-series, bar graphs, etc. Charts are generated by PyGal http://pygal.org, so you can see all options there. The output is a SVG file that can be shown in a sitemap using a Image Element Type. By generating the images in the background, there is also no delay in the App while waiting for a graph to render.
Tested with OpenHAB 2.4 on Openhabian
Multi-series power production with month average
- An OpenHAB installation with Mysql Persistence enabled
- Python 3.5 with numpy, math, time
- pygal http://pygal.org,
pip3 install pygal cairosvg
- Mysql connector for Python
apt-get install python3-mysql.connector
- Cairo for rendering SVG to PNG
apt-get install libcairo2 libopenjp2
- You probably want to load timezones into the MySQL database:
mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root mysql
Extract this library onto the filesystem of the OpenHAB installation, for example in the userdata folder. Write a python file that generates the charts and execute using
/usr/bin/python3 /srv/openhab2-userdata/example.py
You can create a cronjob to generate charts regularly:
0 * * * * /usr/bin/python3 /srv/openhab2-userdata/charts_hourly.py
0 0 * * * /usr/bin/python3 /srv/openhab2-userdata/charts_daily.py
The images should be stored in the static files folder of OpenHAB, /etc/openhab2/html/ on Openhabian. To use the images in a sitemap add this to the sitemap:
Image url="http://<>/static/output.png"
Find examples in the examples folder. These should teach you the basics. For information on the chart modules go to http://pygal.org/en/stable/documentation/index.html