Using relative time in MarcusOlsson-JSON-Datasource Plugin


I’m creating a dashboard with 4 panels, each referencing a relative time, screenshot below -
panel #1 - ‘today so far’
panel #2 - ‘yesterday’
panel #3 - ‘week so far’
panel #4 - ‘month so far’

I’m using the JSON API plugin developed by @marcusolsson (marcusolsson-json-datasource) with global variables ${__from} and ${__to}. The global variables reference the start and end intervals from the time-picker tool on the top-right of the dashboard. Being global variables, the panel’s relative time do not override them.

I will have to replace the global variables ${__from} and ${__to} in the JSON API call with local variables which will reference the panel’s relative time, but I do not know how to go about with this -
Panel #1 - ‘now/d’ to ‘now’
Panel #2 - ‘1d’ to ‘now’
Panel #3 - ‘now/w’ to ‘now’
Panel #4 - ‘now/M’ to ‘now’

I found few relevant posts in the forum, but the solution provided were for users storing data in InfluxDB / MySQL. I’m using EMonCMS to store the data.

Could anyone guide me on how I could go about with this? Thanks!

As a first time poster, was only allowed to share 2 links… including couple of other forum posts and an image on relative time selection to add on to the original post -

Welcome @liame89

Very nice and detailed posts but I am kind of lost as to what you exactly want to do? Could you please post, succinctly, the issue you are trying to solve? Is it about using global variables __From and __to in json data source?

Hello @yosiasz

I’m sorry for being verbose. I’m trying to create a dashboard to display my energy consumption - total energy consumed so far today, total energy consumed yesterday, total energy consumed over the course of a week etc.

Instead of having a single panel and having to individually select the time ranges one at a time (yesterday, last 7 days etc.) from the time-picker tool, I’m creating 4 individual panels each with its own relative timeframe set up in the Query Editor.

I know how to reference the start & end times from the time-picker tool in the JSON API query to the database using the global variables ${__from} and ${__to}. But I do not know how to reference the relative timeframe’s start and end times as key/value pairs in the JSON API’s query to the database.

Reaching out to the community to ask what would be the placeholder variables in the JSON API’s query to the database which would pass on the value of the relative timeframe’s start and end from the Query Editor (instead of the global variables ${__from} and ${__to})