Graph widget for influxdb

I installed Firefox and this is the header information I get back from the error if this helps.

Content-Length: 45
Content-Type: application/json
Date: Fri, 16 Nov 2018 23:39:06 GMT
Request-Id: cea6b555-e9f8-11e8-b96f-0242ac1e2102
X-Influxdb-Build: OSS
X-Influxdb-Error: missing required parameter “q”
X-Influxdb-Version: 1.7.0
X-Request-Id: cea6b555-e9f8-11e8-b96f-0242ac1e2102

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.5
Connection: keep-alive
Host: 192.168.169.136:8086
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0

Please download the updated widget files from the repo. The files that have been updated are basegraph.js and graph.yaml.

In the skin you are using, add the lines

graph_user: YOUR_INFLUXDB_USERNAME
graph_password: YOUR_INFLUXDB_PASSWORD

Now the authentication should work fine!

The authentication fix resolved everything and it is working great. Thank you tjntomas

1 Like

The Graph Widget for influxdb is really good. A little difficult to set up (especially newcomers to HA and AppDaemon like me who don’t know the directory structure for CSS and custom widget files etc…) but well worth the effort. See attached picture…it looks great! A big advantage of this approach is the graphs are superconfigurable…The developer has done a great job creating many configurations you can change in the dashboard yaml file. The javascript is fairly easy to follow too if you need to fine tune things (like I changed the select first(value) to an average to get an hourly average instead of the first temperature for the hour). Great job Tomas!

1 Like

Thanks Jonathan, glad you got it working.

I think I’ll add some options like “average” to be configured in the widget definition file.

Old picture from when I was testing it out, but I ended up using a iframe of a static camera image from HA to just display a graph from influx, but might give this a try for something a bit more native, and looks to be a lot more customizable.

1 Like

Had a bit of spare time this morning, so had a play around @tjntomas

I do like the layout of it, it seems a lot easier to read than the camera component one I have setup, but I do like the ability to be able to see what the current temp is for each sensor from the graph as well, not sure if that is something you might be able to implent. @gadjetnut has seem to added in a second widget for the actual temps. But I dont really have too much space left on my dashboard with a major reorganise.

Many thanks for you awesome work.

Excuse the missing data, was rebulding my server over the last few days.

We could add the measurment to the legend text;

or possibly add a gauge section: gauge

1 Like

I added the option to display the value next to the legend text. I also added som translation options since I noticed that some text were in Swedish.

The new option in the widget definition:

value_in_legend: 1 # If present, the value will be displayed next to the legend text.

And in the skin:

graph_degrees_celsius_text: "Degrees Celsius"  # Adjust to your own language
graph_degrees_fahrenheit_text: "Degrees Fahrenheit"  # Adjust to your own language
graph_percent_text: "Percent"  # Adjust to your own language
1 Like

haha, I didn’t even notice the Swedish :slight_smile:

Also in your documention on github, you have this line for the custom_css folder code,

graph_style: "border-radius: 0px; "background-color: rgba(30,30,30,0.45 );"  # Change to whichever color/opacity you like.

Which I believe should read like this,

graph_style: "border-radius: 0px;"
background-color: "rgba(30,30,30,0.45 );"  # Change to whichever color/opacity you like.

It threw up an error for me anyway.

I’ll have a play around later on with it and report back for you.

Thank’s, a line break was missing. Fixed it now.

1 Like

How can I change the title and other colors of the text highlighted in the image below.

image

I have added the missing mappings for these colors now. You need to update basegraph.js and graph.yaml from the repo.
In the skin, add:

graph_title_color: "#ff0000"  
graph_x_axis_text_color: "#ff00ff"
graph_y_axis_legend_color: "#ffff00"
graph_y_axis_text_color: "#00ffff"

I have used bright default colors here to make it easier to see which is which.

Not tested, but you should also be able to override the skin colors by adding for example:

title_color: "#aabbcc"

to a widget definition if you want different colors for a specific widget. Let me know if this doesn’t work. This should work for all widget types.

