Project

General

Profile

DomotiCharts : Nice interactive charts

Added by BreFra about 5 years ago

One of the elements I would like to have in DomotiGa (web) gui, is the ability to generate nice interactive charts of device values.
So for personal use I wrote a small webpage around the http://www.highcharts.com framework to automatically generate charts like below:


It only requires to have the device values logged to the database. I.e. enable the "Log status changes to db" option at the Options tab and enter a “datasource name” & select a value type (only "gauge" and "counter" are supported) at the Graphs tab.

The dropdown menu is automatically populated for all available device values that are logged to the database.
Source files are available at: https://github.com/brefra/DomotiCharts


Replies (39)

RE: DomotiCharts : Nice interactive charts - Added by rdnzl about 5 years ago

Hi, I have seen your project on GitHub some time ago, made a clone, but forgot to look at it ;-)
Very, very nice, we didn't know what to do with RRDtool and Graphs, but this is a very nice replacement/addition.
Are these hardcoded, or user configurable yet? As as said haven't had time to look at the code yet.

RE: DomotiCharts : Nice interactive charts - Added by rdnzl about 5 years ago

Forked it and made some very minor changes (default database name to lower case, and device_values.deviceid field is changing to device_id in beta branch)
But get empty graphs... still looking..

RE: DomotiCharts : Nice interactive charts - Added by rdnzl about 5 years ago

Found it, for some reason the time is off by one hour. So this produce current time minus 1 hour:
$endTime = gmstrftime('%Y-%m-%d %H:%M:%S', $end / 1000);

And newer data wasn't visible...

RE: DomotiCharts : Nice interactive charts - Added by rdnzl about 5 years ago

Proof:

So what is causing this.. hmmm..

usage.png (65.4 KB) usage.png
1303

RE: DomotiCharts : Nice interactive charts - Added by Mediacj about 5 years ago

Wow this looks really nice!

Thanks for sharing!!

Have it running also, after changing the database name to lower case just like Ron mentioned(thanks)

Mine is off by one hour to.

RE: DomotiCharts : Nice interactive charts - Added by Alexie about 5 years ago

It isn't UTC vs CET (UTC vs UTC+1) during wintertime?

BTW: Looks cool, lets see if we can add it to DomotiGa as a default option.

RE: DomotiCharts : Nice interactive charts - Added by rdnzl about 5 years ago

Using strftime instead of gmstrftime seems to solve the problem.

RE: DomotiCharts : Nice interactive charts - Added by Mediacj about 5 years ago

rdnzl wrote:

Using strftime instead of gmstrftime seems to solve the problem.

Yes works for me to!

RE: DomotiCharts : Nice interactive charts - Added by rdnzl about 5 years ago

It looks like it, but have to check if the correct data is fetched...or wrong data is displayed.
Zooming doesn't work, or selecting a part of a graph... maybe related...

RE: DomotiCharts : Nice interactive charts - Added by BreFra about 5 years ago

Thanks for feedback.
I did not noticed the one hour off myself yet.
I just changed the default database name and fixed the the date/time format.

Nice to hear it's working for others too.

RE: DomotiCharts : Nice interactive charts - Added by rdnzl about 5 years ago

If I change the gmstrftime to strftime, the 'all graph' (gauge) is ok, but zooming (selecting part) in last hour doesn't work, so those timestamps are still wrong, or timestamp data stored in domotiga table are off.

RE: DomotiCharts : Nice interactive charts - Added by BreFra about 5 years ago

rdnzl wrote:

It looks like it, but have to check if the correct data is fetched...or wrong data is displayed.
Zooming doesn't work, or selecting a part of a graph... maybe related...

It's related, only the "endTime" needs to be formatted using strftime:

// set some utility variables
$range = $end - $start;
$startTime = gmstrftime('%Y-%m-%d %H:%M:%S', $start / 1000);
$endTime = strftime('%Y-%m-%d %H:%M:%S', $end / 1000);

RE: DomotiCharts : Nice interactive charts - Added by rdnzl about 5 years ago

LOL, just wanted to post that... anyways it works oke now, enabled much more logging ;-)

RE: DomotiCharts : Nice interactive charts - Added by kasteleman about 5 years ago

Very nice indeed. Up and running in just a few min......

RE: DomotiCharts : Nice interactive charts - Added by wwolkers about 5 years ago

Very nice for sure, but you will want to escape the input:

$device_id = mysql_escape_string($_GET["device_id"]);
$valuenum = mysql_escape_string($_GET["valuenum"]);

That should protect you from SQL injection attacks.

RE: DomotiCharts : Nice interactive charts - Added by rdnzl about 5 years ago

