Working (more like struggling) with Grafana using time series data from InfluxDB stored energie consumption (smart meter) and solar panel production. The basics work fine; I can display graphs with fixed time series intervals (see this post).
But now I want to display bar graphs with varying granularity depending on the time range (hour, day, week, month, year). So for a day graph I want details up to 10m, for month graphs I want just a bar per day displayed. I’ve added a variable to the Grafana dashboard and pass it in the URL to Grafana with a Webview statement depending on the Switch state (like ...&from=now-1w&to=now&var-granularity=1d
The issue: when changing from, for example, week view to day view, the graph gets updated in the browser, but with the ‘old’ granularity. Only after a manual refresh (F5), I get the correct granularity in the bar graph.
I see the Item state changing from ‘1h’ to ‘1d’ in the log when selecting another period with the Switch, but it doesn’t get passed in the URL until a manual refresh in the browser. Looks like an order of events issue where the new URL is sent in the Webview statement before the rule that changes the granularity parameter kicks in.
Sitemap entry:
Webview url="/static/pwroverview.html?dashboard=energieconsumptie&fromItem=Power_Period1&panelItem=Power_Panel1&panelInterval=Power_Gran1
Rule used to set new granularity based on change of Switch item:
rule "Power Graphing period parameter transformation"
when
Item Power_Period1 changed
then
// logError("PowerInterval", "Power_Period1 = "+Power_Period1.state)
switch Power_Period1.state {
case 'HOUR': Power_Gran1.postUpdate("10m")
case 'DAY': Power_Gran1.postUpdate("1h")
case 'WEEK': Power_Gran1.postUpdate("1d")
case 'MONTH': Power_Gran1.postUpdate("1d")
case 'YEAR': Power_Gran1.postUpdate("1w")
}
end
BTW, I used a modified version of @wborn 's great library (added the granularity parameter).
To visualize it, a picture of a correct view:
Followed by a picture of the wrong view after selecting a different time range but before manual browser refresh:
Any thoughts on where to start looking/digging/debugging?