This is exactly what I wanted to change everything individually. Thank you so much. Perfection

The error was an extra ". The line should read:

graph_style: "border-radius: 0px; background-color: rgba(30,30,30,0.45 );"
1 Like

I have almost finally finished moving my homeassistant/appdaemon/influx etc from my Pi/NAS to my new dual xeon server, so once thats all done, I’ll have another play around with it sir.

Although I have to say, moving HA/AD away from the Pi to the server has made a world of difference to loading speed of dashboards, like 5-6 times as fast at least.

After spending 2 or 3 weeks unsuccessfully trying to get the plotly version running I switched to the influxdb solution and almost got it running in a very short time. Unfortunately I get an empty graph that alway shows 10.25 (it is now 14:52). I tried various time values from 1h up to 2w but it’s always gives the same result. The console shows that all available values are returned from the select query and the y-range is correct.

I changed the default time_zone & locale settings to Europe/Zurich & ‘de’ in basegraph.js to get that result. With the original Stockholm & sv I had a range of times on x but only covering a few hundred microseconds:

I can drag the x.axis left and right but I never see any y-values plotted

Here is my dashboard definition:

mvp:
        widget_type: graph
        entities:
          - sensor.temperature_outside  # The entity_id to be plotted.
        influxdb_units:
          - "°C"   # The unit_of_measurement for your sensors/entities
        titles:
          - "Outdoor temperature" # Title of the trace.
        time: 24h   # Time interval to plot. you can combine w, d, h and m as 2w1d3h20m (This would be 2 weeks, 1 day, 3 hours and 20 minutes)
        title: "Temperatures"  # Widget title
        fill: "tozeroy" # options are  "none" | "tozeroy" | "tozerox" | "tonexty" | "tonextx" | "toself" 
        colorIndex: 0   # A number between 0 and 11. 12 colors for the traces are predefined and the colorIndex defines 
        log: 1

layout:
- mvp(8x2)

I have the widget setup in a copy of the default skin.

I also added an additional log output “Logger(self, traces)” just before the Plotly.plot call @line 251 and this seems to confirm the single value (the temperature at 10:25:27 was indeed 3.2°C)

​​fill: “tozeroy”
​​fillcolor: “rgba(50,50,220,0.4)”
​​line: Object { color: “rgba(50,50,220,0.7)”, width: 2, shape: “spline” }
​​mode: “lines”
​​name: “Outdoor temperature”
​​type: “scatter”
​​uid: “c4d58c”
​​x: Array [ “2019-01-07 10:25:27” ]
​​y: Array [ 3.2 ]
​​: Object { … }
​length: 1
​: Array

I think I must have a config issue somewhere as no one seems to have had this result.

Unless you have only posted part of the log output, It looks like you only have one data sample in the influx database so there is nothing to make a plot from. You need at least two samples to draw a trace. To confirm this, you can add dummy values for X and Y by replacing the lines 245 and 246 with:

	x: ["2018-01-01 00:00:00", "2018-01-01 01:00:00"],
	y: [10,20],

If this does not produce a line in the graph, there might be a bug somewhere and I’ll will have a look at it.
Your also welcome to open an issue on github if you run into other problems.

I have 50 records in the DB and I see them in the console output, also if I call the select URL directly.
I posted all of the output. I assume Plotly.plot is only called once for all records. I noticed that Plotly.plot doesn’t return - if I add the Logger output after the call it never writes anything. Is that correct?

Ok, if “traces” only contains one sample, there is an error somewhere in the InfluxDB_Data function that we need to find.

The data is read from influxdb in the InfluxDB_Data function and then calls Multiplot with an array of samples as a parameter named “DataSeries” and it seems from your log that the DataSeries variable does not contain all the samples. Please add

console.log(DataSeries, measurement) 

as the first line in the MultiPlot function and see what you get in the log.

The Plotly.plot function call does not return a promise and this is the reason for the try/catch part to keep the log clean. If I use the Plotly.plot “outside” a widget, the call returns nicely though and I haven’t managed to figure out why it doesn’t return a promise when used in a widget.