Frank, now we don't log values when the don't change, so when something stays on 0 for a longer time, we only have one record in the db, and the charts stops at this point, ie, it doesn't display 0 during from the lastrecords timestamp until now, can this be changed, or do we start logging alle record, wether they change or not?
This is a very small code change, but uses more storage of course.

RE: DomotiCharts : Nice interactive charts - Added by htilly about 5 years ago

This is truly really nice and exactly what I´ve been looking for!

Unfortunately I get this in the log files:

2014-03-05 22:54:29: (mod_fastcgi.c.2676) FastCGI-stderr: PHP Notice: Undefined index: device_id in /var/www/DomotiCharts/index.php on line 19
PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /var/www/DomotiCharts/index.php on line 45
PHP Notice: Undefined variable: Graph_Title in /var/www/DomotiCharts/index.php on line 74
PHP Notice: Undefined variable: Graph_Y_Label in /var/www/DomotiCharts/index.php on line 75
PHP Notice: Undefined variable: Graph_Y_Units in /var/www/DomotiCharts/index.php on line 76
PHP Notice: Undefined variable: Graph_Type in /var/www/DomotiCharts/index.php on line 77

Any idea of why or how to fix ?

EDIT
Works when I enter the device_id directly in the URL, i.e:
http://DOMAIN/DomotiCharts/index.php?device_id=15&valuenum=2

Guess some device is screwed in the DB?

BR Tilly

RE: DomotiCharts : Nice interactive charts - Added by htilly about 5 years ago

Another thought.. Im really no developer, but since the new webgui is coming along real nice.. Would it be hard to integrate yii with highcharts?!
Something like:
http://www.yiiframework.com/extension/highcharts/

BR Tilly

RE: DomotiCharts : Nice interactive charts - Added by rdnzl about 5 years ago

I have fixed those PHP Strict issues in my repository: https://github.com/cyberjunky/DomotiCharts
Yes I have started to see how I can integrate this into DomotiYii, I use the HighCharts 3.0.9 extension.

RE: DomotiCharts : Nice interactive charts - Added by htilly about 5 years ago

DomotiCharts]# git pull
Already up-to-date.

Still seeing the problem :(

I will follow this development closely. Really, really interesting to see what this will bring :-D

Keep up the good work!

/Tilly

rdnzl wrote:

I have fixed those PHP Strict issues in my repository: https://github.com/cyberjunky/DomotiCharts
Yes I have started to see how I can integrate this into DomotiYii, I use the HighCharts 3.0.9 extension.

RE: DomotiCharts : Nice interactive charts - Added by rdnzl about 5 years ago

git pull of which repo?

I have a seperate one, it's not brefa's, you are using mine?

git clone https://github.com/cyberjunky/DomotiCharts

RE: DomotiCharts : Nice interactive charts - Added by rdnzl about 5 years ago

Oh I see now, you have other variables it's complaining about.
But the first undefince index is not there with my code, since there is a isset() in front.
Can you check/post code around line 19 of index.php?

Strangely enough my code works ok here with recent PHP and strict.
In short we have to check with isset() if a variable is defined or now before doing things with it..

RE: DomotiCharts : Nice interactive charts - Added by htilly about 5 years ago

Sorry!

My bad.

git clone https://github.com/cyberjunky/DomotiCharts

Works like a charm ! =)

:)

RE: DomotiCharts : Nice interactive charts - Added by BreFra about 5 years ago

rdnzl wrote:

I have fixed those PHP Strict issues in my repository: https://github.com/cyberjunky/DomotiCharts
Yes I have started to see how I can integrate this into DomotiYii, I use the HighCharts 3.0.9 extension.

Thanks for the pull request. I've applied it earlier this evening.
Integrating this into DomotiYii would by teriffic.

rdnzl wrote:

Frank, now we don't log values when the don't change, so when something stays on 0 for a longer time, we only have one record in the db, and the charts stops at this point, ie, it doesn't display 0 during from the lastrecords timestamp until now, can this be changed, or do we start logging alle record, wether they change or not?
This is a very small code change, but uses more storage of course.

I've noticed this too. It should be possible to always append an extra record into the dataset. I'll give it a try.

By the way, the same applies for the start of the graph if zooming is used. I.e. the line starts at the first record while there is a record available for a record which is before the starting timestamp of the selected zooming timespan. Don't know yet how to solve this...

RE: DomotiCharts : Nice interactive charts - Added by egbertje about 5 years ago

I installed this as described in the Readme file.
But when i go to the adres: localhost/DomotiCharts/index.php i cant select a chart.
Not in Chrome and not in Explorer.
Do i have to install a plugin or something in windows(8)??
See screenshot

(1-25/39)